A minimalistic rfkill gtk gui for toggling your bluetooth and wireless

I just wrote a little rfkill frontend with gtk+. If you use an acer laptop you should load acer-wmi, make sure you have acpi_osi=Linux in your kernel boot.

The following will bind the rfkill key to XF86WLAN

setkeycodes e013 246

Here’s the obligatory screenshot:

If you don’t have an acer device you should launch the app as:

grfkill -w wlandevice -b bluetoothdevice

Use rfkill list to find out the right names.

The source is available github It’s based on Gary’s gtk experiments(the author of urfkilld)

Arch users can use the following:

sudo packer -S grfkill

Changing the cursor color within tmux based on vi mode

As outlined on SE and SU you can execute actions in zsh when you change between normal and insert mode in a vi mode zsh session.

For changing the cursor color see the snippet below.

# use cursor as indicator of vi mode
zle-keymap-select () {
  if [ $KEYMAP = vicmd ]; then
    if [[ $TMUX = '' ]]; then
      echo -ne "\033]12;Red\007"
    else
      printf '\033Ptmux;\033\033]12;red\007\033\\'
    fi
  else
    if [[ $TMUX = '' ]]; then
      echo -ne "\033]12;Grey\007"
    else
      printf '\033Ptmux;\033\033]12;grey\007\033\\'
    fi
  fi
}
zle-line-init () {
  zle -K viins
  echo -ne "\033]12;Grey\007"
}
zle -N zle-keymap-select
zle -N zle-line-init

Put it somewhere in your zshrc and your cursor should switch to red when you enter normal mode and become grey again when you leave it.

launching firefox with text/html entry in mutt 1.5,21

I recently decided that I might want to see some html mails in a real browser instead of a w3m dump. For example when I need to click on the stupid reset password link, which is sent in the html only mail from easyjet.

Figured it would be the easiest thing in the world to do, just change the mailcap entry for text/html and you’re set. But instead I get this:

mailcap entry for type text/html not found

The bad part: It obviously doesn’t work that way. Turns out certain changes in the auto_view behaviour of mutt 1.5.21 cause this. There’s even a bugreport on the matter

The good part: You can now have 2 mailcap entries for text/html. One will be used to display the message inside of mutt. The other will run firefox by pressing m (view-mailcap) in the file list.

My mailcap thus starts as follows:

text/html; firefox %s ;
text/html; w3m -T text/html -dump %s; copiousoutput

Note that the order of the entries is important. Should you switch it both m and the pager will only show the dump.

ruby-enterprise/ruby-1.8.7 in fedora 15 or archlinux

The following bugs occur when trying to install ruby enterprise on distros like fedora 15 or archlinux:

/bin/sh ./libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. -I. -I./src  -I./src   -DNO_TCMALLOC_SAMPLES -pthread -DNDEBUG -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-cfree -fno-builtin-memalign -fno-builtin-posix_memalign -fno-builtin-valloc -fno-builtin-pvalloc  -DNO_FRAME_POINTER -g -O2 -c -o libtcmalloc_minimal_la-tcmalloc.lo `test -f 'src/tcmalloc.cc' || echo
'./'`src/tcmalloc.cc
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I. -I./src -I./src -DNO_TCMALLOC_SAMPLES -pthread -DNDEBUG -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-cfree -fno-builtin-memalign -fno-builtin-posix_memalign -fno-builtin-valloc -fno-builtin-pvalloc -DNO_FRAME_POINTER -g -O2 -c src/tcmalloc.cc  -fPIC -DPIC -o .libs/libtcmalloc_minimal_la-tcmalloc.o
src/tcmalloc.cc:1672:54: error: conflicting declaration ‘void* (* __memalign_hook)(size_t, size_t, const void*)’
/usr/include/malloc.h:183:39: error: ‘__memalign_hook’ has a previous declaration as ‘void* (* volatile __memalign_hook)(size_t, size_t, const void*)’
make: *** [libtcmalloc_minimal_la-tcmalloc.lo] Error 1

and

gcc -I/opt/local/include -I. -I/opt/local/include -I../.. -I../../. -I../.././ext/dl -DHAVE_DLFCN_H -DHAVE_DLOPEN -DHAVE_DLCLOSE -DHAVE_DLSYM -DHAVE_DLERROR    -I. -fPIC -g -O2   -fno-defer-pop -fno-omit-frame-pointer  -c dl.c
In file included from dl.c:104:0:
callback.func:1:1: warning: data definition has no type or storage class [enabled by default]
callback.func:1:7: error: expected identifier or ‘(’ before ‘long’
In file included from dl.c:104:0:
callback.func:78:33: error: expected ‘)’ before ‘(’ token
callback.func:79:3: warning: data definition has no type or storage class [enabled by default]
callback.func:79:24: error: ‘proc’ undeclared here (not in a function)
callback.func:79:39: error: ‘argc’ undeclared here (not in a function)
callback.func:79:45: error: ‘argv’ undeclared here (not in a function)
callback.func:82:1: error: expected identifier or ‘(’ before ‘}’ token
dl.c:106:1: error: expected ‘;’, ‘,’ or ‘)’ before ‘static’
make[1]: *** [dl.o] Error 1

The fix is outlined in this stackoverflow post

Download my patch and use it with:

rvm install --force --patch 0001-archlinux.patch ree

using mutt, mu, offlineimap

I have long experimented with an optimal mail setup. As some readers may be aware there are a lot of tutorials on how how to use mutt and offlineimap. I have had a mutt and offlineimap setup for quite a long time, however I decided to tune it a bit lately.

Why mutt? There are numerous articles out there referencing more efficient email handling. Merlin Mann’s InboxZero is quite popular. The basic idea is to never let any mail unprocessed, don’t show notifications and only check mails in certain intervals. If you use Apple Mail, you can use Mail Act-On which is quite nice as well. However mutt is much more efficient and flexible in it’s mail processing capabilities. At the same time it’s much faster than thunderbird.

I had switched to thunderbird when I discarded my old hackintosh netbook, with it’s slow Atom CPU. The most annoying part to me it seemed, was the fact that it would always bug me with nagscreens when my laptops connection dropped. (and the power consumption)

The offlineimap setup I use thus makes some use of NetworkManager to start and stop offlineimap and msmtpq when an internet connection exists. First of all I have two offlineimap setups, both offlineimap setups create the mailbox folders for mutt automatically as described in the offlineimap manual.

[general]
accounts = Gmail
maxsyncaccounts = 1
# This will suppress anything but errors
ui = Noninteractive.Quiet

[mbnames]
enabled = yes
filename = ~/.mutt/mailboxes
header = "mailboxes "
peritem = "+%(accountname)s/%(foldername)s"
sep = " "
footer = "\n"


[Account Gmail]
localrepository = GmailLocal
remoterepository = GmailRemote
autorefresh = 10
quick       = 5

[Repository GmailLocal]
type = Maildir
localfolders = ~/Mail/GMAIL
restoreatime = no

[Repository GmailRemote]
type = IMAP
ssl = yes
remotehost = imap.gmail.com
remoteuser = fubar@gmail.com

nametrans = lambda foldername: re.sub ('.*Drafts.*', 'drafts',
                               re.sub ('.*Sent Mail.*', 'sent',
                               re.sub ('.*Starred.*', 'flagged', folder)))
folderfilter = lambda foldername: foldername in ['.*INBOX.*', 'archives', 'pending']

Since I use the same hotkey for drafts and sent mail, I use nametrans to have these folders have a consistent name across all my mail accounts. The password for foobar@gmail.com is set in the .netrc file. Also this is the minimal sync setting for whenever I’m on 3G or similar. Since my laptop has an internal wireless and ethernet device eth0 and wlan0 are what I use to assume that there is proper internet existing. NetworkManager will thus call my dispatch.d script which will in turn launch
offlineimap and msmtpq.

#!/bin/sh -e

INTERFACE=$1 # The interface which is brought up or down
STATUS=$2 # The new state of the interface

USER=misterfoo
HOME=/home/$USER
CACHE=$HOME/.cache/daemonize
DAEMONIZE=/usr/sbin/daemonize
OFFLINEIMAP=/usr/bin/offlineimap
NOTIFY=/usr/bin/notify-send

# If the display variable is unset, find the correct display number
# and set the variable.
if [ -z "$DISPLAY" ]; then
    console=`fgconsole`
    dispnum=`ps t tty$console | sed -n -re 's,.*/X(org)? .*:([0-9]+).*,\2,p'`
    export DISPLAY=":$dispnum"
fi


case "$STATUS" in
	'up') # $INTERFACE is up
		su - $USER -c "$NOTIFY -i info 'Network action' 'Starting offlineimap'"
		if [[ "$INTERFACE" == "eth0" || "$INTERFACE" == "wlan0" ]]; then
			$DAEMONIZE -u $USER -l $CACHE/offline_lock -p $CACHE/offline_pid $OFFLINEIMAP -c $HOME/.offlineimaprc_full
		else
			$DAEMONIZE -u $USER -l $CACHE/offline_lock -p $CACHE/offline_pid $OFFLINEIMAP -c $HOME/.offlineimaprc
		fi
		$DAEMONIZE -u $USER -l $CACHE/msmtp_lock   -p $CACHE/msmtp_pid   $HOME/bin/msmtprun
		;;
	'down') # $INTERFACE is down
		# Check for active interface and down if no one active
		if [ ! `nm-tool|grep State|cut -f2 -d' '` == "connected" ]; then
			su - $USER -c "$NOTIFY -i info 'Network action' 'Stopping offlineimap'"
			kill -TERM `cat $CACHE/offline_pid`
			kill -TERM `cat $CACHE/msmtp_pid`
		fi
		;;
esac

daemonize is a little tool for running any command as daemon. With pid- and lockfile support. Since I use msmtp-queue to send mails and I may or may not want to send mails when I’m offline msmtpq -r needs to be run whenever I connect to the internet. Msmtprun is just that, a script that tries to run msmtq -r once every 5 minutes.

#!/bin/sh

while [ 1 ]; do
    /usr/bin/msmtpq -r &
    sleep 300
done

trap "echo -n exiting... ;kill $!;exit" INT TERM

A mutt config that should work in both linux and osx(with minor adjustments) can be found on my github page

I also recently switch to using mu instead of mairix, it’s much faster and more stable than mairix,

You basically do

mu index --quiet --maildir ~/Mail

once and then add something like

to your crontab. The reindexing is very fast in my experience. You can find the hotkeys I use in my hooks and macros and macros_static files on github.

 Scroll to top