Last active
November 1, 2020 11:16
-
-
Save saivert/0c669b3c424ac5e6672c427f883347d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/pwsh | |
$CLR = "$([char]27)[2K" | |
$R = ([char]13) | |
Function LeaveIt { | |
Write-Host -Nonewline $CLR | |
Write-Host "Bye!" | |
exit | |
} | |
[console]::TreatControlCAsInput = $true | |
While ($true) { | |
if ($Host.UI.RawUI.KeyAvailable) { | |
$input = $Host.UI.RawUI.ReadKey("AllowCtrlC,IncludeKeyDown,NoEcho").Character | |
if ([int]$input -eq 3) { | |
LeaveIt | |
} | |
switch ($input) { | |
"z" { playerctl previous } | |
"x" { playerctl play } | |
"c" { playerctl pause } | |
"v" { playerctl stop } | |
"b" { playerctl next } | |
} | |
} | |
$x = playerctl status 2>&1 | |
<# | |
if ($? -eq $false) { | |
LeaveIt | |
} | |
#> | |
#Write-Host "Status is: $x" | |
if ($? -and (($x -eq "Playing") -or ($x -eq "Paused"))) { | |
[int]$length = playerctl metadata --format "{{mpris:length}}" | |
$dur = playerctl metadata --format "{{duration(position)}}" | |
[int]$pos = playerctl metadata --format "{{position}}" | |
if ($length) { | |
$progress = $pos * 100 / $length | |
} else { | |
$progress = 0; | |
} | |
$trackid = playerctl metadata --format "{{mpris:trackid}}" | |
if ($trackid -like "*NoTrack*") { | |
$info = "No track" | |
} else { | |
$info = playerctl metadata --format "{{ artist }} - {{ album }} - {{ title }}" | |
} | |
Write-Progress -Activity "Now playing" -Status "$info" -CurrentOperation $x -PercentComplete $progress | |
} else { | |
Write-Host -Nonewline "$CLR$x (^C to exit)$R" | |
Write-Progress -Activity "Now playing" -Completed | |
} | |
Start-Sleep -Milliseconds 250 | |
} | |
Write-Progress -Activity "Now playing" -Completed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment