Posts tagged ‘zsh’

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

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.

Git status in zsh prompt – the easy way

Copy the completion file to your home directory:

$ cp /usr/share/git/completion/git-completion.bash ~/.git-completion.bash

Add the following to your ~/.zshrc

75
76
77
78
79
80
81
source ~/.git-completion.bash
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM="auto"
PROMPT='%{$fg[cyan]%}%n%{$fg[blue]%}@%{$fg[magenta]%}%m %{$fg[yellow]%}%~ %{$fg[red]%}$(__git_ps1 " (%s)")
%{$fg[green]%}%#%{$reset_color%} '

You may be seeing the following error in your prompt whenever you cd into a local git repository:

local:2: command not found: svn_url_pattern

As discussed here, this is due to syntactical differences between bash and zsh. Make the following changes in ~/.git-completion.bash to fix this:

--- /usr/share/git/completion/git-completion.bash 2012-03-13 10:30:26.000000000 +1100
+++ ./git-completion.bash 2012-03-26 10:22:19.957256527 +1100
@@ -94,8 +94,9 @@ __gitdir ()
__git_ps1_show_upstream ()
{
local key value
- local svn_remote=() svn_url_pattern count n
+ local svn_remote svn_url_pattern count n
local upstream=git legacy="" verbose=""
+ svn_remote=()

# get some config options from git-config
local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\n' '\n ')"
@@ -291,7 +292,7 @@ __git_ps1 ()

if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
- u="%"
+ u="!"
fi
fi