mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-11 02:02:11 -07:00
Shell.hs: +getBrowser, getEditor, helper function
The helper function asks the shell for the value of a variable, else returns the second argument. getBrowser and getEditor obviously specialize it for two particular possibly queries
This commit is contained in:
@@ -17,6 +17,8 @@ module XMonad.Prompt.Shell
|
|||||||
-- $usage
|
-- $usage
|
||||||
shellPrompt
|
shellPrompt
|
||||||
, getCommands
|
, getCommands
|
||||||
|
, getBrowser
|
||||||
|
, getEditor
|
||||||
, getShellCompl
|
, getShellCompl
|
||||||
, split
|
, split
|
||||||
, prompt
|
, prompt
|
||||||
@@ -122,3 +124,20 @@ escape (x:xs)
|
|||||||
|
|
||||||
isSpecialChar :: Char -> Bool
|
isSpecialChar :: Char -> Bool
|
||||||
isSpecialChar = flip elem "\\@\"'#?$*()[]{};"
|
isSpecialChar = flip elem "\\@\"'#?$*()[]{};"
|
||||||
|
|
||||||
|
-- | Ask the shell environment for
|
||||||
|
env :: String -> String -> IO String
|
||||||
|
env variable fallthrough = getEnv variable `catch` \_ -> return fallthrough
|
||||||
|
|
||||||
|
{- | Ask the shell what browser the user likes. If the user hasn't defined any
|
||||||
|
$BROWSER, defaults to returning \"firefox\", since that seems to be the most
|
||||||
|
common X web browser.
|
||||||
|
Note that if you don't specify a GUI browser but a textual one, that'll be a problem
|
||||||
|
as 'getBrowser' will be called by functions expecting to be able to just execute the string
|
||||||
|
or pass it to a shell; so in that case, define $BROWSER as something like \"xterm -e elinks\"
|
||||||
|
or as the name of a shell script doing much the same thing. -}
|
||||||
|
getBrowser :: IO String
|
||||||
|
getBrowser = env "BROWSER" "firefox"
|
||||||
|
|
||||||
|
getEditor :: IO String
|
||||||
|
getEditor = env "EDITOR" "emacs"
|
Reference in New Issue
Block a user