[Linux] Use haskell to write rofi_select_input
This commit is contained in:
parent
de0671026a
commit
e94b7ac060
29
dotfiles/lib/bin/rofi_select_input.hs
Executable file
29
dotfiles/lib/bin/rofi_select_input.hs
Executable file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env runhaskell
|
||||
{-# LANGUAGE OverloadedStrings, AllowAmbiguousTypes #-}
|
||||
|
||||
import Data.List
|
||||
import Data.List.Split
|
||||
import Data.Maybe
|
||||
import Data.Text (unpack)
|
||||
import Text.Regex
|
||||
import Text.Printf
|
||||
import Turtle hiding (printf)
|
||||
import Turtle.Shell
|
||||
|
||||
main = do
|
||||
out <- unpack <$> getSinkText
|
||||
let sinkInfos = splitOn "\nSink" out
|
||||
matches = catMaybes $ matchRegex sinkRegex <$> sinkInfos
|
||||
entries = map buildEntry matches
|
||||
rofiText = intercalate "\n" entries
|
||||
selection <- snd <$> shellStrict "rofi -dmenu -i" (select $ map fromString entries)
|
||||
let selectedSink = head $ splitOn " " $ unpack selection
|
||||
mapM_ (setMuteAction "1" . head) matches
|
||||
setMuteAction "0" selectedSink
|
||||
return ()
|
||||
where getSinkText = snd <$> shellStrict "pactl list sink-inputs" empty
|
||||
sinkRegex = mkRegexWithOpts "Input .([0-9]*).*?application.name =([^\n]*)" False True
|
||||
buildEntry (num:name:_) = let app = (filter (not . (`elem` ("\"" :: String))) name) in printf "%s - %s" num $ trim app
|
||||
setMuteAction status sink = shell (fromString $ setMuteCommand status sink) empty
|
||||
setMuteCommand status sink = "pactl set-sink-input-mute " ++ sink ++ " " ++ status
|
||||
trim = dropWhileEnd (== ' ') . dropWhile (== ' ')
|
@ -1,9 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
inputs=$(pactl list sink-inputs | grep 'Sink Input' | grep -Eo '[0-9]*')
|
||||
selection=$(echo "$inputs" | rofi -dmenu -i)
|
||||
|
||||
echo "$inputs" | xargs -I {} -n1 pactl set-sink-input-mute {} 1
|
||||
|
||||
pactl set-sink-input-mute "$selection" 0
|
||||
|
Loading…
Reference in New Issue
Block a user