Skip to content

Instantly share code, notes, and snippets.

@denlab
Created July 3, 2011 13:43
Show Gist options
  • Save denlab/1062234 to your computer and use it in GitHub Desktop.
Save denlab/1062234 to your computer and use it in GitHub Desktop.
Fabrice's .stumpwmrc commented
;; Hey, Emacs! This is a -*- lisp -*- file!
;;; .stumpwmrc --- my StumpWM Init File
;; Copyright (C) 2008-2010 Fabrice Niessen
;; Time-stamp: <2010-06-21 Mon 14:30 sva on mundaneum>
;; Author: Fabrice Niessen <(concat "fni" at-symbol "mygooglest.com")>
;; Keywords: stumpwm, dotfile, config
;; $Revision: 1933 $
;; $Date: 2010-06-21 14:06:22 +0200 (Mon, 21 Jun 2010) $
;;* Comment:
;; This config is known to work with stumpwm 0.9.6, and should work with
;; later versions as well.
;; You should specify full path to contrib modules. (load "~/...") works on
;; CLisp but doesn't work on SBCL...
;;* TODO
;; - Add googlers or wikiers functions?
;;* Code:
;; This file is only provided as an example. Customize it to your own taste!
;; See http://www.nongnu.org/stumpwm/manual/stumpwm.html
(in-package :stumpwm)
(message "Loading rc!")
(run-shell-command "rm .xsession-errors")
;; (run-shell-command "~/bin/x-second-monitor")
;; ;; load Swank so we can connect with SLIME
;; (load "/usr/share/emacs/site-lisp/slime/swank-loader.lisp")
;; (swank-loader:init)
;; (defvar *swank-p* nil)
;;
;; ;; define swank command to start swank server on port 4005
;; (defcommand swank () ()
;; "Starts a swank server on port 4005 and notifies the user."
;; (setf stumpwm:*top-level-error-action* :break)
;; (if *swank-p*
;; (message "Swank server already running.")
;; (progn
;; (swank:create-server :port 4005
;; :style swank:*communication-style*
;; :dont-close t)
;; (setf *swank-p* t)
;; (message "Starting swank on port 4005."))))
;;** 2 (info "(stumpwm)Key Bindings")
;; `*top-map*' is the top level key map. This is where you'll find the
;; binding for the prefix map.
;;
;; `*root-map*' is the keymap by default bound to `C-t'. It is known as the
;; prefix map.
;;*** --2.2 (info "(stumpwm)Binding Keys")
;; TODO Check this out!
;; unison synchronization
(defcommand unison-synchronization (host) ((:rest "Synchro host: "))
(run-shell-command (concat "/home/sva/bin/unisync " host)))
;; screenshot-to-website
(defcommand screenshot-to-website (filename) ((:rest "Filename: "))
(run-shell-command
(format nil
"import -window root /home/m0rg/code/html/patzy/screenshots/~a"
filename)))
;; screenshot-to-file
(defcommand screenshot-to-file (filename) ((:rest "Filename: "))
(run-shell-command
(format nil "import -window root ~a" filename)))
;; Keyboard Shortcuts
;;**** Sound
;; mixer
;; XXX `m' conflicts with `lastmsg'
(define-key *root-map* (kbd "m") "exec xterm -rv -e alsamixer")
;;**** Desktop
;; launch Emacs
(defcommand emacs () () ;! redefining emacs command
"Start Emacs or switch to it, if it is already running."
(run-or-raise "emacs" '(:class "Emacs")))
;; mail notification
;; use `blink -c -r 1' (TODO Install `blinkd') for new mail (to be configured
;; via `gconf-editor' -> apps -> mail-notification -> commands)
;; launch Web browser
(defcommand firefox () ()
"Start Firefox or switch to it, if it is already running."
(run-or-raise "firefox" '(:class "Firefox")))
(define-key *root-map* (kbd "f") "firefox")
;; run an `urxvt' terminal (instead of `xterm')
;; TODO Install `rxvt-unicode'
;; FIXME If urxvt is not installed, let default keybinding
(defcommand urxvt () ()
"Start an urxvt instance or switch to it, if it is already running."
(run-or-raise "urxvt" '(:instance "urxvt")))
(define-key *root-map* (kbd "c") "urxvt")
; How do I scroll in a `urxvt' or in a `Ctrl-Alt-F6' command prompt?
; Shift + Pg Up/Dn
;
; How do I paste text to an `urxvt' terminal?
; Shift + Insert
;; too dangerous (easily typed!)
;; ;; log out
;; (define-key *root-map* (kbd "q") "quit")
;; ;; shutdown
;; (define-key *root-map* (kbd "Delete") "exec gksudo halt")
;; lock screen (x or L or l?)
(define-key *root-map* (kbd "L") "exec xtrlock")
(define-key *root-map* (kbd "M-l") "exec xset dpms force off")
;; take a screenshot of the screen (using PrtSc)
;; TODO Install `imagemagick' (for getting the `import' command)
(define-key *root-map* (kbd "Print")
"exec import -window root png:$HOME/Desktop/screenshot_$(date +%F_%H-%M-%S).png")
;; take a screenshot of a window (using Alt-PrtSc)
;; TODO Install `scrot'
(defcommand part-screenshot () ()
"Take a screenshot of only the active window."
(run-shell-command "scrot -s"))
(define-key *top-map* (kbd "M-Print") "part-screenshot")
;;**** Window Management
;; push the window in the adjacent frame
(define-key *root-map* (kbd "C-Up") "move-window up")
(define-key *root-map* (kbd "C-Left") "move-window left")
(define-key *root-map* (kbd "C-Down") "move-window down")
(define-key *root-map* (kbd "C-Right") "move-window right")
(define-key *root-map* (kbd "Delete") "repack-window-numbers")
(define-key *root-map* (kbd "I") "show-window-properties")
;;**** Custom Shortcuts
;; keyboard layout (toggling between "qwerty-gb" and "azwerty-fr" via
;; `Caps_Lock')
(run-shell-command "setxkbmap -model \"pc105\" -layout \"gb,fr\" -option \"grp:caps_toggle,grp_led:scroll\"")
;; FIXME grp_led:caps??
;; aptitude
(define-key *root-map* (kbd "&") "exec xterm -rv -e aptitude")
;; openvpn
;; (define-key *root-map* (kbd "o") "exec xterm -name vpnup -rv -e \"sudo openvpn mcbe.vpn\"")
;; ;; (define-key *root-map* (kbd "o") "exec xterm -name vpnup -rv -e \"sudo openvpn --config mcbe.vpn\"")
;; FIXME This does not work.
(defcommand openvpn () ()
(run-or-raise
"urxvt -title openvpn -cd /home/sva/.hide/ -e sudo ./openvpn mcbe.vpn"
'(:title "openvpn" :instance "urxvt" :class "URxvt"))
:all-screens t
:all-groups t)
(define-key *root-map* (kbd "o") "openvpn")
;;** Commands
(defparameter *start-menu*
'(
("Graphics"
("Color Picker" "gcolor2")
("GIMP" "gimp")
("Inkscape" "inkscape")
("Picasa" "picasa")
("Scanner" "xsane")
("OCR" "gocr"))
("Internet"
("Filezilla" "filezilla")
("Firefox" "firefox")
("Skype" "skype"))
("Office"
("OpenOffice.org" "openoffice"))
("Sound and Video"
("Europe 1" "mplayer http://vipicecast.yacast.net/europe1")
("RTL" "mplayer http://streaming.radio.rtl.fr/rtl-1-44-96")
("Mixer" "xterm -rv -e alsamixer")
("K3b Burner" "k3b")
("Eject CD-ROM" "eject cdrom"))
("System Tools"
("Calculator" "speedcrunch")
("Disk space" "filelight")
("File Manager" "nautilus") ; thunar
("Nvidia X Server" "nvidia-settings")
("Power Preferences" "gnome-power-preferences")
("Printers" "system-config-printer")
("Terminal Server" "tsclient")
; Turn on "Enable window manager's key bindings" for prefix key to
; be passed seamlessly (when *not* in full screen).
; Toggle between full screen and not full screen using
; `Ctrl-Alt-Enter'.
;; > In the case of Rdesktop you have to launch the app with the option
;; > '-K' so Stump can retain control over the key combinations that you
;; > input inside the remote session.
("VirtualBox" "VirtualBox"))
("X Windows Tools"
("Clipboard" "xclipboard")
("Fonts" "xfontsel")
("Ruler" "kruler")
("Events" "xev"))
))
(defcommand menu () ()
"docstring"
(labels ((pick (options)
(let ((selection (stumpwm::select-from-menu
(current-screen) options "")))
(cond
((null selection)
(throw 'stumpwm::error "Abort."))
((stringp (second selection))
(second selection))
(t
(pick (cdr selection)))))))
(let ((choice (pick *start-menu*)))
(run-shell-command choice))))
(define-key *root-map* (kbd ".") "menu")
(defcommand reinit () ()
"docstring"
(run-commands "reload" "loadrc"))
;; from http://en.wikipedia.org/wiki/User:Gwern/.stumpwmrc
(defun cat (&rest strings) "A shortcut for (concatenate 'string foo bar)."
(apply 'concatenate 'string strings))
;; Web browsing commands
;; Get the X selection and order the GUI browser to open it. Presumably it
;; is a HTTP address.
(defcommand open-selection-browser () ()
"docstring"
(run-shell-command (cat "exec firefox " (get-x-selection))))
;; Ask user for a search string and search Wikipedia for it.
;; (defcommand wikipedia ((search-string :string "wikipedia " :string)) ()
;; (check-type search-string string)
;; (run-shell-command (cat "exec firefox wikipedia " search-string)))
;; Web jump (works for Google)
(defmacro make-web-jump (name prefix)
`(defcommand ,name (search) ((search :rest ,(concatenate 'string name " search: ")))
(substitute #\+ #\Space search)
(run-shell-command (concatenate 'string ,prefix search))))
;; (make-web-jump "ggoogle" "firefox http://www.google.com/search?q=")
(define-key *root-map* (kbd "z") "google")
;; ask the user for a search string and search for it in Wikipedia
(defcommand wikipedia (search)
((:string "Search in Wikipedia for: "))
"docstring"
(check-type search string)
(substitute #\+ #\Space search)
(run-shell-command (cat "firefox http://www.wikipedia.org/wiki/" search)))
;; ask the user for a search string and search for it in Google
(defcommand google (search)
((:string "Search in Google for: "))
"docstring"
(check-type search string)
(substitute #\+ #\Space search)
(run-shell-command (cat "firefox http://www.google.com/search?q=" search)))
;; courtesy of Peter Seibel
(defmacro with-gensyms ((&rest names) &body body)
`(let ,(loop for n in names collect `(,n (gensym)))
,@body))
(defmacro program-with-layout (name &key (command (string-downcase (string name)))
(props `'(:class ,(string-capitalize command))))
(with-gensyms (s w h files-path layout rules)
`(defcommand ,name () ()
(let* ((,s (current-screen))
(,w (prin1-to-string (screen-width ,s)))
(,h (prin1-to-string (screen-height ,s)))
(,files-path "/home/sva/etc/stumpwm_files/")
(,layout (concat ,files-path ,command "-layout-" ,w "x" ,h))
(,rules (concat ,files-path ,command "-rules")))
(gnew ,command)
(restore-from-file ,layout)
(restore-window-placement-rules ,rules)
(run-or-raise ,command ,props)
(place-existing-windows))))) ; needed if command was already run
(program-with-layout gimp)
;;** 3 (info "(stumpwm)Message and Input Bar")
;;*** 3.1 (info "(stumpwm)Customizing The Bar")
;; Find a font of your choice in `xfontsel' and put it here.
;; set the font for the message bar and input bar
;; (set-font "-*-FreeMono-medium-r-*-*-6*")
(set-font "-adobe-helvetica-medium-r-normal--10*")
;;** 4 (info "(stumpwm)Windows")
;; how to format the window list
(setf *window-format* "^B%m%n^b %40t ")
;;*** 4.2 (info "(stumpwm)Customizing Window Appearance")
;; width in pixels given to the borders of windows with maxsize or ratio
;; hints
(setf *maxsize-border-width* 1)
;; width in pixels given to the borders of transient or pop-up windows
(setf *transient-border-width* 1)
;; width in pixels given to the borders of regular windows
(setf *normal-border-width* 1)
;; TODO Install `xloadimage' (for getting the `xsetbg' command)
(run-shell-command "which xsetbg && xsetbg -fullscreen /usr/share/backgrounds/GrassinA.jpg")
;; set the border color for focused windows
(set-focus-color "orange") ; `white' by default
(set-unfocus-color "palegreen3")
;; input focus is transferred to the window you click on
(setf *mouse-focus-policy* :click)
;; (defun banish-mouse (from-frame to-frame)
;; (run-commands "banish"))
;; (add-hook *focus-window-hook* 'banish-mouse)
;;** 5 (info "(stumpwm)Frames")
;; make frames 1-indexed
;; See http://lists.gnu.org/archive/html/stumpwm-devel/2006-08/msg00002.html
(setf *frame-number-map* "1234567890")
;; FIXME Does not work
;; from simias
(defun shift-windows-forward (frames win)
(when frames
(let ((frame (car frames)))
(shift-windows-forward (cdr frames)
(frame-window frame))
(when win
(pull-window win frame)))))
(defcommand rotate-windows () ()
(let* ((frames (group-frames (current-group)))
(win (frame-window (car (last frames)))))
(shift-windows-forward frames win)))
;; swap 2 windows
(define-key *root-map* (kbd "~") "rotate-windows")
;; from simias
(defcommand toggle-split () ()
(let* ((group (current-group))
(cur-frame (tile-group-current-frame group))
(frames (group-frames group)))
(if (eq (length frames) 2)
(progn (if (or (neighbour :left cur-frame frames)
(neighbour :right cur-frame frames))
(progn
(only)
(vsplit))
(progn
(only)
(hsplit))))
(message "Works only with 2 frames"))))
;; toggle between vertical split and horizontal split
(define-key *root-map* (kbd "|") "toggle-split")
;;** 6 The (info "(stumpwm)Mode-line")
;; modeline foreground color
(setf *mode-line-foreground-color* "palegreen3")
;; modeline border color
(setf *mode-line-border-color* "palegreen3")
;; set contrib directory
(set-contrib-dir "/home/sva/src/stumpwm/contrib")
;; load a few modules
(mapcar #'load-module '("cpu"
"mem"
"battery-portable"
"net"
"wifi"
"disk"))
(defconstant *day-names*
'("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"))
(defun current-date ()
"Returns the date formatted as `2009-11-16 Mon 11:34:03'."
(multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(get-decoded-time)
(format nil "~d-~2,'0d-~2,'0d ~a ^B~2,'0d:~2,'0d:~2,'0d^b"
year month date (nth day-of-week *day-names*)
hour minute second)))
;; FIXME ppp0 comes after lo0; hence, the IP is wrong
(defun current-ip ()
"Returns the IP address in CIDR notation."
(run-shell-command
"IP_ADDRESS=`ifconfig | grep 'inet addr:' | head -n 1 | sed 's/.*addr:\\([0-9.]*\\).*/\\1/'`; NETMASK=`ifconfig | grep 'inet addr:' | head -n 1 | sed 's/.*Mask:\\([0-9.]*\\).*/\\1/'`; NETWORK=`ipcalc -n -b $IP_ADDRESS $NETMASK | grep Network | awk '{print $2}'`; echo -n IP:$IP_ADDRESS`echo $NETWORK | sed 's/.*\\(\\/.*\\)/\\1/g' | tr -d '[:cntrl:]'`"
t))
(defun current-gw ()
"Returns the default gateway."
(run-shell-command
"echo -n Gw:`ip route show | grep default | awk '{print $3}' | tr -d '[:cntrl:]'`"
t))
;; TODO Get this in a lighter manner, by parsing /proc/net/route. See, for
;; example, contribs/net.lisp.
;; %h :: List the number of the head the mode-line belongs to
;; %w :: List all windows in the current group windows using `*window-format*'
;; %W :: List all windows on the current head of the current group using `*window-format*'
;; %g :: List the groups using `*group-format*'
;; colors
;; 0 = black, 1 = red, 2 = green, 3 = yellow,
;; 4 = blue, 5 = magenta, 6 = cyan, 7 = white
;; %N :: notifications
;; what's `^n'?
;; what's `%48'?
;; what will be displayed on the modeline (sort of taskbar) for each screen
;; FIXME `run-shell-command' in mode-line could be the source of StumpWM crashes?
(setf *screen-mode-line-format*
(list
;; date
"^6*" '(:eval (current-date)) ; defined above
;; cpu | mem | battery
" | %D | %c %C (%f) %t | %M | %B"
;; ip and gw
" | " '(:eval (current-ip)) " " '(:eval (current-gw)) ; defined above
;; net | wifi
" | %l | %I"
'(:eval (run-shell-command "echo" t))
"^2*" "[^B%n^b] %W%48"))
;; how many seconds elapse between each update of the modeline
(setf *mode-line-timeout* 1) ; must be set *before* turning on the modeline
;; turn on the modeline
(if (not (head-mode-line (current-head)))
(toggle-mode-line (current-screen) (current-head)))
; A head is a physical monitor. A screen is a section of video memory
; that heads are mapped on to. When using xinerama you generally have
; 1 screen and many heads. When not using xinerama each screen is a
; physical monitor so you have many screens with only one head on them.
;; number of padding pixels between the modeline text and the top/bottom of
;; the modeline
(setf *mode-line-pad-y* 0)
;; modeline background color
(setf *mode-line-background-color* "black")
;; TODO add hook so I get notified when people say my name on IRC or IM me
(defun echo-urgent-window (target)
(message-no-timeout "~a has an message for you." (window-title target)))
(add-hook *urgent-window-hook* 'echo-urgent-window)
;;** 7 (info "(stumpwm)Groups")
;; Super_L-F1..F9 to change workspace
;; Is there a way to share windows between several groups?
;; Try using tags. A window can have arbitrary set of tags, and there is a
;; command to pull all windows which have any of the specified tags to current
;; group. Bind some tags to F1-F10 instead of groups, and you are done.
;; create the other groups
(run-commands "gnewbg Other")
;;** 9 (info "(stumpwm)Interacting With Unix")
;; shell program used by `run-shell-command' (`sh' by default, which is *not*
;; `bash' nor `zsh')
(setq *shell-program* (stumpwm::getenv "SHELL")) ; `getenv' is not exported
;; system tray
;; ;; TODO Check if it exists
;; (run-shell-command "which stalonetray && stalonetray")
;; From http://archive.ubuntu.com/ubuntu/pool/universe/t/trayer/
(run-shell-command "/usr/bin/trayer --SetDockType false --transparent true --expand false")
;; (run-shell-command "/usr/bin/trayer")
;; dzen2 -fn fixed -w 600 -ta l -fg '#ffffff' -bg '#006699' -e ''
;; dzen provides customisable status bars
;; 9menu
;; dmenu provides a simple popup menu for launching programs
(define-key *root-map* (kbd "P")
"exec dmenu_run -i -b -p \"run command:\"") ; simple $PATH to run commands
;; (run-shell-command "/usr/bin/gnome-settings-daemon")
;; ;;(run-shell-command "/usr/bin/gnome-panel &")
;; (run-shell-command "/usr/bin/nm-applet &")
;; (run-shell-command "/usr/bin/bluetooth-applet &")
;; (run-shell-command "/usr/bin/pactl load-module module-x11-xsmp &")
;; other programs in the system tray
(run-shell-command "gnome-power-manager")
(run-shell-command "nm-applet --sm-disable") ; network manager
;; (run-shell-command "which mail-notification && mail-notification --sm-disable")
(run-shell-command "which log-event-notify && log-event-notify")
; TODO Install `inotify-tools' and
; `libnotify-bin' for this to work as
; expected
(run-shell-command "emacs")
;; (run-shell-command "urxvt")
(run-shell-command "update-manager")
;; fix volume levels
(run-shell-command "~/bin/volume-control")
;; so i modified my keymap settings so that compaq keys2-4 are mapped to
;; function keys F13-F15 (i only have F1 to F12…)
;;
;; -- .Xmodmap --
;; keycode 160 = F13
;; keycode 174 = F14
;; keycode 176 = F15
;;
;; and my corresponding .fluxbox/keys file
;;
;; -- snip --
;;
;; # laptop keymap
;; F13 :ExecCommand /bin/bash ~/.mykbd
;; F14 :ExecCommand /usr/bin/amixer sset PCM 5%-
;; F15 :ExecCommand /usr/bin/amixer sset PCM 5%+
;;** 11 (info "(stumpwm)Miscellaneous Commands")
;; This forces the user to set the focus into the screen before being able to
;; use the prefix key for the first time!
;; ;; get rid of cursor initially
;; (banish-pointer)
;;*** 11.2 (info "(stumpwm)Debugging StumpWM")
;; turn on debugging (look at `.xsession-errors')
(setf stumpwm::*debug-level* 10) ; get rid of debug by setting level to 0
;;*** 11.4 (info "(stumpwm)Getting Help")
(setf *help-map*
(let ((m (make-sparse-keymap)))
(define-key m (kbd "m") "man")
(define-key m (kbd "i") "info")
(define-key m (kbd "v") "describe-variable")
(define-key m (kbd "f") "describe-function")
(define-key m (kbd "k") "describe-key")
(define-key m (kbd "w") "where-is")
m))
;;** 12 (info "(stumpwm)Hooks")
;; display the key sequence in progress
(defun key-press-hook (key key-seq cmd)
(declare (ignore key))
(unless (eq *top-map* *resize-map*)
(let ((*message-window-gravity* :bottom-right))
(message "Key sequence: ~a" (print-key-seq (reverse key-seq))))
(when (stringp cmd)
;; give 'em time to read it
(sleep 0.5))))
(defmacro replace-hook (hook fn)
`(remove-hook ,hook ,fn)
`(add-hook ,hook ,fn))
(replace-hook *key-press-hook* 'key-press-hook)
;;** Prefix Key
;; I tend to place "system-wide" window manager shortcut keys consistently
;; on Super-<something> rather than the horrible defaults that can get in
;; the way of Emacs' use (various Control and Alt bindings).
;; same as `keycode 133 = F20' in `~/.Xmodmap', `133' (TO BE CHECKED WITH
;; `xev') being the left "Windows" key, aka `Super_L'
;; (run-shell-command "xmodmap -e 'keycode 133 = F20'" t)
;; change the prefix key
(set-prefix-key (kbd "ISO_Level3_Shift")) ;; `Alt Gr'
;; This is for the sake of Emacs.
;; Local Variables:
;; coding: utf-8
;; mode: emacs-lisp
;; mode: outline-minor
;; ispell-local-dictionary: "en_US"
;; End:
;;; .stumpwmrc ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment