aboutsummaryrefslogtreecommitdiffstats
path: root/Run.hs
diff options
context:
space:
mode:
authorgwern0 <gwern0@gmail.com>2007-10-19 20:10:09 +0200
committergwern0 <gwern0@gmail.com>2007-10-19 20:10:09 +0200
commit7ce28a9d0c84179bd0beceab29264542b9d2adcc (patch)
treeb39f948db4ad25b98c97aa6871b1ed7a9c47bd86 /Run.hs
parentab7d4a946f053a77c007923c0dec4fd2409c825e (diff)
downloadXMonadContrib-7ce28a9d0c84179bd0beceab29264542b9d2adcc.tar.gz
XMonadContrib-7ce28a9d0c84179bd0beceab29264542b9d2adcc.tar.xz
XMonadContrib-7ce28a9d0c84179bd0beceab29264542b9d2adcc.zip
Run.hs: +2 functions, safeSpawn & unsafeSpawn
See their documentation. This is part of a re-organization of various 'run' commands; this two make it easier to go through the shell or not, and will be re-used elsewhere. darcs-hash:20071019181009-f7719-4f4073639389f335080d552c4788667fd109b6f3.gz
Diffstat (limited to 'Run.hs')
-rw-r--r--Run.hs21
1 files changed, 21 insertions, 0 deletions
diff --git a/Run.hs b/Run.hs
index 2eb16d4..5d61110 100644
--- a/Run.hs
+++ b/Run.hs
@@ -20,6 +20,8 @@ module XMonadContrib.Run (
-- $usage
runProcessWithInput,
runProcessWithInputAndWait,
+ safeSpawn,
+ unsafeSpawn,
seconds
) where
@@ -81,3 +83,22 @@ runProcessWithInputAndWait cmd args input timeout = do
-}
seconds :: Rational -> Int
seconds = fromEnum . (* 1000000)
+
+{- | safeSpawn bypasses XMonad's 'spawn' command, because spawn passes strings to /bin/sh to be interpreted as shell
+ commands. This is often what one wants, but in many cases the passed string will contain shell metacharacters
+ which one does not want interpreted as such (URLs particularly often have shell metacharacters like '&' in them).
+ In this case, it is more useful to specify a file or program to be run and a string to give it as an argument so
+ as to bypass the shell and be certain the program will receive the string as you typed it.
+ unsafeSpawn is an alias for XMonad's 'spawn', to remind one that use of it can be, well, unsafe.
+ Examples:
+ > , ((modMask, xK_Print ), unsafeSpawn "import -window root png:$HOME/xwd-$(date +%s)$$.png")
+ > , ((modMask, xK_d ), safeSpawn "firefox" "")
+
+ Note that the unsafeSpawn example must be unsafe and not safe because it makes use of shell interpretation by relying on
+ $HOME and interpolation, whereas the safeSpawn example can be safe because Firefox doesn't need any arguments if it is
+ just being started.
+-}
+safeSpawn :: FilePath -> String -> X ()
+safeSpawn prog arg = io (try (forkProcess $ executeFile prog True [arg] Nothing) >> return ())
+unsafeSpawn :: String -> X ()
+unsafeSpawn = spawn