From fb24509e21bbc239ef9a4639af7943bb25dd7633 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Thu, 30 Mar 2017 11:36:44 -0700 Subject: [PATCH] [Linux] Don't do anything in rofi_select_input if nothing selected --- dotfiles/lib/bin/rofi_select_input.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dotfiles/lib/bin/rofi_select_input.hs b/dotfiles/lib/bin/rofi_select_input.hs index 71a7ca19..dcc5b152 100755 --- a/dotfiles/lib/bin/rofi_select_input.hs +++ b/dotfiles/lib/bin/rofi_select_input.hs @@ -16,11 +16,14 @@ main = do 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 () + (exitCode, selection) <- shellStrict "rofi -dmenu -i" (select $ map fromString entries) + case exitCode of + ExitSuccess -> do + let selectedSink = head $ splitOn " " $ unpack selection + mapM_ (setMuteAction "1" . head) matches + setMuteAction "0" selectedSink + return () + ExitFailure _ -> 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