module XMonad.Prompt.Zsh
(
Zsh (..)
, zshPrompt
, getZshCompl
, stripZsh
) where
import XMonad
import XMonad.Prompt
import XMonad.Util.Run
data Zsh = Zsh
instance XPrompt Zsh where
showXPrompt :: Zsh -> String
showXPrompt Zsh
Zsh = String
"Run: "
completionToCommand :: Zsh -> String -> String
completionToCommand Zsh
_ = String -> String
stripZsh
commandToComplete :: Zsh -> String -> String
commandToComplete Zsh
_ String
s = String
s
nextCompletion :: Zsh -> String -> [String] -> String
nextCompletion Zsh
_ String
s [String]
cs = String -> [String] -> String
getNextCompletion String
s (forall a b. (a -> b) -> [a] -> [b]
map String -> String
stripZsh [String]
cs)
zshPrompt :: XPConfig -> FilePath -> X ()
zshPrompt :: XPConfig -> String -> X ()
zshPrompt XPConfig
c String
capture = forall p.
XPrompt p =>
p -> XPConfig -> ComplFunction -> (String -> X ()) -> X ()
mkXPrompt Zsh
Zsh XPConfig
c (String -> ComplFunction
getZshCompl String
capture) (\String
x -> forall (m :: * -> *). MonadIO m => String -> [String] -> m ()
safeSpawn String
"zsh" [String
"-c",String
x])
getZshCompl :: FilePath -> String -> IO [String]
getZshCompl :: String -> ComplFunction
getZshCompl String
capture String
s
| String
s forall a. Eq a => a -> a -> Bool
== String
"" = forall (m :: * -> *) a. Monad m => a -> m a
return []
| Bool
otherwise = String -> [String]
processCompls forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
MonadIO m =>
String -> [String] -> String -> m String
runProcessWithInput String
capture [String
s] String
""
where processCompls :: String -> [String]
processCompls = forall a b. (a -> b) -> [a] -> [b]
map (\String
x -> String -> String
skipLastWord String
s forall a. [a] -> [a] -> [a]
++ forall a. (a -> Bool) -> [a] -> [a]
filter (forall a. Eq a => a -> a -> Bool
/= Char
'\r') String
x) forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
lines
stripZsh :: String -> String
stripZsh :: String -> String
stripZsh String
"" = String
""
stripZsh (Char
' ':Char
'-':Char
'-':Char
' ':String
_) = String
""
stripZsh (Char
x:String
xs) = Char
x forall a. a -> [a] -> [a]
: String -> String
stripZsh String
xs