Archive for September, 2010

Bash history essentials


I’ve been using the Bash history since a long time, but in a rather limited way. I’d use the “history” command, !<num> to execute command again, !* to get all parameters of the last command, and Ctrl-r to match previous commands.

This article by symkat showed me a lot more interesting history features.

Here’s my personal list of what a productive developer needs to know about Bash history:

  • history: Show the history in case you get lost.
  • !<num>: Execute line again, where is the number shown by history.
  • Ctrl-p: Browse the history backwards. Also on cursor-up, but doesn’t make you leave touch typing position.
  • Ctrl-r: Search backwards. Invaluable. Matches can anchor anywhere. Pressing it repeatedly shows older matches.
  • !$: Substitutes for the last word of the previous line. Very useful for doing something else with the same thing. For example, you might first say ls -R very/long/path, then du !$ to show the directory’s size.
  • Esc-. or Alt-. (that’s Alt-PERIOD): Like !$, but Bash inserts the word into your current line right away, so you can check or modify it.

Also, setting the HISTCONTROL environment variable to “Ignoreboth” to ignore duplicate history entries and commands starting with a space is a must.

Simple Frame Initialization


Is anyone else confused by the variety and complexity of packages for Emacs session management out there? I read through some of the documentation recently, but in the end I was overwhelmed and didn’t install anything.

Session management is about open files, buffer positions and the like on the one hand, and about the frame configuration on the other hand. I realized that my actual use case for frame session management was so simple that I could trivially implement it myself.

All I really wanted was that my Emacs would launch in fullscreen, and split it into two or three vertical windows, depending on whether I was using the laptop screen or the larger external screen. If I could accept the two-split as default, and run a function to create the three-window setup when needed, then all I’d need were some small initialization functions.

Like almost everything else, Emacs exposes its window and frame handling in an ELisp API. So here we go:

(defun my-big-screen ()
  "Set up frame for external screen, with three windows."
  (my-initialize-frame 3))

(defun my-small-screen ()
  "Set up frame for laptop screen, with two windows."
  (my-initialize-frame 2))

(defun my-initialize-frame (columns)
  "Set current frame to fullscreen and split it into COLUMNS
vertical windows."
  (set-frame-parameter nil :fullscreen t)
  (dotimes (not-used (1- columns))

This is not rocket science and I hope it didn’t bore the Planet Emacsen readers, but maybe it encourages people to get creative with their Emacs’ frames and windows. Start with the Emacs Lisp manual, chapters 28 (Windows) and 29 (Frames).