From 7e8f3c51d4078c926ad9ae7724cb617e42fde2a1 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Fri, 8 May 2009 20:12:32 +0000 Subject: Reorder stuff, move stuff into functions, and start with vcs_info git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@395 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- zshrc | 324 ++++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 177 insertions(+), 147 deletions(-) (limited to 'zshrc') diff --git a/zshrc b/zshrc index 42d880c..bc9767c 100644 --- a/zshrc +++ b/zshrc @@ -54,10 +54,12 @@ case "$TERM" in ;; esac +####################################################################### +####################################################################### +# SETUP ENVIRONMENT AND OPTIONS +####################################################################### +####################################################################### - - -## Set options setopt \ extendedglob \ list_types \ @@ -77,136 +79,32 @@ setopt \ HIST_FIND_NO_DUPS \ HIST_IGNORE_SPACE \ -HISTFILE=~/.zsh_history -HISTSIZE=50000 -SAVEHIST=50000 - - -case $TERM in - xterm*) - precmd() { - title=$TITLE - #print -Pn "\e]2;$title\a\e]1;\a" - print -Pn "\033]0;$title\007" - }; - preexec() { - title="$1 [$TITLE]" - title=`echo $title | tr '\n' ' '` - #print -Pn "\e]2;$title\a\e]1;\a" - print -Pn "\033]0;$title\007" - }; - ;; - screen*) - if [ -x /usr/bin/screen ] || [ -x /usr/local/bin/screen ]; then - if grep -i -q screen <<< $TERMCAP ; then - precmd () {p=`print -Pn "%~"`; screen -X title "<$p>";} - preexec () {p=`print -Pn "%~:$1"`; screen -X title "<$p>";} - fi - fi; - ;; -esac - - -## Export environment -if [ -x /usr/bin/lesspipe ] ; then - eval `lesspipe` -fi - -export DEBEMAIL="weasel@debian.org" - - # in 'foo bar | baz' make a second ^W not eat 'bar |', but only '|' # this has the disadvantage that in 'bar|baz' it eats all of it. typeset WORDCHARS='|'$WORDCHARS -# malsync -if [ "$SYSTEM" = "Linux" ] ; then - eval `dircolors` - LS_COLORS="$LS_COLORS""*.divx=01;35:" - - alias ls='ls --color=auto -F' - alias grep='grep --color' -fi -alias cp='cp -i' -alias mv='mv -i' - -alias mmv='noglob mmv' - -alias zinterdiff='interdiff -z' - -alias defaultfixed='echo -n -e "\033]50;fixed\007"' -alias default='echo -n -e "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-15\007"' -alias hide='echo -n -e "\033]50;nil2\007"' -alias tiny='echo -n -e "\033]50;-misc-fixed-medium-r-normal--7-70-75-75-c-50-iso8859-15\007"' -alias small='echo -n -e "\033]50;-misc-fixed-medium-r-normal--10-100-75-75-c-60-iso8859-15\007"' -alias medium='echo -n -e "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-15\007"' -alias large='echo -n -e "\033]50;-misc-fixed-medium-r-normal--15-140-75-75-c-90-iso8859-15\007"' -alias huge='echo -n -e "\033]50;-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso8859-15\007"' - -[[ -x /usr/sbin/traceroute ]] && alias traceroute=/usr/sbin/traceroute -[[ -x /sbin/ifconfig ]] && alias ifconfig=/sbin/ifconfig -[[ -x /sbin/route ]] && alias route=/sbin/route - -if [ -x /usr/bin/recode ]; then - alias unix2dos='recode lat1..ibmpc' - alias dos2unix='recode ibmpc..lat1' -fi -[[ -x /usr/sbin/samhain ]] && alias samhain-check='sudo /usr/sbin/samhain -t check -i -p err -s none -l none -m none' - -alias 221='pstops "2:0L@.7(21cm,0)+1L@.7(21cm,14.85cm)"' -alias rot13='tr a-zA-Z n-za-mN-ZA-M' -alias 64216='perl -MMIME::Base64 -e "print unpack(\"H*\", decode_base64(<>)),\"\n\""' -alias 16264='perl -MMIME::Base64 -e "\$l=<>; chomp \$l; print encode_base64(pack(\"H*\", \$l)),\"\n\""' - -if [ -x /usr/bin/base64 ]; then - alias base64-encode=base64 - alias base64-decode='base64 -d' -else - alias base64-encode='perl -MMIME::Base64 -e "print encode_base64(<>)"' - alias base64-decode='perl -MMIME::Base64 -e "print decode_base64(<>)"' -fi - -alias vnc='xtightvncviewer -encodings "tight copyrect" -compresslevel 9 -quality 4' -alias rdesktop-w='rdesktop -x l -g 1280x1024 -a 16 172.22.118.112' - - -if [ -f ~/.ssh/alias ] ; then - . ~/.ssh/alias -else - if [ -f ~/.ssh/config ] ; then - for i in `grep "^Host " ~/.ssh/config | awk ' !/\*/ {print $2}'`; do alias $i="ssh $i"; done - fi -fi +HISTFILE=~/.zsh_history +HISTSIZE=50000 +SAVEHIST=50000 -if [ "$HOSTNAME" = 'thetis' ] ; then - alias ldapvi='ldapvi --encoding=ASCII -h localhost -D cn=admin,o=ab.office.dibral.at -w `grep bindpw $HOME/.noreply.ldap | cut -d" " -f 2`' -fi -if [ "$HOSTNAME" = 'anguilla' ] && [ -r "$HOME/.oftc-hosts" ] ; then - cat "$HOME/.oftc-hosts" | while read name ip; do - alias -g $name-ip="$ip" - alias irssi-$name="irssi --home=$HOME/.irssi-MASTER --connect=OFTC-$name" +#watch=( $(<~/.friends) ) # watch for people in .friends file +watch=(notme) # watch for everybody but me +LOGCHECK=300 # check every 5 min for login/logout activity +WATCHFMT='%n %a %l from %m at %t.' - alias -g $name-testnet-ip="$ip" - alias irssi-testnet-$name="irssi --home=$HOME/.irssi-MASTER --connect=TESTNET-$name" - done -fi +[ -x /usr/bin/lesspipe ] && eval `lesspipe` -if [ -e /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) -fi +unset LANG +export DEBEMAIL="weasel@debian.org" -if [ "`id -u`" = "0" -o ! -x /usr/bin/id ] ; then - export PROMPT="${debian_chroot:+[$debian_chroot] }%n@%m:%~# " - export TITLE="%n@%m: %~" -else - export PROMPT="${debian_chroot:+[$debian_chroot] }%n@%m:%~$ " - export TITLE="%n@%m: %~" -fi +####################################################################### +####################################################################### +# SETUP PATHS +####################################################################### +####################################################################### -# SETUP PATH -############ fpath=( "$HOME/.zshfunc" "$fpath[@]" ) export FPATH # Only unique entries please. @@ -264,6 +162,7 @@ unset paths # we want colorful listings zmodload -i zsh/complist zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} + hosts="" if [ -e $HOME/.ssh/known_hosts ]; then hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*}) @@ -273,43 +172,174 @@ fi autoload -U compinit compinit +####################################################################### +####################################################################### +# SETUP ALIASES +####################################################################### +####################################################################### +if [ "$SYSTEM" = "Linux" ] ; then + eval `dircolors` + LS_COLORS="$LS_COLORS""*.divx=01;35:" -if [ -x /usr/bin/ddate ] ; then - /usr/bin/ddate - echo + alias ls='ls --color=auto -F' + alias grep='grep --color' fi +alias cp='cp -i' +alias mv='mv -i' -if [ -x /usr/games/fortune ]; then - FORTUNE_PATH="" - [ -d /usr/share/games/fortunes ] && FORTUNE_PATH="$FORTUNE_PATH /usr/share/games/fortunes" - [ -d /usr/share/games/fortunes/off ] && FORTUNE_PATH="$FORTUNE_PATH /usr/share/games/fortunes/off" - [ -d $HOME/.fortunes/ ] && FORTUNE_PATH="$FORTUNE_PATH $HOME/.fortunes/" - fortune `echo $FORTUNE_PATH` - echo +alias mmv='noglob mmv' + +alias zinterdiff='interdiff -z' + +alias 221='pstops "2:0L@.7(21cm,0)+1L@.7(21cm,14.85cm)"' +alias rot13='tr a-zA-Z n-za-mN-ZA-M' +alias 64216='perl -MMIME::Base64 -e "print unpack(\"H*\", decode_base64(<>)),\"\n\""' +alias 16264='perl -MMIME::Base64 -e "\$l=<>; chomp \$l; print encode_base64(pack(\"H*\", \$l)),\"\n\""' + +alias vnc='xtightvncviewer -encodings "tight copyrect" -compresslevel 9 -quality 4' +alias hs-mplayer='mplayer -ao alsa:device=hw=1' + +alias defaultfixed='echo -n -e "\033]50;fixed\007"' +alias default='echo -n -e "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-15\007"' +alias hide='echo -n -e "\033]50;nil2\007"' +alias tiny='echo -n -e "\033]50;-misc-fixed-medium-r-normal--7-70-75-75-c-50-iso8859-15\007"' +alias small='echo -n -e "\033]50;-misc-fixed-medium-r-normal--10-100-75-75-c-60-iso8859-15\007"' +alias medium='echo -n -e "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-15\007"' +alias large='echo -n -e "\033]50;-misc-fixed-medium-r-normal--15-140-75-75-c-90-iso8859-15\007"' +alias huge='echo -n -e "\033]50;-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso8859-15\007"' + +[[ -x /usr/sbin/traceroute ]] && alias traceroute=/usr/sbin/traceroute +[[ -x /sbin/ifconfig ]] && alias ifconfig=/sbin/ifconfig +[[ -x /sbin/route ]] && alias route=/sbin/route +[[ -x /usr/sbin/samhain ]] && alias samhain-check='sudo /usr/sbin/samhain -t check -i -p err -s none -l none -m none' + +[ "$HOSTNAME" = 'anguilla' ] && [ -r "$HOME/.oftc-hosts" ] && setup-oftc-aliases +[ "$HOSTNAME" = 'thetis' ] && alias ldapvi='ldapvi --encoding=ASCII -h localhost -D cn=admin,o=ab.office.dibral.at -w `grep bindpw $HOME/.noreply.ldap | cut -d" " -f 2`' + +if [ -x /usr/bin/recode ]; then + alias unix2dos='recode lat1..ibmpc' + alias dos2unix='recode ibmpc..lat1' fi +if [ -x /usr/bin/base64 ]; then + alias base64-encode=base64 + alias base64-decode='base64 -d' +else + alias base64-encode='perl -MMIME::Base64 -e "print encode_base64(<>)"' + alias base64-decode='perl -MMIME::Base64 -e "print decode_base64(<>)"' +fi -#watch=( $(<~/.friends) ) # watch for people in .friends file -watch=(notme) # watch for everybody but me -LOGCHECK=300 # check every 5 min for login/logout activity -WATCHFMT='%n %a %l from %m at %t.' -[ -f COMMANDMENTS ] && cat COMMANDMENTS -if [ "$SSH_AUTH_SOCK" != "" ] && [ "$SSH_AUTH_SOCK" != "$HOME/.ssh-auth-sock" ] ; then - if ! [ -e "$HOME/.ssh-auth-sock" ] || [ "`readlink $HOME/.ssh-auth-sock`" != "$SSH_AUTH_SOCK" ]; then - echo "Setting ~/.ssh-auth-sock." - rm -f "$HOME/.ssh-auth-sock" - ln -s "$SSH_AUTH_SOCK" "$HOME/.ssh-auth-sock" + +case $TERM in + xterm*) + function update-title() { + print -Pn "\033]0;$1\007" + } + function build-and-update-title() { + local location cmd title + location="$1" + cmd="$2" + if [ "$cmd" = "" ]; then + title="$location" + else + title="$cmd [$location]" + title=`echo $title | tr '\n' ' '` + fi + update-title "$title" + } + ;; + + screen*) + if [ -x /usr/bin/screen ] || [ -x /usr/local/bin/screen ]; then + function update-title() { + screen -X title "<$1>" + } + function build-and-update-title() { + local location cmd title + location="$1" + cmd="$2" + if [ "$cmd" = "" ]; then + title=`print -Pn "%~"` + else + title=`print -Pn "%~:$cmd"` + fi + update-title "$title" + } + else + function build-and-update-title() { } + fi + ;; +esac + +function precmd() { + vcs_info + build-and-update-title "$TITLE" +}; +function preexec() { + build-and-update-title "$TITLE" "$1" +}; + +# gather version control information for inclusion in a prompt +# we will only be using one variable, so let the code know now. +autoload -Uz vcs_info && vcs_info +zstyle ':vcs_info:*' max-exports 1 +zstyle ':vcs_info:*' disable cdv darcs mtn tla hg +zstyle ':vcs_info:*' use-prompt-escapes +zstyle ':vcs_info:*' use_simple + + +function init-prompt() { + # init colors: + autoload colors zsh/terminfo + if [[ "$terminfo[colors]" -ge 8 ]]; then + colors fi -elif [ "$SSH_AUTH_SOCK" = "" ] && [ -e "$HOME/.ssh-auth-sock" ]; then - SSH_AUTH_SOCK="$HOME/.ssh-auth-sock"; export SSH_AUTH_SOCK -fi + for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do + eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}' + eval PR_LIGHT_$color='%{$fg[${(L)color}]%}' + (( count = $count + 1 )) + done + if [ -e /etc/debian_chroot ]; then + debian_chroot=$(cat /etc/debian_chroot) + fi -alias hs-mplayer='mplayer -ao alsa:device=hw=1' + PR_NO_COLOUR="%{$terminfo[sgr0]%}" + # change vcs_info formats for the prompt + if [[ "$TERM" == dumb ]] ; then + zstyle ':vcs_info:*' actionformats "(%s%)-[%b|%a] " + zstyle ':vcs_info:*' formats "(%s%)-[%b] " + else +# these are the same, just with a lot of colours: + zstyle ':vcs_info:*' actionformats "${PR_YELLOW}(${PR_NO_COLOUR}%s${PR_YELLOW})${PR_CYAN}-${PR_YELLOW}[${PR_GREEN}%b${PR_YELLOW}|${PR_RED}%a${PR_YELLOW}]${PR_NO_COLOUR}" + zstyle ':vcs_info:*' formats "${PR_YELLOW}(${PR_NO_COLOUR}%s${PR_YELLOW})${PR_CYAN}-${PR_YELLOW}[${PR_GREEN}%b${PR_YELLOW}]${PR_NO_COLOUR}" + zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b${PR_RED}:${YELLOW}%r" + fi + + if [ "`id -u`" = "0" -o ! -x /usr/bin/id ] ; then + export PROMPT="${debian_chroot:+[$debian_chroot] }%n@%m${vcs_info_msg_0_}:%~# " + export TITLE="%n@%m: %~" + else + export PROMPT="${debian_chroot:+[$debian_chroot] }%n@%m${vcs_info_msg_0_}:%~$ " + export TITLE="%n@%m: %~" + fi +} +safe-restore-ssh-agent-socket +init-prompt + +[ -x /usr/bin/ddate ] && /usr/bin/ddate && echo +if [ -x /usr/games/fortune ]; then + FORTUNE_PATH="" + [ -d /usr/share/games/fortunes ] && FORTUNE_PATH="$FORTUNE_PATH /usr/share/games/fortunes" + [ -d /usr/share/games/fortunes/off ] && FORTUNE_PATH="$FORTUNE_PATH /usr/share/games/fortunes/off" + [ -d $HOME/.fortunes/ ] && FORTUNE_PATH="$FORTUNE_PATH $HOME/.fortunes/" + fortune `echo $FORTUNE_PATH` + echo +fi +[ -f COMMANDMENTS ] && cat COMMANDMENTS [ -e $HOME/.zshrc-local ] && . $HOME/.zshrc-local [ -e $HOME/.pal ] && [ -e /usr/bin/pal ] && pal -r 5-10 -unset LANG -- cgit v1.2.3