2020-04-01 22:06:00 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | Functions for formatting and spawning shell commands
|
|
|
|
|
2020-04-01 20:17:47 -04:00
|
|
|
module XMonad.Internal.Shell
|
|
|
|
( fmtCmd
|
|
|
|
, spawnCmd
|
2020-05-31 20:56:57 -04:00
|
|
|
, spawnSound
|
2021-06-17 01:17:59 -04:00
|
|
|
, doubleQuote
|
|
|
|
, singleQuote
|
2020-04-01 20:17:47 -04:00
|
|
|
, (#!&&)
|
|
|
|
, (#!||)
|
|
|
|
, (#!>>)
|
|
|
|
) where
|
2020-03-18 12:17:39 -04:00
|
|
|
|
2020-07-06 21:08:32 -04:00
|
|
|
import Control.Monad.IO.Class
|
|
|
|
|
2020-05-31 20:56:57 -04:00
|
|
|
import System.FilePath.Posix
|
|
|
|
|
2020-07-06 21:08:32 -04:00
|
|
|
import XMonad.Core (getXMonadDir)
|
2020-04-06 00:14:56 -04:00
|
|
|
import XMonad.Internal.Process
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2020-04-01 22:06:00 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | Opening subshell
|
2020-03-18 12:17:39 -04:00
|
|
|
|
2020-07-06 21:08:32 -04:00
|
|
|
spawnCmd :: MonadIO m => String -> [String] -> m ()
|
2020-03-18 12:17:39 -04:00
|
|
|
spawnCmd cmd args = spawn $ fmtCmd cmd args
|
|
|
|
|
2020-05-31 20:56:57 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | Playing sound
|
|
|
|
|
|
|
|
soundDir :: FilePath
|
|
|
|
soundDir = "sound"
|
|
|
|
|
2020-07-06 21:08:32 -04:00
|
|
|
spawnSound :: MonadIO m => FilePath -> m ()
|
2020-05-31 20:56:57 -04:00
|
|
|
spawnSound file = do
|
|
|
|
path <- (</> soundDir </> file) <$> getXMonadDir
|
2020-05-31 23:58:30 -04:00
|
|
|
-- paplay seems to have less latency than aplay
|
|
|
|
spawnCmd "paplay" [path]
|
2020-05-31 20:56:57 -04:00
|
|
|
|
2020-04-01 22:06:00 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | Formatting commands
|
|
|
|
|
|
|
|
fmtCmd :: String -> [String] -> String
|
|
|
|
fmtCmd cmd args = unwords $ cmd : args
|
|
|
|
|
2020-03-18 12:17:39 -04:00
|
|
|
(#!&&) :: String -> String -> String
|
|
|
|
cmdA #!&& cmdB = cmdA ++ " && " ++ cmdB
|
|
|
|
|
|
|
|
infixr 0 #!&&
|
|
|
|
|
|
|
|
(#!||) :: String -> String -> String
|
|
|
|
cmdA #!|| cmdB = cmdA ++ " || " ++ cmdB
|
|
|
|
|
|
|
|
infixr 0 #!||
|
|
|
|
|
|
|
|
(#!>>) :: String -> String -> String
|
|
|
|
cmdA #!>> cmdB = cmdA ++ "; " ++ cmdB
|
|
|
|
|
|
|
|
infixr 0 #!>>
|
2021-06-17 01:17:59 -04:00
|
|
|
|
|
|
|
doubleQuote :: String -> String
|
|
|
|
doubleQuote s = "\"" ++ s ++ "\""
|
|
|
|
|
|
|
|
singleQuote :: String -> String
|
|
|
|
singleQuote s = "'" ++ s ++ "'"
|