67 lines
1.4 KiB
Haskell
67 lines
1.4 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- | Functions for formatting and spawning shell commands
|
|
|
|
module XMonad.Internal.Shell
|
|
( fmtCmd
|
|
, spawnCmd
|
|
, doubleQuote
|
|
, singleQuote
|
|
, skip
|
|
, (#!&&)
|
|
, (#!||)
|
|
, (#!|)
|
|
, (#!>>)
|
|
) where
|
|
|
|
import Control.Monad.IO.Class
|
|
|
|
import qualified RIO.Text as T
|
|
|
|
import XMonad.Internal.Process
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- | Opening subshell
|
|
|
|
spawnCmd :: MonadIO m => FilePath -> [T.Text] -> m ()
|
|
spawnCmd cmd args = spawn $ T.unpack $ fmtCmd cmd args
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- | Formatting commands
|
|
|
|
fmtCmd :: FilePath -> [T.Text] -> T.Text
|
|
fmtCmd cmd args = T.unwords $ T.pack cmd : args
|
|
|
|
op :: T.Text -> T.Text -> T.Text -> T.Text
|
|
op a x b = T.unwords [a, x, b]
|
|
|
|
(#!&&) :: T.Text -> T.Text -> T.Text
|
|
cmdA #!&& cmdB = op cmdA "&&" cmdB
|
|
|
|
infixr 0 #!&&
|
|
|
|
(#!|) :: T.Text -> T.Text -> T.Text
|
|
cmdA #!| cmdB = op cmdA "|" cmdB
|
|
|
|
infixr 0 #!|
|
|
|
|
(#!||) :: T.Text -> T.Text -> T.Text
|
|
cmdA #!|| cmdB = op cmdA "||" cmdB
|
|
|
|
infixr 0 #!||
|
|
|
|
(#!>>) :: T.Text -> T.Text -> T.Text
|
|
cmdA #!>> cmdB = op cmdA ";" cmdB
|
|
|
|
infixr 0 #!>>
|
|
|
|
doubleQuote :: T.Text -> T.Text
|
|
doubleQuote s = T.concat ["\"", s, "\""]
|
|
|
|
singleQuote :: T.Text -> T.Text
|
|
singleQuote s = T.concat ["'", s, "'"]
|
|
|
|
skip :: Monad m => m ()
|
|
skip = return ()
|