2022-12-26 14:45:49 -05:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
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
|
2021-11-07 13:35:08 -05:00
|
|
|
( fmtCmd
|
2020-04-01 20:17:47 -04:00
|
|
|
, spawnCmd
|
2021-06-17 01:17:59 -04:00
|
|
|
, doubleQuote
|
|
|
|
, singleQuote
|
2021-06-19 00:17:47 -04:00
|
|
|
, skip
|
2020-04-01 20:17:47 -04:00
|
|
|
, (#!&&)
|
|
|
|
, (#!||)
|
2021-06-20 01:01:36 -04:00
|
|
|
, (#!|)
|
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
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
import qualified RIO.Text as T
|
|
|
|
|
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
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
spawnCmd :: MonadIO m => FilePath -> [T.Text] -> m ()
|
|
|
|
spawnCmd cmd args = spawn $ T.unpack $ fmtCmd cmd args
|
2020-03-18 12:17:39 -04:00
|
|
|
|
2020-04-01 22:06:00 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | Formatting commands
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
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]
|
2020-04-01 22:06:00 -04:00
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
(#!&&) :: T.Text -> T.Text -> T.Text
|
|
|
|
cmdA #!&& cmdB = op cmdA "&&" cmdB
|
2020-03-18 12:17:39 -04:00
|
|
|
|
|
|
|
infixr 0 #!&&
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
(#!|) :: T.Text -> T.Text -> T.Text
|
|
|
|
cmdA #!| cmdB = op cmdA "|" cmdB
|
2021-06-20 01:01:36 -04:00
|
|
|
|
|
|
|
infixr 0 #!|
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
(#!||) :: T.Text -> T.Text -> T.Text
|
|
|
|
cmdA #!|| cmdB = op cmdA "||" cmdB
|
2020-03-18 12:17:39 -04:00
|
|
|
|
|
|
|
infixr 0 #!||
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
(#!>>) :: T.Text -> T.Text -> T.Text
|
|
|
|
cmdA #!>> cmdB = op cmdA ";" cmdB
|
2020-03-18 12:17:39 -04:00
|
|
|
|
|
|
|
infixr 0 #!>>
|
2021-06-17 01:17:59 -04:00
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
doubleQuote :: T.Text -> T.Text
|
|
|
|
doubleQuote s = T.concat ["\"", s, "\""]
|
2021-06-17 01:17:59 -04:00
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
singleQuote :: T.Text -> T.Text
|
|
|
|
singleQuote s = T.concat ["'", s, "'"]
|
2021-11-07 13:35:08 -05:00
|
|
|
|
|
|
|
skip :: Monad m => m ()
|
|
|
|
skip = return ()
|