From 6e52f21443139d5e7766222a744a5faca075fc47 Mon Sep 17 00:00:00 2001 From: gwern0 Date: Tue, 1 Apr 2008 03:34:47 +0200 Subject: 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 darcs-hash:20080401013447-f7719-ef866971330f39e4938445e645a726a56707d04f.gz --- XMonad/Prompt/Shell.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'XMonad/Prompt/Shell.hs') diff --git a/XMonad/Prompt/Shell.hs b/XMonad/Prompt/Shell.hs index d28f92d..be928ee 100644 --- a/XMonad/Prompt/Shell.hs +++ b/XMonad/Prompt/Shell.hs @@ -17,6 +17,8 @@ module XMonad.Prompt.Shell -- $usage shellPrompt , getCommands + , getBrowser + , getEditor , getShellCompl , split , prompt @@ -122,3 +124,20 @@ escape (x:xs) isSpecialChar :: Char -> Bool 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" \ No newline at end of file -- cgit v1.2.3