Archive for April 2012

Better dircolors with Solarized

When using the recommended Solarized colours in ~/.Xresources, dircolors output isn’t very distinguishable.

Here’s what it looks like:

Here’s what we want:

Copy the default dircolors to $HOME

$ dircolors -p > ~/.dir_colours

Make the following changes to ~/.dir_colours

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--- .dir_colours.orig	2012-04-21 19:48:39.029808008 +1000
+++ .dir_colours	2012-04-21 18:28:38.645813921 +1000
@@ -68,8 +68,8 @@ TERM xterm-debian
 #NORMAL 00 # no color code at all
 #FILE 00 # regular file: use no color at all
 RESET 0 # reset to "normal" color
-DIR 01;34 # directory
-LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
+DIR 00;34 # directory
+LINK 00;36 # symbolic link. (If you set this to 'target' instead of a
  # numerical value, the color is as for the file pointed to.)
 MULTIHARDLINK 00 # regular file with more than one link
 FIFO 40;33 # pipe
@@ -85,7 +85,7 @@ STICKY_OTHER_WRITABLE 30;42 # dir that i
 OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
 STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable
 # This is for files with execute permission:
-EXEC 01;32
+EXEC 00;32
 # List any file extensions like '.gz' or '.tar' that you would like ls
 # to colorize below. Put the extension, a space, and the color init string.
 # (and any comments you want to add after a '#')
@@ -184,19 +184,19 @@ EXEC 01;32
 .ogv 01;35
 .ogx 01;35
 # audio formats
-.aac 00;36
-.au 00;36
-.flac 00;36
-.mid 00;36
-.midi 00;36
-.mka 00;36
-.mp3 00;36
-.mpc 00;36
-.ogg 00;36
-.ra 00;36
-.wav 00;36
+.aac 00;33
+.au 00;33
+.flac 00;33
+.mid 00;33
+.midi 00;33
+.mka 00;33
+.mp3 00;33
+.mpc 00;33
+.ogg 00;33
+.ra 00;33
+.wav 00;33
 # http://wiki.xiph.org/index.php/MIME_Types_and_File_Extensions
-.axa 00;36
-.oga 00;36
-.spx 00;36
-.xspf 00;36
+.axa 00;33
+.oga 00;33
+.spx 00;33
+.xspf 00;33

Finally, run the following line to append to the colours to ~/.bashrc or ~/.zshrc:

$ echo "eval $(dircolors ~/.dir_colours)" >> ~/.zshrc

Setting up eggdrop

Eggdrop is an open source IRC bot. Since no ArchWiki article exists for eggdrop, here’s a quick getting started guide.

Download the aur eggdrop package:

$ yaourt -S eggdrop

Copy the configuration file to a local directory:

# mkdir ~/.eggdrop
# cp /etc/eggdrop.conf ~/.eggdrop

Modify ~/.eggdrop/eggdrop.conf using the eggdrop wiki as a guide:
http://eggwiki.org/Eggdrop.conf

Start eggdrop:

cd ~/.eggdrop
eggdrop eggdrop.conf

Message your bot from your IRC client to setup an admin password:

/msg YourBotsName hello

Control your bot by via DCC:

/ctcp YourBotsName chat
/dcc chat YourBotsName

To start eggdrop when you startx, add to ~/.xinitrc:

cd ~/.eggdrop && eggdrop eggdrop.conf &

Fixing Cousine from ttf-google-webfonts

This refers to the latest ttf-google-webfonts aur package (version: 2369-1, revision: f50f26f0c77c).

Problem #1: tilde character looks like a dash when font size is less than 10
Problem #2: semicolon glyph is missing

I’ve entered a bug report here

Fix:

  1. Download latest files from the source:
    https://googlefontdirectory.googlecode.com/hg/cousine/src/
  2. Install fontforge
    # pacman -S fontforge
  3. Open Cousine-Regular.ttf in fontforge
  4. Element -> Font Info -> PS Names
  5. Change font name to distinguish it from the ttf-google-webfonts package
    Fontname: CousineRegen
    Family Name: Cousine Regen
    Name of Humans: Cousine Regen
  6. OK -> Change
  7. File -> Generate Fonts -> Truetype -> untick Validate before saving -> Save
  8. Repeat 3-7 for the bold, italic and boldItalic ttf files
  9. Add CousineRegen*.ttf to a directory in your FontPath
  10. Refresh font cache
    # fc-cache -fv

tl;dr: Source ttf fonts provide missing glyph. Regenerating fonts in fontforge fixes tilde character at low fontsizes.

Before vs after:

Make IPython recognise virtualenv

IPython doesn’t currently recognise when you’re in a virtualenv. (See high priority issue).

There are currently 3 popular workarounds for those without root access.

Workaround #1. Add the following to ~/.bashrc or ~/.zshrc:

alias ipython="python /usr/bin/ipython"

Workaround #2. Install a local virtualenv copy of ipython:

$ pip install ipython

Workaround #3. Create ~/.config/ipython/profile_default/ipython_virtualenv.py with the following (for Python3):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Modified for Python 3 (https://gist.github.com/1759781)
from os import environ
from os.path import join, sep
 
if 'VIRTUAL_ENV' in environ:
    virtual_env_dir = environ['VIRTUAL_ENV']
    activate_this = join(virtual_env_dir, "bin", "activate_this.py")
    exec(compile(open(activate_this).read(), activate_this, 'exec'),
         dict(__file__=activate_this))
    virtual_env_name = virtual_env_dir.split(sep)[-1]
    message = 'virtualenv "{0}" ({1})]'.format(virtual_env_name,
                                               virtual_env_dir)
    print(message)
    del virtual_env_dir
del environ, join, sep

Add the following to ~/.config/ipython/profile_default/ipython_config.py:

c.InteractiveShellApp.exec_files = ['ipython_virtualenv.py']

From the IPython FAQ, those with root access can access it by modifying the shebang in /usr/bin/ipython

1
#!/usr/bin/env python

Zsh: Change cursor colour to indicate vi-mode

From Arch Forums.

It’s possible to change the cursor in urxvt when using zsh to indicate the current vi mode (e.g. grey for INSERT, red for NORMAL).

Append the following to ~/.zshrc

33
34
35
36
37
38
39
40
41
42
43
44
45
46
# change cursor colour depending on vi mode
zle-keymap-select () {
  if [ "$TERM" = "rxvt-unicode-256color" ]; then
if [ $KEYMAP = vicmd ]; then
echo -ne "\033]12;red\007"
    else
echo -ne "\033]12;grey\007"
    fi
fi
}; zle -N zle-keymap-select
zle-line-init () {
  zle -K viins
  echo -ne "\033]12;grey\007"
}; zle -N zle-line-init

Zsh auto-detects and sets the editing mode (default: emacs) to vi if $EDITOR=vim. If this environment variable isn’t set, or is set to something else, you’ll also need to add bindkey -v to your ~/.zshrc.