UP | HOME

Fish

The fish shell is pretty cool. It is unfortunately also very different, I haven't been able to make CDM work with it, yet, so I can't switch to if full time, besides, I still haven't given up on some scsh.

Table of Contents

1 The prompt

The prompt is easily what I spent the most time on, any time on, really. I find fish very easy to write for.

It shows:

hostname
In magenta. See my eshell prompt.
directory
In the default current working directory color of fish, See my eshell prompt.
git branch
In yellow. See my eshell prompt.
exit status
Green for success, red for failure. See my eshell prompt.
function fish_prompt -d "Write out the prompt"
   set last_status $status
   set current_directory (prompt_pwd)
   set git_branch (git branch --contains HEAD 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
   set cnormal (set_color white)

   echo -n $cnormal

   printf '%s%s%s' (set_color magenta) (hostname|cut -d . -f 1) $cnormal

   if test -n "$current_directory"
       printf ' %s%s%s' (set_color $fish_color_cwd) $current_directory $cnormal
   end

   if test -n "$git_branch"
       printf '@%s%s%s' (set_color yellow) $git_branch $cnormal
   end

   if test $last_status -eq 0
       printf '%s' (set_color --bold green)
   else
       printf '%s' (set_color --bold red)
   end

   printf '>%s ' (set_color normal)
end

2 Commands

Since fish doesn't really support aliases the same way other shells do, it is recommended to write functions for them instead of aliases.

Most of these are just to enable some colors.

function grep
    /bin/grep --color=always $argv
end

function less
    /bin/less -FXRS $argv
end

function ls
    /bin/ls -F --color=always $argv
end

With MySQL, I'd like to use a pager, which should have been set-up as less, to look at big query results.

function mysql
    /usr/bin/mysql --pager $argv
end

With slrn I have to export the NNTPSERVER variable first.

function slrn
    set -x NNTPSERVER 'news.gmane.org'
    /usr/bin/slrn $argv
end

I want to be able to shutdown/reboot as a user. This worked for a while, and is the reason why I started using consolekit, but it hasn't worked in a while.

function shutdown
    dbus-send --system --print-reply \
        --dest="org.freedesktop.ConsoleKit" \
        /org/freedesktop/ConsoleKit/Manager \
        org.freedesktop.ConsoleKit.Manager.Stop
end

function reboot
    dbus-send --system --print-reply \
        --dest="org.freedesktop.ConsoleKit" \
        /org/freedesktop/ConsoleKit/Manager \
        org.freedesktop.ConsoleKit.Manager.Restart
end

I saw this coming by on reddit, I think, and though it is kind of annoying, I thought I'd save it anyway. It's a nice gimmick to have.

function engage
    play -n -c1 synth whitenoise band -n 100 20 band -n 50 20 gain +25 fade h 1 864000 1
end

I saw this coming by somewhere as well, thought it would be handy to keep.

function lscompmod -d "List kernel modules used by hardware"
    lspci -mvk | awk '/^Module/ {print $2}' | sort -u
end

3 Variables

Nothing much different from my other shells.

set -x PAGER 'less -FXRS'
set -x BROWSER firefox
set -x EDITOR 'emacs -nw'

Date: 01-07-2012 14:38:10

Org version 7.8.11 with Emacs version 24

Validate XHTML 1.0