aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgwern0 <gwern0@gmail.com>2007-10-19 20:09:00 +0200
committergwern0 <gwern0@gmail.com>2007-10-19 20:09:00 +0200
commitb1b88b0feda71b8092386963d36da11a8d0472be (patch)
tree7628d2bb5b002aa4142c376a2dd56271f84c9373
parent24f22c3a558181ac176c28f8ca836db6d51b011b (diff)
downloadXMonadContrib-b1b88b0feda71b8092386963d36da11a8d0472be.tar.gz
XMonadContrib-b1b88b0feda71b8092386963d36da11a8d0472be.tar.xz
XMonadContrib-b1b88b0feda71b8092386963d36da11a8d0472be.zip
Run.hs, ShellPrompt.sh: mv runInXTerm to ShellPrompt.hs
darcs-hash:20071019180900-f7719-6d6ef4a67f2ccae639e9e79c49fd80dd32d746c5.gz
Diffstat (limited to '')
-rw-r--r--Run.hs13
-rw-r--r--ShellPrompt.hs24
2 files changed, 28 insertions, 9 deletions
diff --git a/Run.hs b/Run.hs
index 98da796..7fd9ff7 100644
--- a/Run.hs
+++ b/Run.hs
@@ -18,7 +18,6 @@
module XMonadContrib.Run (
-- * Usage
-- $usage
- runInXTerm,
runProcessWithInput,
runProcessWithInputAndWait,
seconds
@@ -78,13 +77,9 @@ runProcessWithInputAndWait cmd args input timeout = do
getProcessStatus True False pid
return ()
-runInXTerm :: String -> X ()
-runInXTerm com = do
- c <- io $ catch (getEnv "XTERMCMD") (const $ return "xterm")
- spawn ("exec " ++ c ++ " -e " ++ com)
-
--- | Multiplies by ONE MILLION, for use with runProcessWithInputAndWait.
--- Use like:
--- > (5.5 `seconds`)
+{- | Multiplies by ONE MILLION, for use with runProcessWithInputAndWait.
+ Use like:
+ > (5.5 `seconds`)
+-}
seconds :: Rational -> Int
seconds = fromEnum . (* 1000000)
diff --git a/ShellPrompt.hs b/ShellPrompt.hs
index 03d1f6e..493b2c1 100644
--- a/ShellPrompt.hs
+++ b/ShellPrompt.hs
@@ -18,6 +18,9 @@ module XMonadContrib.ShellPrompt (
shellPrompt
, getShellCompl
, split
+ , prompt
+ , safePrompt
+ , runInXTerm
) where
import XMonad
@@ -57,6 +60,27 @@ shellPrompt c = do
cmds <- io $ getCommands
mkXPrompt Shell c (getShellCompl cmds) spawn
+{- | See safe and unsafeSpawn. prompt is an alias for safePrompt; safePrompt and unsafePrompt work on the same principles,
+ but will use XPrompt to interactively query the user for input; the appearance is set by passing an XPConfig as the
+ second argument. The first argument is the program to be run with the interactive input.
+ You would use these like this:
+ > , ((modMask, xK_b ), safePrompt "firefox" greenXPConfig)
+ > , ((modMask .|. shiftMask, xK_c ), prompt ("xterm" ++ " -e") greenXPConfig)
+ Note that you want to use safePrompt for Firefox input, as Firefox wants URLs, and unsafePrompt for the XTerm example
+ because this allows you to easily start a terminal executing an arbitrary command, like 'top'. -}
+prompt, unsafePrompt, safePrompt :: FilePath -> XPConfig -> X ()
+prompt = unsafePrompt
+safePrompt c config = mkXPrompt Shell config (getShellCompl [c]) run
+ where run = safeSpawn c
+unsafePrompt c config = mkXPrompt Shell config (getShellCompl [c]) run
+ where run a = unsafeSpawn $ c ++ " " ++ a
+
+-- This may be better done as a specialization of 'prompt'
+runInXTerm :: String -> X ()
+runInXTerm com = do
+ c <- io $ catch (getEnv "XTERMCMD") (const $ return "xterm")
+ spawn ("exec " ++ c ++ " -e " ++ com)
+
getShellCompl :: [String] -> String -> IO [String]
getShellCompl cmds s | s == "" || last s == ' ' = return []
| otherwise = do