## This is a mess, and needs tidying up. Hopefully it works on linux and (free)bsd, and can be sourced repeatedly without making PATH grow each time. export LANG=en_GB.UTF-8 if [[ $- != *i* ]]; then # Non-interactive shell return fi export HOSTNAME=${HOSTNAME:-$(hostname -s)} export HOST=$HOSTNAME export USER=${USER:-$(whoami)} #if [[ x$SCRIPT == x ]] #then # script -q typescripts/script-`date +%Y%m%d%H%M%S``tty|tr / -`-$$ # exit #fi ## use _ for "internal" functions, and - for those intended to be used ## interactively do_interesting_prompt() { prompt_choice=$1 # col for colour, not column reset_col='\[\e[0m\]' sif_col='\[\e[0;35m\]' tyr_col='\[\e[0;36m\]' basil_col='\[\e[0;33m\]' gendros_col='\[\e[1;37m\]' host_col=$reset_col # TODO make all of these unique again [[ "x$HOST" == "xsif" ]] && host_col=$sif_col [[ "x$HOST" == "xtyr" ]] && host_col=$tyr_col [[ "x$HOST" == "xsagacity" ]] && host_col=$tyr_col [[ "x$HOST" == "xwolfman" ]] && host_col=$tyr_col [[ "x$HOST" == "xbasil" ]] && host_col=$basil_col [[ "x$HOST" == "xgendros" ]] && host_col=$gendros_col [[ "x$HOST" == "xCHESTER" ]] && host_col=$gendros_col [[ "x$HOST" == "xtriton" ]] && host_col=$gendros_col djm_col='\[\e[0;32m\]' wiz_col='\[\e[1;32m\]' deejayem_col='\[\e[1;32m\]' user_col=$reset_col [[ "x$USER" == "xdjm" ]] && user_col=$djm_col [[ "x$USER" == "xwizard" ]] && user_col=$wiz_col [[ "x$USER" == "xdeejayem" ]] && user_col=$deejayem_col [[ "x$USER" == "xdavidmo" ]] && user_col=$deejayem_col at_col='\[\e[0;37m\]' [[ -n "$SSH_CLIENT" ]] && at_col='\[\e[1;33m\]' time_col='\[\e[0;36m\]' # don't clash with host_col [[ "x$HOST" == "xtyr" ]] && time_col='\[\e[1;33m\]' [[ "x$HOST" == "xsagacity" ]] && time_col='\[\e[1;33m\]' [[ "x$HOST" == "xwolfman" ]] && time_col='\[\e[1;33m\]' dir_col='\[\e[1;34m\]' sb_col=$reset_col # Square brackets rb_col='\[\e[0;32m\]' # Round brackets cb_col='\[\e[0;32m\]' # Curly brackets cn_col='\[\e[0;35m\]' # Command numbers # Should vaguely correspond to user_col, but emphasise whether or not # we're using ssh (shutting down the wrong machine is not cool) prompt_col='\[\e[0;32m\]' [[ -n "$SSH_CLIENT" ]] && prompt_col='\[\e[1;32m\]' # col for colour, not column (still) # \h on first line as well as the second, because ^R obscures the second if [[ $prompt_choice -eq 1 ]]; then export PS1="$time_col\d \t $cb_col{$host_col\h$cb_col}\n$sb_col[$user_col\u$at_col@$host_col\h $dir_col\w$sb_col]$rb_col($cn_col\#:\j:"'$?'"$rb_col)$prompt_col\$$reset_col " elif [[ $prompt_choice -eq 2 ]]; then export PS1="$sb_col[$user_col\u$at_col@$host_col\h $dir_col\w$sb_col] $time_col\d \t $rb_col($cn_col\#:\j:"'$?'"$rb_col)\n$prompt_col\$$reset_col " elif [[ $prompt_choice -eq 3 ]]; then export PS1="$sb_col[$user_col\u$at_col@$host_col\h $dir_col\w$sb_col]$rb_col($cn_col\#:\j:"'$?'"$rb_col)$prompt_col\$$reset_col " else do_interesting_prompt 2 fi } do_boring_prompt() { export PS1='\n\d \t {\h}\n[\u@\h \w](\#)\$ ' } if [ -x "$(command -v gdircolors)" ]; then dircolors=`type -p gdircolors` else dircolors=`type -p dircolors` fi #if [ -n "${dircolors+x}" ]; then if [ -n "${dircolors}" ]; then if [[ -f ~/.dir_colors ]]; then eval `$dircolors -b ~/.dir_colors` else eval `$dircolors -b /etc/DIR_COLORS` fi fi #alias ls="ls --color=no" ## PATH - TODO reduce duplication with a function if [[ -n "${PATH/*\/usr\/local\/mpi\/openmpi\/bin:*/}" ]] ; then export PATH="/usr/local/mpi/openmpi/bin:$PATH" fi if [[ -n "${PATH/*\/usr\/local\/texlive\/2009\/bin\/i386-freebsd8:*/}" ]] ; then export PATH="/usr/local/texlive/2009/bin/i386-freebsd8:$PATH" fi if [[ -n "${PATH/*$HOME\/local\/bin:*/}" ]] ; then export PATH="$HOME/local/bin:$PATH" fi if [[ -n "${PATH/*$HOME\/.local\/bin:*/}" ]] ; then export PATH="$HOME/.local/bin:$PATH" fi if [[ -n "${PATH/*$HOME\/games:*/}" ]] ; then export PATH="$HOME/games:$PATH" fi if [[ -n "${PATH/*$HOME\/bin:*/}" ]] ; then export PATH="$HOME/bin:$PATH" fi ## MANPATH if [[ -n "${MANPATH/*\/usr\/local\/mpi\/openmpi\/man:*/}" ]] ; then export PATH="/usr/local/mpi/openmpi/man:$PATH" fi if [[ -n "${MANPATH/*$HOME\/local\/man:*/}" ]] ; then export PATH="$HOME/local/man:$PATH" fi if [[ -n "${MANPATH/*$HOME\/local\/share\/man:*/}" ]] ; then export PATH="$HOME/local/share/man:$PATH" fi # Should test to see if we're capable of being interesting or not (TODO) do_interesting_prompt 2 #do_boring_prompt # Change the window title of X terminals case $TERM in xterm*|rxvt*|Eterm) PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"' ;; # screen) # don't want this with tmux... # PROMPT_COMMAND='echo -ne "\033k${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"' # ;; esac [ -f /etc/bash_completion ] && source /etc/bash_completion #[ -f /usr/local/etc/bash_completion ] && source /usr/local/etc/bash_completion [ -f /usr/local/share/bash-completion/bash_completion.sh ] && source /usr/local/share/bash-completion/bash_completion.sh set -C #export PATH=${HOME}/bin:${HOME}/local/bin:${HOME}/.local/bin:$PATH #export PATH=/usr/local/games/:$PATH #export MPD_HOST=redacted@localhost #export MPD_PORT=6600 #export NNTPSERVER=news.btopenworld.com #export NNTPSERVER=news.individual.net #export NNTPSERVER=public.teranews.com #export NNTPSERVER=reader.news4all.se export HOSTNAME=`hostname -s` export HOST=$HOSTNAME [ -f /usr/bin/vim ] && export EDITOR=/usr/bin/vim [ -f /usr/local/bin/vim ] && export EDITOR=/usr/local/bin/vim export PAGER=/usr/bin/less #export PERL5LIB="${HOME}/perl/share/perl/:${HOME}/lib/perl/:${HOME}/perl5/" export MOZ_NO_PANGO=1 alias y=yes alias s="sudo" alias svi="sudo vim" alias gvi=gvim alias vi=vim alias viclean="rm *~" alias vidotclean="rm .*~" alias vibinclean="rm ~/bin/*~" alias trunc="colrm 80" alias pc="${HOME}/bin/pocket-cli.py" [ ! -x "$(command -v fetch)" -a -x "$(command -v wget)" ] && alias fetch="wget" [ -f /etc/debian_version ] && alias psearch="apt-cache search" #alias esv='diatheke -b ESV -k' alias esv="bible esv" alias asv="diatheke -b ASV -k" alias niv="diatheke -b NIV -k" alias tniv="diatheke -b TNIV -k" alias kjv="diatheke -b KJV -k" alias nkjv="diatheke -b NKJV -k" alias nasb="diatheke -b NASB -k" alias amp="diatheke -b Amp -k" alias ylt="diatheke -b YLT -k" alias nlt="diatheke -b NLT -k" alias Geneva="diatheke -b Geneva1599 -k" alias hcsb="diatheke -b HCSB -k" alias net="diatheke -b NETfree -k" #alias host=hostx #alias cc_="gcc -ansi -pedantic-errors -Wall -W -Werror -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wbad-function-cast -Wredundant-decls -Wcast-qual -Wundef -Winline -Wpointer-arith -Wcast-align -Wchar-subscripts -Wshadow -Wwrite-strings" #alias noxbell=LD_PRELOAD=$HOME/noxbell/libnoxbell.so alias m='mpc' alias madd='mpc add' alias mcl='mpc clear' alias mp='mpc play' alias mls='mpc playlist' alias msearch='mpc search' # individual aliases so they can be tab completed alias msearchalbum='mpc search album' alias msearchartist='mpc search artist' alias msearchcomposer='mpc search composer' alias msearchfile='mpc search filename' alias msearchtitle='mpc search title' alias msearchfilename='mpc search filename' alias mupdate='mpc update' #source ~/bashmp.sh keychain ~/.ssh/id_dsa keychain ~/.ssh/id_rsa #. ~/.keychain/${HOSTNAME}-sh-gpg . ~/.keychain/${HOSTNAME}-sh #if ! type tac &>/dev/null; then if ! [ -x "$(command -v tac)" ]; then alias tac="sed -n '1!G;\$p;h'" fi shopt -s extglob set -o noclobber set -o vi bind '"\e."':yank-last-arg bind -m vi-command ".":insert-last-argument bind -m vi-insert "\C-l.":clear-screen bind -m vi-insert "\C-a.":beginning-of-line bind -m vi-insert "\C-e.":end-of-line bind -m vi-insert "\C-w.":backward-kill-word export HISTSIZE=2000 export HISTFILESIZE=2000 export HISTCONTROL=ignorespace:ignoredups # easily done with tail and head, but where's the fun in that? nth-from-end() { n=$1 sed -n -e :a -e "\${P;q;};N;$((n+1)),\$D;ba" ${2} } most-recent() { ls -t|head -1 } function google () { w3m http://www.google.co.uk/search?q="$@"; } function swap-lines() { sed -n "${1}h;${2}{p;x;p};2,3!p" ${3} } function maths() { echo "scale=6;${@/x/*}"|bc } function title() { wget --quiet -O- "${1}" | sed -n 's/