Archive for the ‘GNU/Linux’ Category

I’ve switched to another tiling window manager called awesome and it’s really like its name suggests. It’s more a window manager framework that can be programmed in lua to create a window manager that does exactly what you want it to do.

Awesome has a lua library called naughty for displaying notifications. Now my idea was that whenever my mouse pointer enters the region of the textbox widget that shows the current date and time in a wibox, a popup should show the agenda for this week and dispose automatically when I move the mouse away.

Ok, so here’s the code on the emacs side. It assures that the file /tmp/org-agenda.txt always contains a plain-text export of the current org agenda. It’s created once on emacs startup and after each change to any org agenda file it’ll be updated.

;; update agenda file after changes to org files
(defun th-org-mode-init ()
  (add-hook 'after-save-hook 'th-org-update-agenda-file t t))

(add-hook 'org-mode-hook 'th-org-mode-init)

;; that's the export function
(defun th-org-update-agenda-file (&optional force)
      (let ((file "/tmp/org-agenda.txt"))
        (org-write-agenda file)))))

;; do it once at startup
(th-org-update-agenda-file t)

And here’s the lua code on the awesome side:

-- the current agenda popup
org_agenda_pupup = nil

-- do some highlighting and show the popup
function show_org_agenda ()
   local fd ="/tmp/org-agenda.txt", "r")
   if not fd then
   local text = fd:read("*a")
   -- highlight week agenda line
   text = text:gsub("(Week%-agenda[ ]+%(W%d%d?%):)", "<span style="text-decoration: underline;">%1</span>")
   -- highlight dates
   text = text:gsub("(%w+[ ]+%d%d? %w+ %d%d%d%d[^n]*)", "%1")
   -- highlight times
   text = text:gsub("(%d%d?:%d%d)", "%1")
   -- highlight tags
   text = text:gsub("(:[^ ]+:)([ ]*n)", "%1%2")
   -- highlight TODOs
   text = text:gsub("(TODO) ", "<strong>%1</strong> ")
   -- highlight categories
   text = text:gsub("([ ]+%w+:) ", "%1 ")
   org_agenda_pupup = naughty.notify(
      { text     = text,
        timeout  = 999999999,
        width    = 600,
        position = "bottom_right",
        screen   = mouse.screen })

-- dispose the popup
function dispose_org_agenda ()
   if org_agenda_pupup ~= nil then
      org_agenda_pupup = nil

mydatebox = widget({ type = "textbox", align = "right" }) -- shows the date
mydatebox.mouse_enter = show_org_agenda
mydatebox.mouse_leave = dispose_org_agenda

-- after that the mydatebox is added to some wibox, of course...

And that’s how it looks like.

The Org Agenda in an Awesome/Naughty popup

The Org Agenda in an Awesome/Naughty popup


I have my emacs running as server and two small wrapper scripts ec and et which connect to it with emacsclient (either creating a new frame or opening a terminal frame).

Because I want to do all my system administration (editing files in /etc/) with emacs and don’t want to start another emacs instance as root, I use TRAMP to switch to superuser mode automagically if the opened file is read-only.

Here’s the code (UPDATED: Uses defadvice instead of hooking into find-file-hook, which had the bad effect of find-file-hook running twice.):

(defun th-rename-tramp-buffer ()
  (when (file-remote-p (buffer-file-name))
     (format "%s:%s"
             (file-remote-p (buffer-file-name) 'method)

(add-hook 'find-file-hook

(defadvice find-file (around th-find-file activate)
  "Open FILENAME using tramp's sudo method if it's read-only."
  (if (and (not (file-writable-p (ad-get-arg 0)))
           (y-or-n-p (concat "File "
                             (ad-get-arg 0)
                             " is read-only.  Open it as root? ")))
      (th-find-file-sudo (ad-get-arg 0))

(defun th-find-file-sudo (file)
  "Opens FILE with root privileges."
  (interactive "F")
  (set-buffer (find-file (concat "/sudo::" file))))

Now whenever I type ec /some/file/i/have/no/permissions/to/write (or emacsclient [-c|-t] /some/root/file, emacs asks me to re-open it using TRAMP’s sudo method.

My funky ZSH prompt

Posted: December 6, 2007 in Applications, GNU/Linux, ZSH
Tags: , ,

Here’s the config for my ZSH prompt:
local blue_op="%{$fg[blue]%}[%{$reset_color%}"
local blue_cp="%{$fg[blue]%}]%{$reset_color%}"
local path_p="${blue_op}%~${blue_cp}"
local user_host="${blue_op}%n@%m${blue_cp}"
local ret_status="${blue_op}%?${blue_cp}"
local hist_no="${blue_op}%h${blue_cp}"
local smiley="%(?,%{$fg[green]%}:%)%{$reset_color%},%{$fg[red]%}:(%{$reset_color%})"
╰─${blue_op}${smiley}${blue_cp} %# "
local cur_cmd="${blue_op}%_${blue_cp}"
PROMPT2="${cur_cmd}> "

It looks like this. ZSH prompt

It has two lines. The first displays the path of the current working directory, then the user and hostname, then the return value of the last executed command, and the last item is the command’s number in the history.

The second line displays a green smiley, if the last command worked well, or a red smiley, if it failed.

I took some inspirations from the prompt of strcat, see

There are some keystrokes that are quite painful if you type them over and over. The worst ones are those where your thumb has to wander below your palm. On my german dvorak keyboard M-q (which runs fill-paragraph in emacs) is such a candidate. But all one-handed keystrokes can be a source of RSI.

Today some newsgroup posting pointed my attention to the topic of sticky keys. With sticky modifier keys, if you want to type C-x M-a Z for example, you can instead type its linear form Control x Meta a Shift z. As I said, you can, but you can still use the normal press-keys-in-parallel variant.

Ok, so how do you get sticky keys? For the linux console you have to edit your keymap. You have to replace the symbols Control, Alt and Shift with their sticky counter parts SCtrl, SAlt and SShift. I did that for my custom German Dvorak Type II keymap you can fetch from

For X11 you have to get the AccessX utility or use the control center of your desktop environment, if you use one and it provides an option for sticky keys. KDE and GNOME do AFAICT. The command line AccessX tool ax explains itself with ax help.

Happy typing. ;-)