Host parameter
This commit is contained in:
parent
910e0b54c0
commit
decb091842
|
@ -3,13 +3,12 @@
|
|||
let configPath = $"($env.XDG_CONFIG_HOME? | default $"($env.HOME)/.config")/irs.toml"
|
||||
let config = if ($configPath | path exists) { open $configPath }
|
||||
|
||||
let mpdHost = if ($config == nothing) { $config.noise.host? | default 'localhost' } else { 'localhost' }
|
||||
let current = mpc --host $mpdHost current
|
||||
let mpdHost = if ($config | is-empty) { 'localhost' } else { $config.noise.host? | default 'localhost' }
|
||||
|
||||
def notify [message: string, display_icon:bool] {
|
||||
def notify [message: string, display_icon:bool, host] {
|
||||
match $display_icon {
|
||||
true => {
|
||||
do { mpc --host $mpdHost -f "%file%" current | xargs -I{} mpc --host $mpdHost albumart {} } | save -f /tmp/mpc_current.png
|
||||
do { mpc --host $host -f "%file%" current | xargs -I{} mpc --host $host albumart {} } | save -f /tmp/mpc_current.png
|
||||
notify-send "Noise" $"($message)" -i /tmp/mpc_current.png
|
||||
}
|
||||
false => {
|
||||
|
@ -18,90 +17,126 @@ def notify [message: string, display_icon:bool] {
|
|||
}
|
||||
}
|
||||
|
||||
def getHost [ host?: string ] {
|
||||
match ($host | is-empty) {
|
||||
true => $mpdHost
|
||||
false => $host
|
||||
}
|
||||
}
|
||||
|
||||
def getCurrent [ host: string ] {
|
||||
mpc current --host $host
|
||||
}
|
||||
|
||||
# Displays the currently playing song
|
||||
def main [--no-icon(-n) # Disables icon in notification
|
||||
--host(-H): string # mpd host
|
||||
] {
|
||||
mpc --host $mpdHost
|
||||
notify $current (not $no_icon)
|
||||
let host = getHost $host
|
||||
mpc --host $host
|
||||
notify $"(getCurrent $host)" (not $no_icon) $host
|
||||
}
|
||||
|
||||
# Displays the currently playing song and only the current song
|
||||
def "main current" [--no-icon(-n) # Disables icon in notification
|
||||
--host(-H): string # mpd host
|
||||
] {
|
||||
mpc --host $mpdHost current
|
||||
notify $current (not $no_icon)
|
||||
let host = getHost $host
|
||||
notify $"(getCurrent $host)" (not $no_icon) $host
|
||||
}
|
||||
|
||||
|
||||
# Lists currently playing song
|
||||
def "main tail" [] {
|
||||
while true { mpc --host $mpdHost idle playlist | ignore; mpc --host $mpdHost current}
|
||||
def "main tail" [ --host(-H): string # mpd host
|
||||
] {
|
||||
let host = getHost $host
|
||||
while true { mpc --host $host idle player | ignore; mpc --host $host current}
|
||||
}
|
||||
|
||||
# Skips to next song
|
||||
def "main next" [--no-icon(-n) # Disables icon in notification
|
||||
--host(-H): string # mpd host
|
||||
] {
|
||||
mpc --host $mpdHost next
|
||||
notify $"Switching to:\n($current)" (not $no_icon)
|
||||
let host = getHost $host
|
||||
mpc --host $host next
|
||||
notify $"Switching to:\n(getCurrent $host)" (not $no_icon) $host
|
||||
}
|
||||
|
||||
# Moves back a song in the que
|
||||
def "main prev" [--no-icon(-n) # Disables icon in notification
|
||||
--host(-H): string # mpd host
|
||||
] {
|
||||
mpc --host $mpdHost prev
|
||||
notify $"Switching to:\n($current)" (not $no_icon)
|
||||
let host = getHost $host
|
||||
mpc --host $host
|
||||
notify $"Switching to:\n(getCurrent $host)" (not $no_icon) $host
|
||||
}
|
||||
|
||||
# Shuffles the current que
|
||||
def "main shuffle" [--no-icon(-n) # Disables icon in notification
|
||||
--host(-H): string # mpd host
|
||||
] {
|
||||
let host = getHost $host
|
||||
mpc --host $mpdHost shuffle
|
||||
notify $"Shuffling que..." (not $no_icon)
|
||||
notify $"Shuffling que..." (not $no_icon) $host
|
||||
}
|
||||
|
||||
# Stops playing the current que
|
||||
def "main stop" [--no-icon(-n) # Disables icon in notification
|
||||
--host(-H): string # mpd host
|
||||
] {
|
||||
mpc --host $mpdHost stop
|
||||
notify $"Stopping playback of:\n(mpc --host $mpdHost toggle)" (not $no_icon)
|
||||
let host = getHost $host
|
||||
mpc --host $host stop
|
||||
notify $"Stopping playback of:\n(getCurrent $host)" (not $no_icon) $host
|
||||
}
|
||||
|
||||
# Starts playing the current que
|
||||
def "main start" [--no-icon(-n) # Disables icon in notification
|
||||
--host(-H): string # mpd host
|
||||
] {
|
||||
mpc --host $mpdHost start
|
||||
notify $"Starting playback of:\n(mpc --host $mpdHost toggle)" (not $no_icon)
|
||||
let host = getHost $host
|
||||
mpc --host $host start
|
||||
notify $"Starting playback of:\n(getCurrent $host)" (not $no_icon) $host
|
||||
}
|
||||
|
||||
# Toggles playback of the current que
|
||||
def "main toggle" [--no-icon(-n) # Disables icon in notification
|
||||
--host(-H): string # mpd host
|
||||
] {
|
||||
mpc --host $mpdHost toggle
|
||||
notify $"Toggling playback of:\n($current)" (not $no_icon)
|
||||
let host = getHost $host
|
||||
mpc --host $host toggle
|
||||
notify $"Toggling playback of:\n(getCurrent $host)" (not $no_icon) $host
|
||||
}
|
||||
|
||||
# Searches 'mpd' database querying all fields by default
|
||||
def "main search" [--field(-f): string=any # Field to query
|
||||
, ...query: string # Search query
|
||||
, --host(-H): string # mpd host
|
||||
] {
|
||||
mpc --host $mpdHost search ($field) $"(echo ...$query | str join ' ')"
|
||||
let host = getHost $host
|
||||
mpc --host $host search ($field) $"(echo ...$query | str join ' ')"
|
||||
}
|
||||
|
||||
# Insert uri after currently playing song
|
||||
def "main insert" [] {
|
||||
$in | mpc insert --host $mpdHost
|
||||
def "main insert" [ --host(-H): string # mpd host
|
||||
] {
|
||||
let host = getHost $host
|
||||
$in | mpc insert --host $host
|
||||
}
|
||||
|
||||
# Adds uri to the end of current que
|
||||
def "main add" [] {
|
||||
$in | mpc add --host $mpdHost
|
||||
def "main add" [ --host(-H): string # mpd host
|
||||
] {
|
||||
let host = getHost $host
|
||||
$in | mpc add --host $host
|
||||
}
|
||||
|
||||
# Direct wrapper around 'mpc crossfade'
|
||||
def "main crossfade" [ time?: int # Time in seconds
|
||||
--host(-H): string # mpd host
|
||||
] {
|
||||
let host = getHost $host
|
||||
match ($time | is-empty) {
|
||||
true => { mpc --host $mpdHost crossfade }
|
||||
false => { mpc --host $mpdHost crossfade $time }
|
||||
true => { mpc --host $host crossfade }
|
||||
false => { mpc --host $host crossfade $time }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue