[linux] 80chars
This commit is contained in:
parent
887e0a77f3
commit
d534721312
@ -5,7 +5,6 @@ import Control.Monad
|
|||||||
import Data.List
|
import Data.List
|
||||||
import Data.List.Split
|
import Data.List.Split
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.Text (unpack)
|
|
||||||
import System.Process
|
import System.Process
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
import Text.Regex
|
import Text.Regex
|
||||||
@ -17,12 +16,13 @@ main = do
|
|||||||
let sinkInfos = splitOn "\nSink" out
|
let sinkInfos = splitOn "\nSink" out
|
||||||
matches = catMaybes $ matchRegex sinkRegex <$> sinkInfos
|
matches = catMaybes $ matchRegex sinkRegex <$> sinkInfos
|
||||||
entries = map buildEntry matches
|
entries = map buildEntry matches
|
||||||
(exitCode, selection, _) <- readCreateProcessWithExitCode (shell "rofi -dmenu -i -kb-custom-1 'Alt-o'") $
|
(exitCode, selection, _) <-
|
||||||
intercalate "\n" entries
|
readCreateProcessWithExitCode
|
||||||
|
(shell "rofi -dmenu -i -kb-custom-1 'Alt-o'") $ intercalate "\n" entries
|
||||||
let selectedSink = head $ splitOn " " selection
|
let selectedSink = head $ splitOn " " selection
|
||||||
unMuteSelected = setMuteAction "0" selectedSink
|
unMuteSelected = setMuteAction "0" selectedSink
|
||||||
selectedIsMuted = fromMaybe True $
|
selectedIsMuted =
|
||||||
isMuted . (!! 1) <$> find ((== selectedSink) . head) matches
|
maybe True (isMuted . (!! 1)) $ find ((== selectedSink) . head) matches
|
||||||
setAll state = mapM_ (setMuteAction state . head) matches
|
setAll state = mapM_ (setMuteAction state . head) matches
|
||||||
case exitCode of
|
case exitCode of
|
||||||
ExitSuccess ->
|
ExitSuccess ->
|
||||||
@ -32,18 +32,25 @@ main = do
|
|||||||
setAll "1"
|
setAll "1"
|
||||||
void unMuteSelected
|
void unMuteSelected
|
||||||
ExitFailure _ -> setAll "0"
|
ExitFailure _ -> setAll "0"
|
||||||
where getSinkText = do
|
where getSinkText =
|
||||||
(_, txt, _) <- readCreateProcessWithExitCode (shell "pactl list sink-inputs") ""
|
do
|
||||||
return txt
|
(_, txt, _) <- readCreateProcessWithExitCode
|
||||||
sinkRegex = mkRegexWithOpts "Input .([0-9]*).*?Mute: ([^\n]*).*?application.name =([^\n]*)" False True
|
(shell "pactl list sink-inputs") ""
|
||||||
|
return txt
|
||||||
|
sinkRegex =
|
||||||
|
mkRegexWithOpts
|
||||||
|
"Input .([0-9]*).*?Mute: ([^\n]*).*?application.name =([^\n]*)"
|
||||||
|
False True
|
||||||
buildEntry (num:status:name:_) =
|
buildEntry (num:status:name:_) =
|
||||||
printf "%s - %s%s" num (trim $ noQuotes name) (muteString status)
|
printf "%s - %s%s" num (trim $ noQuotes name) (muteString status)
|
||||||
buildEntry _ = ""
|
buildEntry _ = ""
|
||||||
setMuteAction status sink = callCommand $ setMuteCommand status sink
|
setMuteAction status sink = callCommand $ setMuteCommand status sink
|
||||||
setMuteCommand status sink = "pactl set-sink-input-mute " ++ sink ++ " " ++ status
|
setMuteCommand status sink =
|
||||||
|
"pactl set-sink-input-mute " ++ sink ++ " " ++ status
|
||||||
trim = dropWhileEnd (== ' ') . dropWhile (== ' ')
|
trim = dropWhileEnd (== ' ') . dropWhile (== ' ')
|
||||||
isMuted = (== "yes")
|
isMuted = (== "yes")
|
||||||
muteString status = if isMuted status then " (Muted)" else "" :: String
|
muteString status =
|
||||||
|
if isMuted status then " (Muted)" else "" :: String
|
||||||
noQuotes = filter (not . (`elem` ("\"" :: String)))
|
noQuotes = filter (not . (`elem` ("\"" :: String)))
|
||||||
toSetString True = "0"
|
toSetString True = "0"
|
||||||
toSetString False = "1"
|
toSetString False = "1"
|
||||||
|
Loading…
Reference in New Issue
Block a user