# Sean B. Palmer's .shellrc # Designed to work for bash and zsh # License: GPL 2; share and enjoy! # Author: Sean B. Palmer, inamidst.com # Date: 2002-2005 VERSION='2006-01-12' if [ $BASH_VERSION ] then export SHELLNAME=bash elif [ $ZSH_VERSION ] then export SHELLNAME=zsh fi # Check whether we're running over ssh remotely or not SUB=${SSH_CLIENT%%.*} export REMOTE=0 if [[ (! -z $SSH_CLIENT) && ($SUB != '192') && ($SUB != '127') ]] then export REMOTE=1 fi # Set an appropriate PS1 for the shell and connection if [ $SHELLNAME = zsh -a $REMOTE = 0 ] then PS1=$(echo -n "\n%{\e[32m%}%n@%m %{\e[36m%}%~%{\e[0m%}\n$ ") elif [ $SHELLNAME = zsh ] then PS1=$(echo -n "\n%n@%m %~\n$ ") elif [ $REMOTE = 0 ] then PS1='\[\033]0;\w\007\n\033[32m\]\u@\h \[\033[33m\w\033[0m\]\n$ ' else PS1='\n\u@\h:\w\n\$ ' fi PS2='> ' # Stop Ctrl+S and Ctrl+Q from being annoying stty start "" stty stop "" # Set the other important environment variables # if [ -d /misc ] # then export MISC='/misc' # else export MISC="$HOME" # fi # export PATH="$PATH:$MISC/tools/util" # export CDPATH=".:$HOME:$MISC/projects:$MISC/tools:$MISC/web:$MISC:/" export HISTFILE=~/.zsh_history export HISTSIZE=50000 export SAVEHIST=50000 export DIRSTACKSIZE=10 # @@ zsh only? export HISTCONTROL=ignoredups export INPUTRC=~/.inputrc export TZ=WET export LANG=en_GB.UTF-8 # According to its manpage, crontab using "the editor specified by the # VISUAL or EDITOR environment variables [or] /usr/bin/editor export EDITOR=nano umask 022 # Some zsh specific options if [ $SHELLNAME = zsh ]; then # @@ cf. http://swhack.com/logs/2005-06-03#T21-40-26 TIMEFMT=$'real\t%*Es\nuser\t%*Us\nsys \t%*Ss\ncpu \t%P' # @@ compctl -g "*(-/) .*(-/)" cd bindkey "\e[7~" beginning-of-line bindkey "\e[8~" end-of-line bindkey "\e[3~" delete-char bindkey "\e[5~" history-search-backward bindkey "\e[6~" history-search-forward # bindkey "^m" self-insert setopt autopushd pushdminus pushdsilent pushdtohome setopt autocd setopt cdablevars # cf. http://zsh.sunsite.dk/Intro/intro_2.html setopt extendedglob setopt globdots setopt ignoreeof setopt interactivecomments setopt noclobber setopt HIST_REDUCE_BLANKS setopt HIST_IGNORE_SPACE # Decent completion, for make etc. autoload -U compinit compinit -u fi # Set the title if [ $TERM = 'xterm' ]; then if [ $SHELLNAME = "zsh" ] then function precmd() { print -Pn "\e]0;%n@%m: %~\a"; } elif [ $SHELLNAME = "bash" ] then PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD}\007"' fi fi # Messages # @@ these should probably be in .zlogin echo -en "Using $SHELLNAME ${ZSH_VERSION:-$BASH_VERSION}; $TERM; " date +"%Y-%m-%d %H:%M:%S" echo "(And .shellrc $VERSION)" # Public Aliases alias ls='ls -aF' # @@ AF? alias ..='cd ..' alias uhm='fc -l -7' alias wget='wget -c' alias decr='dos2unix' alias recr='unix2dos' alias dh='dirs -v' if [[ ("$TERM" = 'screen') || (-n "$STY") ]] then alias exit='echo BAD. YOU ARE IN SCREEN' fi if [[ -f /usr/local/bin/svn ]] then alias svnt=/usr/local/bin/svn fi # Private Aliases # if [ -f $MISC/info/privalias ]; then # source $MISC/info/privalias if [ -f ~/.privalias ] then source ~/.privalias fi # Functions # @@ Search for wget, curl, lynx, perl GET if ! which GET &> /dev/null; then function GET() { curl -A 'Mozilla/5.0 (GET)' $1 2> /dev/null; } fi # @@ Use rsync for cpdir? cp -r? function cpdir() { (cd $1 && tar cf - . ) | (cd $2 && tar xvfpk -); } function mkd() { mkdir $1 && cd $1; } # if [ -f $(which aptitude) ]; then # function aptget() { su -c "aptitude install $1"; } # elif [ -f $(which apt-get) ]; then # function aptget() { su -c "apt-get install $1"; } # fi # Some magic from deltab: http://swhack.com/logs/2004-08-13#T00-22-44-1 function withcd() { (cd "$1" && shift && "$@"); } # @@ The ZSH documentation's version of this doesn't work # http://zsh.sunsite.dk/Intro/intro_5.html if [ $SHELLNAME = zsh ]; then function namedir() { eval "$1=$PWD" && : ~$1 echo Named $PWD '~'$1 } fi # [EOF]