Source

dotfiles / shellrc

#!/bin/sh
# ~/.shellrc - shell agnostic rc file, sourced by bashrc, zshrc etc.
# NOTE: Try to keep things in here sh-compliant.

#### Setup prompt colour ############################################
function getPromptColour {
  #  31     32      33    34       35    36
  # red  green  yellow  blue  magenta  cyan
  case "$1" in
    firefly-desky ) echo "green"   ;;
    firefly-lappy ) echo "red"     ;;
    firefly-xen   ) echo "yellow"  ;;
    firefly-n900  ) echo "cyan"    ;;
    *.kth.se      ) echo "blue"    ;;
    Nokia-N900    ) echo "cyan"    ;;
    *             ) echo "magenta" ;;
  esac
}

unamen="`uname -n`"
prompt_color="`getPromptColour $unamen`"


#### Vars & aliases #################################################

# Make sure that a command exists and allows the given flags, by attempting to
# run it with said flags + "--version" (to prevent default operation).
#   Makes the assumption that the program complains about unrecognized flags,
# and that it has a "--version" flag that returns zero on success.
function try_alias {
  to_be_bound="$1" # $to_be_bound is the command that is to be bound,
  shift            # $* is the target of the aliasing.

  # Attempt to run the command...
  $@ --version >/dev/null 2>&1 \
  && alias $to_be_bound="$*"
  # ...and make sure that it exited with an exit code of 0.
}

# Like try_alias, but for environment variables
function try_export {
  # see `try_alias` above
  to_be_bound="$1"  # the variable to assign & export
  shift

  # Attempt to run..
  $@ --version >/dev/null 2>&1 \
  && export $to_be_bound="$*"
}

## Environment variables
export EDITOR=vim
#export VISUAL=gvim
export PAGER=less
export BROWSER=luakit

#if [ x$TERM != xlinux ]; then
#  export TERM=xterm
#  export TERM=rxvt-unicode-256color
#fi

export PATH="$PATH:$HOME/bin:$HOME/node_modules/.bin:$HOME/.cabal/bin"

export DEVKITPRO="/opt/devkitpro"
export DEVKITARM="${DEVKITPRO}/devkitARM"

export XMODIFIERS=@im-ibus
export GTK_IM_MODULE=ibus
export QT_IM_MODULE=ibus

### Utility variables
export brightness="/sys/class/backlight/intel_backlight/brightness"


## Aliases
try_alias  ls    ls --color=auto
try_alias  grep  grep -P --color=auto
try_alias  sed   ssed -R
#try_export PAGER "/usr/share/vim/vim73/macros/less.sh"
try_export PAGER "$HOME/.vim/macros/less.sh"

# `less` is in my muscle memory...
#alias less=$PAGER

alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."

alias ff_colours='for i in `seq 30 37`; do echo -e "\e[0;${i}m $i \e[1;${i}m $i \e[m"; done'

alias make-luakit="make clean && USE_UNIQUE=1 USE_LUAJIT=1 CC=clang make -j4"

# allow vim's :h to work in the shell, and make it behave like less
function :h {
  vim +":h $1" +'wincmd o' +'nnoremap q :q!<CR>'
}