mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
Add XMonad.Prompt.Zsh
This commit is contained in:
parent
8ba646aec6
commit
8c39850dc0
@ -50,6 +50,11 @@
|
||||
Declare any window as a scratchpad on the fly. Once declared, the
|
||||
scratchpad behaves like `XMonad.Util.NamedScratchpad`.
|
||||
|
||||
* `XMonad.Prompt.Zsh`
|
||||
|
||||
A version of `XMonad.Prompt.Shell` that lets you use completions supplied by
|
||||
zsh.
|
||||
|
||||
### Bug Fixes and Minor Changes
|
||||
|
||||
* `XMonad.Util.Run`
|
||||
|
64
XMonad/Prompt/Zsh.hs
Normal file
64
XMonad/Prompt/Zsh.hs
Normal file
@ -0,0 +1,64 @@
|
||||
{- |
|
||||
Module : XMonad.Prompt.Zsh
|
||||
Copyright : (C) 2020 Zubin Duggal
|
||||
License : BSD3
|
||||
|
||||
Maintainer : zubin.duggal@gmail.com
|
||||
Stability : unstable
|
||||
Portability : unportable
|
||||
|
||||
A version of "XMonad.Prompt.Shell" that lets you access the awesome power of Zsh
|
||||
completions in your xmonad prompt
|
||||
-}
|
||||
|
||||
module XMonad.Prompt.Zsh
|
||||
( -- * Usage
|
||||
-- $usage
|
||||
Zsh (..)
|
||||
, zshPrompt
|
||||
-- * Utility functions
|
||||
, getZshCompl
|
||||
, stripZsh
|
||||
) where
|
||||
|
||||
import XMonad
|
||||
import XMonad.Prompt
|
||||
import XMonad.Util.Run
|
||||
|
||||
{- $usage
|
||||
1. Grab the @capture.zsh@ script to capture zsh completions from <https://github.com/Valodim/zsh-capture-completion>
|
||||
2. In your @~\/.xmonad\/xmonad.hs@:
|
||||
|
||||
> import XMonad.Prompt
|
||||
> import XMonad.Prompt.Zsh
|
||||
|
||||
3. In your keybindings add something like:
|
||||
|
||||
> , ((modm .|. controlMask, xK_x), zshPrompt def "/path/to/capture.zsh")
|
||||
|
||||
For detailed instruction on editing the key binding see
|
||||
"XMonad.Doc.Extending#Editing_key_bindings". -}
|
||||
|
||||
data Zsh = Zsh
|
||||
|
||||
instance XPrompt Zsh where
|
||||
showXPrompt Zsh = "Run: "
|
||||
completionToCommand _ = stripZsh
|
||||
commandToComplete _ s = s
|
||||
nextCompletion _ s cs = getNextCompletion s (map stripZsh cs)
|
||||
|
||||
zshPrompt :: XPConfig -> FilePath -> X ()
|
||||
zshPrompt c capture = mkXPrompt Zsh c (getZshCompl capture) (\x -> safeSpawn "zsh" ["-c",x])
|
||||
|
||||
getZshCompl :: FilePath -> String -> IO [String]
|
||||
getZshCompl capture s
|
||||
| s == "" = return []
|
||||
| otherwise = processCompls <$> runProcessWithInput capture [s] ""
|
||||
where processCompls = map (\x -> (skipLastWord s ++ filter (/= '\r') x)) . lines
|
||||
|
||||
-- | Removes the argument description from the zsh completion
|
||||
stripZsh :: String -> String
|
||||
stripZsh "" = ""
|
||||
stripZsh (' ':'-':'-':' ':_) = ""
|
||||
stripZsh (x:xs) = x : stripZsh xs
|
||||
|
@ -316,6 +316,7 @@ library
|
||||
XMonad.Prompt.Window
|
||||
XMonad.Prompt.Workspace
|
||||
XMonad.Prompt.XMonad
|
||||
XMonad.Prompt.Zsh
|
||||
XMonad.Util.Cursor
|
||||
XMonad.Util.CustomKeys
|
||||
XMonad.Util.DebugWindow
|
||||
|
Loading…
x
Reference in New Issue
Block a user