Personal tools

Xmonad/Config archive/Gwern's xmonad.hs

From HaskellWiki

< Xmonad | Config archive(Difference between revisions)
Jump to: navigation, search
(update)
(update for 0.10)
(16 intermediate revisions by one user not shown)
Line 1: Line 1:
 
<haskell>
 
<haskell>
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
+
import Data.Map as M (fromList,union, Map())
module Main where
 
 
import Data.Bits (Bits((.|.)))
 
import Data.Map as M (M.fromList, M.union, Map())
 
 
 
import XMonad
 
import XMonad
-- XMonad re-exports Graphics.X11, so we can't enumerate imports without also
+
import XMonad.Actions.GridSelect (defaultGSConfig, goToSelected)
-- enumerating all the keys and such-like. The stuff from XMonad itself is:
+
import XMonad.Actions.Search (google, wayback, wikipedia, wiktionary, selectSearch, promptSearch)
-- (XConfig(layoutHook, keys, modMask, focusedBorderColor, normalBorderColor,
+
import XMonad.Actions.WindowGo (raiseMaybe, raiseBrowser, raiseEditor, runOrRaise)
-- terminal, XConfig), X())
+
import XMonad.Config.Gnome (gnomeConfig)
import XMonad.Actions.Search (google, wayback, wikipedia, selectSearch, promptSearch)
+
import XMonad.Hooks.EwmhDesktops (ewmhDesktopsLogHook)
import XMonad.Config (defaultConfig)
+
import XMonad.Hooks.ManageDocks (avoidStruts, manageDocks)
import XMonad.Layout (Full(..), Mirror(..), Tall(..), (|||))
+
import XMonad.Hooks.UrgencyHook (withUrgencyHook, FocusHook(..))
 
import XMonad.Layout.NoBorders (smartBorders)
 
import XMonad.Layout.NoBorders (smartBorders)
import XMonad.Main (xmonad)
+
import XMonad.Prompt (greenXPConfig)
import XMonad.Operations (kill, windows)
 
import XMonad.Prompt (XPPosition(Top), XPConfig(historySize, height, position,
 
promptBorderWidth, fgColor, bgColor, font), defaultXPConfig)
 
 
import XMonad.Prompt.Shell (shellPrompt, prompt, safePrompt)
 
import XMonad.Prompt.Shell (shellPrompt, prompt, safePrompt)
import XMonad.StackSet as W (W.focusUp, W.focusDown)
+
import XMonad.StackSet as W (focusUp, focusDown, sink)
import XMonad.Util.Run (unsafeSpawn, runInTerm)
+
import XMonad.Util.Run (unsafeSpawn, runInTerm, safeSpawnProg)
 
import XMonad.Util.XSelection (safePromptSelection)
 
import XMonad.Util.XSelection (safePromptSelection)
import XMonad.Actions.WindowGo (className, title, runOrRaise, raiseMaybe, (=?))
+
import XMonad.Prompt.AppendFile
   
 
main :: IO ()
 
main :: IO ()
main = xmonad myConfig
+
main = spawn "killall unclutter;unclutter;" >> spawn "killall urxvtd;urxvtd -q -f -o" >> xmonad myConfig
  +
where myConfig = withUrgencyHook FocusHook $ gnomeConfig { focusedBorderColor = "red"
  +
, keys = \c -> myKeys c `M.union` keys defaultConfig c
  +
, layoutHook = avoidStruts $ smartBorders (Full ||| tiled ||| Mirror tiled)
  +
, logHook = ewmhDesktopsLogHook
  +
, manageHook = myManageHook
  +
, modMask = mod4Mask
  +
, normalBorderColor = "grey"
  +
, terminal = "urxvtc"
  +
, XMonad.workspaces = ["web", "irc", "code", "4"] }
  +
where tiled = Tall 1 0.03 0.5
   
{- Begin custom bindings.
+
{- Important things to note: We specifically don't use 'managehook
these add a need for: urxvt, Firefox, and Emacs -}
+
defaultConfig, since I don't like floating mplayer and I don't use the other
myConfig = defaultConfig
+
specified applications. Otherwise, we have manageDocks there to allow use of
{ terminal = "urxvt"
+
gnome-panel; Firefox/Emacs/Irssi go to their designated workspaces. -}
, normalBorderColor = "grey"
+
myManageHook :: ManageHook
, focusedBorderColor = "red"
+
myManageHook = composeAll [moveT "Amphetype" "code",
, modMask = mod4Mask
+
moveT "Brain Workshop 4.8.1" "code",
, keys = \c -> myKeys c `M.union` keys defaultConfig c
+
moveC "Emacs" "code",
, layoutHook = smartBorders (Full ||| tiled ||| Mirror tiled) }
+
moveC "Iceweasel" "web",
+
moveC "Gimp" "irc",
tiled :: Tall a
+
moveC "gscan2pdf" "code",
tiled = Tall 1 0.03 0.5
+
moveC "Mnemosyne" "code",
+
moveT "irssi" "irc",
ff, term :: String
+
className =? "defcon.bin.x86" --> unfloat,
ff = "firefox"
+
className =? "Darwinia" --> unfloat,
term = "urxvtc"
+
className =? "gnome-panel" --> doIgnore,
+
className =? "Mnemosyne" --> unfloat,
greenXPConfig :: XPConfig
+
title =? "Brain Workshop 4.8.1" --> unfloat]
greenXPConfig = defaultXPConfig { font = "9x15bold,xft:DejaVu Vera Sans Mono"
+
<+> manageDocks
, bgColor = "black"
+
where moveC c w = className =? c --> doShift w
, fgColor = "green"
+
moveT t w = title =? t --> doShift w
, promptBorderWidth = 0
+
unfloat = ask >>= doF . W.sink
, position = Top
 
, height = 16
 
, historySize = 256 }
 
   
 
myKeys :: XConfig t -> M.Map (KeyMask, KeySym) (X ())
 
myKeys :: XConfig t -> M.Map (KeyMask, KeySym) (X ())
myKeys (XConfig {modMask = modm}) =
+
myKeys (XConfig {modMask = m, terminal = term}) = M.fromList [ -- rebind standard keys
M.fromList $
+
((m .|. shiftMask,xK_p), shellPrompt greenXPConfig)
[ ((modm .|. shiftMask, xK_p ), shellPrompt greenXPConfig)
+
, ((m, xK_k), kill)
, ((modm, xK_k ), kill)
+
, ((m, xK_n), windows W.focusDown)
, ((modm, xK_n ), windows W.focusDown)
+
, ((m, xK_p), windows W.focusUp)
, ((modm, xK_p ), windows W.focusUp)
+
, ((m, xK_z), withFocused $ windows . W.sink) -- unfloat
+
-- Custom bindings and commands
, ((modm .|. shiftMask, xK_b ), safePromptSelection ff)
+
, ((m, xK_s), goToSelected defaultGSConfig)
, ((modm .|. shiftMask, xK_c ), prompt (term ++ " -e") greenXPConfig)
+
, ((m ,xK_a), safeSpawnProg "/home/gwern/bin/bin/amphetype")
, ((modm .|. shiftMask, xK_d ), raiseMaybe (runInTerm "-title elinks" "elinks") (title =? "elinks"))
+
, ((m, xK_b), safePrompt "firefox" greenXPConfig)
, ((modm .|. shiftMask, xK_e ), prompt "emacsclient -a emacs" greenXPConfig)
+
, ((m .|. shiftMask,xK_b), safePromptSelection "firefox")
, ((modm .|. shiftMask, xK_g ), selectSearch ff google)
+
, ((m, xK_c), safeSpawnProg term)
, ((modm .|. shiftMask, xK_t ), selectSearch ff wikipedia)
+
, ((m .|. shiftMask,xK_c), prompt (term ++ " -e") greenXPConfig)
, ((modm .|. shiftMask, xK_y ), selectSearch ff wayback)
+
, ((m .|. shiftMask,xK_d), raiseMaybe (runInTerm "-title elinks" "elinks") (title =? "elinks"))
, ((modm, xK_Print ), unsafeSpawn "import -quality 90 -window root png:$HOME/xwd-$(date +%s)$$.png")
+
, ((m, xK_e), raiseEditor)
, ((modm, xK_b ), safePrompt ff greenXPConfig)
+
, ((m .|. shiftMask,xK_e), prompt "emacs" greenXPConfig)
, ((modm, xK_c ), unsafeSpawn term)
+
, ((m, xK_g), promptSearch greenXPConfig google)
, ((modm, xK_e ), runOrRaise "emacs" (className =? "Emacs"))
+
, ((m .|. shiftMask,xK_g), selectSearch google)
, ((modm, xK_g ), promptSearch greenXPConfig ff google)
+
, ((m, xK_t), promptSearch greenXPConfig wikipedia)
, ((modm, xK_t ), promptSearch greenXPConfig ff wikipedia)
+
, ((m .|. shiftMask,xK_t), selectSearch wikipedia)
, ((modm, xK_y ), promptSearch greenXPConfig ff wayback)
+
, ((m, xK_y), promptSearch greenXPConfig wayback)
, ((modm, xK_i ), raiseMaybe (runInTerm "-title irssi" "sh -c 'screen -r irssi'") (title =? "irssi"))
+
, ((m .|. shiftMask,xK_y), selectSearch wayback)
, ((modm, xK_m ), raiseMaybe (runInTerm "-title mutt" "sh -c 'mutt'") (title =? "mutt"))
+
, ((m .|. shiftMask,xK_w), selectSearch wiktionary)
, ((modm, xK_r ), raiseMaybe (runInTerm "-title rtorrent" "sh -c 'screen -r rtorrent'") (title =? "rtorrent"))
+
, ((m, xK_w), safeSpawnProg "/home/gwern/bin/bin/brainworkshop")
, ((modm, xK_d ), runOrRaise "firefox" (className =? "Firefox")) ]
+
, ((m, xK_Print), unsafeSpawn "import -quality 90 -window root png:$HOME/xwd-$(date +%s)$$.png")
  +
, ((m, xK_i), raiseMaybe (runInTerm "-title irssi" "sh -c 'screen -r irssi'") (title =? "irssi"))
  +
, ((m .|. shiftMask,xK_i), spawn "xclip -o|tr '\n' ' '|sed -e 's/- //' > ~/z.txt && screen -S irssi -X readbuf ~/z.txt && screen -S irssi -X paste .;rm ~/z.txt")
  +
, ((m, xK_m), runOrRaise "mnemosyne" (className =? "Mnemosyne"))
  +
, ((m, xK_r), raiseMaybe (runInTerm "-title rtorrent" "sh -c 'screen -r rtorrent'") (title =? "rtorrent"))
  +
, ((m, xK_d), raiseBrowser)
  +
, ((m, xK_x), spawn ("date>>"++lg) >> appendFilePrompt greenXPConfig lg)]
  +
where lg = "/home/gwern/doc/archive/wiki/log.txt"
 
</haskell>
 
</haskell>

Revision as of 13:16, 4 December 2011

import Data.Map as M (fromList,union, Map())
import XMonad
import XMonad.Actions.GridSelect (defaultGSConfig, goToSelected)
import XMonad.Actions.Search (google, wayback, wikipedia, wiktionary, selectSearch, promptSearch)
import XMonad.Actions.WindowGo (raiseMaybe, raiseBrowser, raiseEditor, runOrRaise)
import XMonad.Config.Gnome (gnomeConfig)
import XMonad.Hooks.EwmhDesktops (ewmhDesktopsLogHook)
import XMonad.Hooks.ManageDocks (avoidStruts, manageDocks)
import XMonad.Hooks.UrgencyHook (withUrgencyHook, FocusHook(..))
import XMonad.Layout.NoBorders (smartBorders)
import XMonad.Prompt (greenXPConfig)
import XMonad.Prompt.Shell (shellPrompt, prompt, safePrompt)
import XMonad.StackSet as W (focusUp, focusDown, sink)
import XMonad.Util.Run (unsafeSpawn, runInTerm, safeSpawnProg)
import XMonad.Util.XSelection (safePromptSelection)
import XMonad.Prompt.AppendFile
 
main :: IO ()
main = spawn "killall unclutter;unclutter;" >> spawn "killall urxvtd;urxvtd -q -f -o" >> xmonad myConfig
 where myConfig = withUrgencyHook FocusHook $ gnomeConfig { focusedBorderColor = "red"
                         , keys = \c -> myKeys c `M.union` keys defaultConfig c
                         , layoutHook =  avoidStruts $ smartBorders (Full ||| tiled ||| Mirror tiled)
                         , logHook    = ewmhDesktopsLogHook
                         , manageHook = myManageHook
                         , modMask = mod4Mask
                         , normalBorderColor  = "grey"
                         , terminal = "urxvtc"
                         , XMonad.workspaces = ["web", "irc", "code", "4"] }
           where tiled = Tall 1 0.03 0.5
 
{- Important things to note: We specifically don't use 'managehook
   defaultConfig, since I don't like floating mplayer and I don't use the other
   specified applications. Otherwise, we have manageDocks there to allow use of
   gnome-panel; Firefox/Emacs/Irssi go to their designated workspaces. -}
myManageHook :: ManageHook
myManageHook = composeAll [moveT "Amphetype" "code",
                           moveT "Brain Workshop 4.8.1" "code",
                           moveC "Emacs"     "code",
                           moveC "Iceweasel" "web",
                           moveC "Gimp"      "irc",
                           moveC "gscan2pdf" "code",
                           moveC "Mnemosyne" "code",
                           moveT "irssi"     "irc",
                           className =? "defcon.bin.x86" --> unfloat,
                           className =? "Darwinia" --> unfloat,
                           className =? "gnome-panel" --> doIgnore,
                           className =? "Mnemosyne" --> unfloat,
                           title     =? "Brain Workshop 4.8.1" --> unfloat]
                           <+> manageDocks
          where moveC c w = className =? c --> doShift w
                moveT t w = title     =? t --> doShift w
                unfloat = ask >>= doF . W.sink
 
myKeys :: XConfig t -> M.Map (KeyMask, KeySym) (X ())
myKeys (XConfig {modMask = m, terminal = term}) = M.fromList [ -- rebind standard keys
            ((m .|. shiftMask,xK_p), shellPrompt greenXPConfig)
          , ((m,              xK_k), kill)
          , ((m,              xK_n), windows W.focusDown)
          , ((m,              xK_p), windows W.focusUp)
          , ((m,              xK_z), withFocused $ windows . W.sink) -- unfloat
          -- Custom bindings and commands
          , ((m,              xK_s), goToSelected defaultGSConfig)
          , ((m               ,xK_a), safeSpawnProg "/home/gwern/bin/bin/amphetype")
          , ((m,              xK_b), safePrompt "firefox" greenXPConfig)
          , ((m .|. shiftMask,xK_b), safePromptSelection "firefox")
          , ((m,              xK_c), safeSpawnProg term)
          , ((m .|. shiftMask,xK_c), prompt (term ++ " -e") greenXPConfig)
          , ((m .|. shiftMask,xK_d), raiseMaybe (runInTerm "-title elinks" "elinks") (title =? "elinks"))
          , ((m,              xK_e), raiseEditor)
          , ((m .|. shiftMask,xK_e), prompt "emacs" greenXPConfig)
          , ((m,              xK_g), promptSearch greenXPConfig google)
          , ((m .|. shiftMask,xK_g), selectSearch google)
          , ((m,              xK_t), promptSearch greenXPConfig wikipedia)
          , ((m .|. shiftMask,xK_t), selectSearch wikipedia)
          , ((m,              xK_y), promptSearch greenXPConfig wayback)
          , ((m .|. shiftMask,xK_y), selectSearch wayback)
          , ((m .|. shiftMask,xK_w), selectSearch wiktionary)
          , ((m,              xK_w), safeSpawnProg "/home/gwern/bin/bin/brainworkshop")
          , ((m,          xK_Print), unsafeSpawn "import -quality 90 -window root png:$HOME/xwd-$(date +%s)$$.png")
          , ((m,              xK_i), raiseMaybe (runInTerm "-title irssi" "sh -c 'screen -r irssi'") (title =? "irssi"))
          , ((m .|. shiftMask,xK_i), spawn "xclip -o|tr '\n' ' '|sed -e 's/- //' > ~/z.txt && screen -S irssi -X readbuf ~/z.txt && screen -S irssi -X paste .;rm ~/z.txt")
          , ((m,              xK_m), runOrRaise "mnemosyne" (className =? "Mnemosyne"))
          , ((m,              xK_r), raiseMaybe (runInTerm "-title rtorrent" "sh -c 'screen -r rtorrent'") (title =? "rtorrent"))
          , ((m,              xK_d), raiseBrowser)
          , ((m,              xK_x), spawn ("date>>"++lg) >> appendFilePrompt greenXPConfig lg)]
  where lg = "/home/gwern/doc/archive/wiki/log.txt"