分类: LINUX
2011-03-12 23:32:00
This is a big post that I’ve been putting off for a long time. There are a lot of awesome modules in the XMonad.Prompt.* family, and so there’s a lot to cover here.
XMonad.Prompt itself defines a library for displaying prompts to the user, with autocompletion and customizable look and feel. This module is a back-end library, not intended for use in configurations. What follows is a description and use cases for what I consider the most important modules in the Prompt family, a breakdown of how to customize the look and feel, and a quick rundown of the remaining Prompt modules as of 0.8.
Binding a Prompt action to a key
Nearly all Prompt actions are performed using key bindings. You
can bind them to whichever keys you wish, and they all take the same
basic form. First, you need to import the relevant module, for example
Second, you need to create a keybinding to call a function from it
( modMask conf .|. xK_s, shellPrompt myXPConfig )or using XMonad.Util.EZConfig (which will be the subject of a future PYXM)
("M-s", shellPrompt myXPConfig)The myXPConfig argument is how you customize the look and feel of the prompts. See the section called “Look and Feel Customization” below on how to do this.
Running Commands and Launching Applications: Shell, RunOrRaise, DirExec
One obvious application of Prompt is using it to run shell commands and launch applications. XMonad.Prompt.Shell.shellPrompt works similarly to dmenu, though it allows command-line arguments to be provided as well, and more complete look-and-feel customization.
XMonad.Prompt.RunOrRaise.runOrRaisePrompt uses the XMonad.Actions.RunOrRaise functionality to prompt for an application, launch it if it isn’t running, and summon it if it is.
XMonad.Prompt.DirExec.dirExecPrompt can be used when you want to run programs from a directory not necessarily in your path.
Navigating by Window Titles: Window
XMonad.Prompt.Window‘s windowPromptGoto and windowPromptBring
functions present an autocompleting list of window titles for all the
windows in your session, and either take you to the window you name, or
bring it to your location. This can be very helpful both for tracking
down windows you’ve misplaced, and for bringing remote windows here
without going to find them.
Minimally Disruptive Note-Taking: AppendFile
XMonad.Prompt.AppendFile is my personal favourite find from my research for this article. That might not be fair to Shell and Window, I knew they were there so they weren’t “finds”. What AppendFile does is prompt you for one line of text, which it then appends to a file named in your xmonad.hs.
The intended purpose (there are probably others) is to be able to jot
down quick notes by hitting a key binding and typing one line, without
disrupting whatever other task you were doing.
Arbitrary XMonad Actions: XMonad
XMonad.Prompt.XMonad can be viewed as an extension of your key
bindings. It displays an autocompleting list of actions, each action
bound to an arbitrary X (), like a key binding. You can use the provided
default bindings using xmonadPrompt (which seem to correspond
to roughly the same actions as the default key bindings) or create your
own list of (name,action) pairs with xmonadPromptC.
Look and Feel Customization: XPConfig
The XPConfig data type is defined in XMonad.Prompt,
and it defines the various colours and other parameters that determine
the appearance, position, font, size and behaviour of the Prompt box.
Following is a rundown of the parameters and what they control.
Remaining modules
These modules are well worth mentioning but are straightforward enough to just list quickly:
Conclusion
The XMonad.Prompt.* family is a prime example of the awesome
functionality just waiting to be discovered. Depending on how they use
XMonad, I have seen Ssh, Window and RunOrRaise all make an xmonad user’s day.