ZSHRC_VERSION='$Id: zshrc 62 2006-05-09 11:55:55Z richih $'
READNULLCMD=${PAGER:-/usr/bin/pager}
if [[ "$TERM" != emacs ]]; then
[[ -z "$terminfo[kdch1]" ]] || bindkey -M emacs "$terminfo[kdch1]" delete-char
[[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
[[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line
[[ -z "$terminfo[kich1]" ]] || bindkey -M emacs "$terminfo[kich1]" overwrite-mode
[[ -z "$terminfo[kdch1]" ]] || bindkey -M vicmd "$terminfo[kdch1]" vi-delete-char
[[ -z "$terminfo[khome]" ]] || bindkey -M vicmd "$terminfo[khome]" vi-beginning-of-line
[[ -z "$terminfo[kend]" ]] || bindkey -M vicmd "$terminfo[kend]" vi-end-of-line
[[ -z "$terminfo[kich1]" ]] || bindkey -M vicmd "$terminfo[kich1]" overwrite-mode
[[ -z "$terminfo[cuu1]" ]] || bindkey -M viins "$terminfo[cuu1]" vi-up-line-or-history
[[ -z "$terminfo[cuf1]" ]] || bindkey -M viins "$terminfo[cuf1]" vi-forward-char
[[ -z "$terminfo[kcuu1]" ]] || bindkey -M viins "$terminfo[kcuu1]" vi-up-line-or-history
[[ -z "$terminfo[kcud1]" ]] || bindkey -M viins "$terminfo[kcud1]" vi-down-line-or-history
[[ -z "$terminfo[kcuf1]" ]] || bindkey -M viins "$terminfo[kcuf1]" vi-forward-char
[[ -z "$terminfo[kcub1]" ]] || bindkey -M viins "$terminfo[kcub1]" vi-backward-char
# ncurses fogyatekos
[[ "$terminfo[kcuu1]" == "O"* ]] && bindkey -M viins "${terminfo[kcuu1]/O/[}" up-line-or-history
[[ "$terminfo[kcud1]" == "O"* ]] && bindkey -M viins "${terminfo[kcud1]/O/[}" down-line-or-history
[[ "$terminfo[kcuf1]" == "O"* ]] && bindkey -M viins "${terminfo[kcuf1]/O/[}" vi-forward-char
[[ "$terminfo[kcub1]" == "O"* ]] && bindkey -M viins "${terminfo[kcub1]/O/[}" vi-backward-char
[[ "$terminfo[khome]" == "O"* ]] && bindkey -M viins "${terminfo[khome]/O/[}" beginning-of-line
[[ "$terminfo[kend]" == "O"* ]] && bindkey -M viins "${terminfo[kend]/O/[}" end-of-line
[[ "$terminfo[khome]" == "O"* ]] && bindkey -M emacs "${terminfo[khome]/O/[}" beginning-of-line
[[ "$terminfo[kend]" == "O"* ]] && bindkey -M emacs "${terminfo[kend]/O/[}" end-of-line
fi
## RichiH
zstyle ':completion:*:sudo:*' command-path /usr/local/sbin /usr/local/bin \
/usr/sbin /usr/bin /sbin /bin /usr/X11R6/bin
# this will include newly installed programs into tab completion
_force_rehash() { (( CURRENT == 1 )) && rehash return 1 }
zstyle ':completion:*' completers _force_rehash
LISTMAX=0 # only ask if completion should be shown if it is larger than our screen
# this will not complete dotfiles in ~, unless you provide at least .<tab>
zstyle -e ':completion:*' ignored-patterns 'if [[ $PWD = ~ ]] && [[ ! $words[-1] == .* ]]; then reply=(.*); fi'
# Don't complete backup files (e.g. 'bin/foo~') as executables
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'
# color completion
zstyle ':completion:*' list-colors ''
# http://zshwiki.org/ZshConfigurationFiles
#
bindkey '^R' history-incremental-search-backward
bindkey '^[[3~' delete-char
PATH+=':/usr/bin'
PATH="/usr/local/bin:"$PATH
fg_green=$'%{\e[0;32m%}'
fg_blue=$'%{\e[0;34m%}'
fg_cyan=$'%{\e[0;36m%}'
fg_red=$'%{\e[0;31m%}'
fg_brown=$'%{\e[0;33m%}'
fg_purple=$'%{\e[0;35m%}'
fg_light_gray=$'%{\e[0;37m%}'
fg_dark_gray=$'%{\e[1;30m%}'
fg_light_blue=$'%{\e[1;34m%}'
fg_light_green=$'%{\e[1;32m%}'
fg_light_cyan=$'%{\e[1;36m%}'
fg_light_red=$'%{\e[1;31m%}'
fg_light_purple=$'%{\e[1;35m%}'
fg_no_colour=$'%{\e[0m%}'
fg_white=$'%{\e[1;37m%}'
fg_black=$'%{\e[0;30m%}'
#other color codes
#NORMAL "\033[0m"
#BOLD "\033[1m"
#UNDERLINED "\033[4m"
#BLINK "\033[5m"
#INVERTED "\033[7m"
#INVISIBLE "\033[8m"
#RED "\033[31m"
#GREEN "\033[32m"
#YELLOW "\033[33m"
#BLUE "\033[34m"
#PURPLE "\033[35m"
#AQUA "\033[36m"
#GREY "\033[90m"
#REDBACK "\033[41m"
#GREENBACK "\033[42m"
#YELLOWBACK "\033[43m"
#BLUEBACK "\033[44m"
#PURPLEBACK "\033[45m"
#AQUABACK "\033[46m"
#WHITEBACK "\033[47m"
# get all pids and names of parents in order to decide coloring fo the prompt
if [[ -x `which awk` ]]
then
PPNAME=` ps -Al | awk -v ppid=$PPID '{ if ( $4 == ppid ) print $14 }'`
PPPID=` ps -Al | awk -v ppid=$PPID '{ if ( $4 == ppid ) print $5 }'`
PPPNAME=` ps -Al | awk -v pppid=$PPPID '{ if ( $4 == pppid ) print $14 }'`
PPPPID=` ps -Al | awk -v pppid=$PPPID '{ if ( $4 == pppid ) print $5 }'`
PPPPNAME=` ps -Al | awk -v ppppid=$PPPPID '{ if ( $4 == ppppid ) print $14 }'`
else
echo "awk is not installed, this means i will not be able to show if our parent is a sshd"
fi
if [[ $PPNAME = sshd || $PPPNAME = sshd || $PPPPNAME = sshd ]]
then
ZSHRC_PARENT_SSHD=1
fi
if [[ -n $SSH_TTY ]]
then
ZSHRC_PARENT_SCREEN=1
fi
PROMPT="%(!.$fg_red%m$fg_no_colour $fg_light_blue%~ %# $fg_no_colour.$fg_light_green%n@%m$fg_no_colour $fg_light_blue%~ %# $fg_no_colour)" # %([is_superuser].true.false)
RPROMPT="%(?..${fg_light_gray}[$fg_red%U%?%u${fg_light_gray}]$fg_no_colour) %h %D{%T %a %e.%m.%Y}"
PS2='%_ > ' # show for i in 1 2 3 \r foo >
SPROMPT="zsh: correct '%R' to '%r'? [N/y/a/e] " # the prompt we see when being asked for substitutions
## TODO use 'good' color codes with array
## TODO host-based todo list
## TODO color completion
## TODO ssh completion
## TODO fat completion?
## TODO check if root has .Xauthotiry per ln -s, else warn
## TODO list of hostnames where the PROMPT color should change, implement color scheme from .zshrc_local?
## \-> use $SSH_CLIENT?
## TODO:
# richih@cheetah ~/.ssh % screen -ls
# There is a screen on:
# 8800.pts-0.cheetah (Dead ???)
# Remove dead screens with 'screen -wipe'.
# 1 Socket in /var/run/screen/S-richih.
#
zshrc_show_chars() {
for i in 3 4 5 6 7 8 9 a b c d e; do; for j in 0 1 2 3 4 5 6 7 8 9 a b c d e; do; print "$i$j \x$i$j "; done; done;
}
zshrc_show_colors() {
# see all colors
PROMPT="$fg_green gr $fg_blue bl $fg_cyan cy $fg_red re $fg_brown br $fg_purple pu $fg_light_gray lg $fg_dark_gray dg $fg_light_blue lb $fg_light_green lg $fg_light_cyan lc $fg_light_purple lp $fg_no_colour nc $fg_white wh $fg_black bl $fg_no_colour -"
}
export EDITOR="vim" # if there is no vim, the computer we are running on is not worth working on
#if [[ -x =most ]] # most is way better than less
if [[ -x `which most` ]] # most is way better than less
then
export PAGER="most"
else
# if [[ -x =less ]]
if [[ -x ` which less` ]]
then
export PAGER="less"
else
export PAGER="more"
fi
fi
if [[ -x `which links2` ]]
then
export BROWSER="links2"
else
if [[ -x `which elinks` ]]
then
export BROWSER="elinks"
else
if [[ -x `which lynx` ]]
then
export BROWSER="lynx"
else
export BROWSER="links"
fi
fi
fi
#if [[ -x =vimdiff ]]
if [[ -x `which vimdiff` ]]
then
DIFFER="vimdiff"
else
DIFFER="diff"
fi
#if [[ -x =devtodo ]]
if [[ -x `which devtodo` ]]
then
else
echo "devtodo not installed"
fi
HISTFILE=~/.zsh_history
SAVEHIST=50000
HISTSIZE=50000
setopt histignoredups # this will ignore _consecutive_ duplicates
setopt histignorespace # if any command starts with a whitespace, it will not be saved. it will stil be displayed in the current session, though
setopt appendhistory # don't overwrite history
# perhaps we want to change HISTCONTROL=ignoredups ?
setopt autocd # /base/media is an actuall 'command', now
setopt correctall ## can we set the default to e? caphuso says no
#setopt globdots # with this, we could treat dotfiles the same as normal ones
setopt interactivecomments # with this, we can do `some_evil_stuff # which we explain` and just execute some_evil_stuff
setopt noclobber # this will probihbit `cat foo > bar` if bar exists. use >! instead
setopt extendedglob # enables various things, most notably ^negation. see cheatsheet & http://zsh.dotsrc.org/Intro/intro_2.html#SEC2
setopt notify # enabled by default; this will put info from finished background processes over the current line
setopt functionargzero # enabled by default; this will fill $0 with the function name, not 'zsh'
# POSIX_BUILTINS # find out about this one
setopt completeinword # tab completion witin words
setopt multios # this enables various goodness
# ls > foo > bar
# cmd > >(cmd1) > >(cmd2) # would redirect stdout from cmd to stdin of cmd1,2
# make install > /tmp/logfile | grep -i error
setopt braceccl # {a-z} {0-2} etc expansion
#setopt transientrprompt # this will only show RPROMPT in the current line
autoload compinit;compinit # this enables autocompletion for pretty much everything
# shortcuts
alias a=alias
alias ua=unalias
alias ls='ls --color=auto'
alias la='ls -a'
alias ll='ls -l'
alias lh='ls -lh'
alias ld='ls -ld'
alias l='ll'
alias v='vim'
alias sr='screen -r'
alias sdr='screen -D -r'
alias du='du -hx --max-depth=1'
#alias up='updatedb'
alias svim='vim -n -i NONE --cmd "setlocal noswapfile" --cmd "set nocompatible" --cmd "set tabstop=4" -u NONE' # for editing without a trace
alias scls='screen -ls'
alias scdr='screen -dr'
alias dd_status='kill -SIGUSR1 $(pidof dd)'
alias no=ls # for Dvorak
# various stuff to make the commands more sane
alias mv='nocorrect mv -i' # prompt before overwriting files
alias mkdir='nocorrect mkdir' # don't correct mkdir
alias man='nocorrect man'
alias wget='wget -nc' # else, i will have my home dir cluttered with dozens of foo.n
alias whois='whois -H'
alias gpg='gpg --no-use-agent' # shitty SuSE presets make that necessary
alias ifconfig='ifconfig -a'
alias on='w | grep -v `whoami`'
alias grep='grep --color=auto'
### alias md='mkdir -p' # make parent, no errors ### remove the 'no error' bit and use it
# useful to see what hogs your disk
alias sz='l | sort -nr +4 | tail -10'
# various stuff from thailand
alias s='sync'
alias dt='dmesg | tail'
alias dfh='df -h'
alias du='du -chx --max-depth=1'
# use different programs
#if [[ -x =htop ]]
if [[ -x `which htop` ]]
then
alias top='htop'
fi
# global aliases. use with care!
alias -g L='| $PAGER'
alias -g E='| egrep'
alias -g G='| grep -i'
alias -g ...=../..
alias -g ....=../../..
alias -g .....=../../../..
alias -g ......=../../../../..
############## test and use this
#alias -g L='| less'
alias -g LS='| less -S'
alias -g EL='|& less'
alias -g ELS='|& less -S'
alias -g TRIM='| cut -c 1-$COLUMNS'
alias -g H='| head'
alias -g HL='| head -n $(( +LINES ? LINES - 4 : 20 ))'
alias -g EH='|& head'
alias -g EHL='|& head -n $(( +LINES ? LINES - 4 : 20 ))'
alias -g T='| tail'
alias -g TL='| tail -n $(( +LINES ? LINES - 4 : 20 ))'
alias -g ET='|& tail'
alias -g ETL='|& tail -n $(( +LINES ? LINES - 4 : 20 ))'
alias -g C='| wc -l'
alias -g S='| sort'
alias -g Su='| sort -u'
alias -g Sn='| sort -n'
alias -g Snr='| sort -nr'
alias -g DN=/dev/null
alias -g VL=/var/log/
alias -g V='| vim -'
alias -g G='| egrep'
alias -g Gv='| egrep -v'
alias -g EG='|& egrep'
alias -g EGv='|& egrep -v'
alias -g X='| xargs'
alias -g X0='| xargs -0'
alias -g XG='| xargs egrep'
alias -g XGv='| xargs egrep -v'
alias -g X0G='| xargs -0 egrep'
alias -g X0Gv='| xargs -0 egrep -v'
alias -g A='| awk '
alias -g A1="| awk '{print \$1}'"
alias -g A2="| awk '{print \$2}'"
alias -g A3="| awk '{print \$3}'"
alias -g A4="| awk '{print \$4}'"
alias -g A5="| awk '{print \$5}'"
alias -g EA='|& awk '
alias -g EA1="|& awk '{print \$1}'"
alias -g EA2="|& awk '{print \$2}'"
alias -g EA3="|& awk '{print \$3}'"
alias -g EA4="|& awk '{print \$4}'"
alias -g EA5="|& awk '{print \$5}'"
#############
on () {who | awk {'print $1;'} | perl -pe 's/\n/ /' && echo ""}
up() {
if [[ $HOME = $PWD ]]
then
svn update config
if [[ -d .zsnes ]]
then
svn update .zsnes
fi
else
svn update .
fi
}
preexec () {ZSHRC_LAST_TIME=$SECONDS;ZSHRC_LAST_EXECUTE="1";}
NEW_TIME='0'
rebuildrprompt() {
#
##
### TODO setopt promptsubst - this way, we can put variables into prompt and they get substituted
##
#
# we are using this style to create a more readable version
RPROMPT="%(?..${fg_light_gray}[$fg_red%U%?%u${fg_light_gray}]$fg_no_colour) " # colored [$returncode]
if [[ $ZSHRC_LAST_EXECUTE -eq 1 ]]; then;
ZSHRC_NEW_TIME=$((SECONDS - ZSHRC_LAST_TIME));
ZSHRC_LAST_EXECUTE="0";
RPROMPT+="$ZSHRC_NEW_TIME " # print return code & execution time of last command
## TODO use hours, minutes, seconds
fi;
if [[ $ZSHRC_ACPITOOL -eq 1 ]]
then
ZSHRC_ACPITOOL_ARRAY=(${(z)$(acpitool | perl -e 'while (<>) { if (/.*Battery.* (.*), (.*)%$/) { print "$1 $2 "} elsif (/AC adapter.*: (.*)-line$/) {print $1}}')})
# this is to de-bork vim highlighting: '
if [[ $ZSHRC_ACPITOOL_ARRAY[1] = "charged" ]]
then
RPROMPT+="$fg_green"
elif [[ $ZSHRC_ACPITOOL_ARRAY[1] = "charging" ]]
then
RPROMPT+="$fg_light_green"
elif [[ $ZSHRC_ACPITOOL_ARRAY[1] = "discharging" ]]
then
if [[ $ZSHRC_ACPITOOL_ARRAY[2] -lt "30.0" ]]
then
RPROMPT+="$fg_red"
else
RPROMPT+="$fg_purple"
fi
fi
RPROMPT+="$ZSHRC_ACPITOOL_ARRAY[2] $fg_no_colour"
fi
RPROMPT+="%h %D{%T %a %e.%m.%Y}"
}
precmd() {
rebuildrprompt
# RPROMPT="%(?..${fg_light_gray}[$fg_red%U%?%u${fg_light_gray}]$fg_no_colour) $NEW_TIME %h %D{%T %a %e.%m.%Y}";
}
changetermtitle () {
[[ -t 1 ]] || return
case $TERM in
sun-cmd) print -Pn "\e]l%n@%m:%~\e\\"
;;
*xterm*|rxvt|(dt|k|E)term) print -Pn "\e]2;%n@%m:%~\a"
;;
esac
}
version() {
echo $ZSHRC_VERSION
}
startup () {
version
# info on any running screens
if [[ -x =screen ]]
then
ZSHRC_SCREENLIST=(${${(M)${(f)"$(screen -ls)"}:#(#s)[[:space:]]##([0-9]##).*}/(#b)[[:space:]]#([0-9]##).*/$match[1]})
if [[ $#ZSHRC_SCREENLIST -ge 1 ]]
then
echo "There are $#ZSHRC_SCREENLIST screens running. $ZSHRC_SCREENLIST"
fi
# ZSHRC_SCREENLIST=`screen -ls | perl -e 'while (<>) {if (s/^\s+(\d*).*$/$1 /) {chomp; print}}'`
# ZSHRC_SCREENCOUNT=`echo $ZSHRC_SCREENLIST | wc -w`
# echo "There are $ZSHRC_SCREENCOUNT screens running. $ZSHRC_SCREENLIST"
fi
# .todo_zshrc parsing
if [[ -e ~/.todo_zshrc ]]
then
echo "There are `wc -l ~/.todo_zshrc | awk '{print $1}'` items on your todo list."
fi
# check if acpitool is installed. if yes, tell rebuildrprompt to use it
# if [[ -x =acpitool ]]
if [[ -x `which acpitool` ]]
then
ZSHRC_ACPITOOL='1'
fi
# change the terminals title if it's a xterm, konsole or the like
changetermtitle
}
chpwd () {
# this function gets executed every time zsh changes pwd
changetermtitle
}
todo () {
grep TODO *
}
show () {
[[ -e ~/.todo_zshrc ]] || return
echo "todo:"
cat ~/.todozshrc
}
trans () {
[[ -o transientrprompt ]] && unsetopt transientrprompt || setopt transientrprompt
}
toggleopt () {
[[ -o $1 ]] && unsetopt $1 || setopt $1
}
issetopt () {
[[ -o $1 ]] && exit 0 || exit 1
}
rehash () {
source ~/.zshrc
}
help_modifiers () {
echo \
'Modifiers:
(:h) head; (:t) tail; (:e) extension; (:u) upercase; (:l) lowercase
Editing:
print -z foo
'
}
termwidth () {
#steal from http://aperiodic.net/phil/prompt/ to reduce PWD length
echo $((${COLUMNS} - 1));
}
## TODO see below
#todo_add
#todo_del
update() {
## TODO check if we are on kiwi/in birdcage -> only svn
if [[ $HOST = "laptop" || $HOST = "kiwi" || $HOST = "box" ]]
then
echo "using svn"
svn update ~/config
#elif [[ -x =scp ]]
elif [[ -x `which scp` ]]
then
echo "using wget"
wget -nc http://www.net.informatik.tu-muenchen.de/~richih/zshrc -O ~/zshrc_new && cp ~/zshrc_new ~/.zshrc
# UPDATE_DOWNLOAD_COMMAND='`scp richih@kiwi.net.informtik.tu-muenchen.de:~/.zshrc ~/.zshrc_new`'
#
# # it's nicer to keep all commands in one place
# UPDATE_BACKUP_FILE="~/.zshrc_backup`date +%G-%m-%d-%H:%M:%S`"
## $UPDATE_DOWNLOAD_COMMAND
## scp richih@kiwi.net.informatik.tu-muenchen.de:~/.zshrc ~/.zshrc_new
# cp ~/.zshrc $ZSHRC_UPDATE_BACKUP_FILE
# $DIFFER $ZSHRC_UPDATE_BACKUP_FILE ~/.zshrc_new
# echo "Do you want to use the new file? [N/y]"
# perl -e 'if (<> =~ /y/i) {exit 0} else {exit 1}' || exit 1 ##TODO if we exit here as root, we become richih!!!
# cp ~/.zshrc_new ~/.zshrc
fi
echo "sourcing new .zshrc"
source ~/.zshrc
}
commit() {
if [[ $HOST = "laptop" || $HOST = "kiwi" || $HOST = "box" ]]
then
svn commit ~/config
fi
}
# Checks wheter a PCRE matches a value. Example:
# % regcheck '\^.{3} EUR' '500 EUR'
preg() {
zmodload -i zsh/pcre
pcre_compile $1 && \
pcre_match $2 && echo "regex matches" || echo "regex does not match"
}
# A quick globbing reference, stolen from GRML.
help_glob() {
echo -e "
/ directories
. plain files
@ symbolic links
= sockets
p named pipes (FIFOs)
* executable plain files (0100)
% device files (character or block special)
%b block special files
%c character special files
r owner-readable files (0400)
w owner-writable files (0200)
x owner-executable files (0100)
A group-readable files (0040)
I group-writable files (0020)
E group-executable files (0010)
R world-readable files (0004)
W world-writable files (0002)
X world-executable files (0001)
s setuid files (04000)
S setgid files (02000)
t files with the sticky bit (01000)
print *(m-1) # Dateien, die vor bis zu einem Tag modifiziert wurden.
print *(a1) # Dateien, auf die vor einem Tag zugegriffen wurde.
print *(@) # Nur Links
print *(Lk+50) # Dateien die ueber 50 Kilobytes grosz sind
print *(Lk-50) # Dateien die kleiner als 50 Kilobytes sind
print **/*.c # Alle *.c - Dateien unterhalb von \$PWD
print **/*.c~file.c # Alle *.c - Dateien, aber nicht 'file.c'
print (foo|bar).* # Alle Dateien mit 'foo' und / oder 'bar' am Anfang
print *~*.* # Nur Dateien ohne '.' in Namen
chmod 644 *(.^x) # make all non-executable files publically readable
print -l *(.c|.h) # Nur Dateien mit dem Suffix '.c' und / oder '.h'
print **/*(g:users:) # Alle Dateien/Verzeichnisse der Gruppe >users<
echo /proc/*/cwd(:h:t:s/self//) # Analog zu >ps ax | awk '{print $1}'<"
}
# Make ISO image. Query values interactively.
mkiso() {
echo " * Volume name "
read volume
echo " * ISO Name (ie. tmp.iso)"
read iso
echo " * Directory or File"
read files
mkisofs -o ~/$iso -A $volume -allow-multidot -J -R -iso-level 3 -V $volume -R $files
}
# Farbiges ls in less
cls() { ls --color=always $* | less -r }
# ls to pager
lsp() { ls --color=always -l $* | less -r }
# cd and list
cl() { cd $1 && ls --color=auto }
# "m"ake directory and "cd" to it
mcd() { mkdir -p "$@"; cd "$@" }
## This allows incremental completion of a word.
## After starting this command, a list of completion
## choices can be shown after every character you
## type, which you can delete with ^h or DEL.
## RET will accept the completion so far.
## You can hit TAB to do normal completion, ^g to
## abort back to the state when you started, and ^d to list the matches.
autoload -U incremental-complete-word
zle -N incremental-complete-word
bindkey "^Xi" incremental-complete-word ## C-x-i
## This function allows you type a file pattern,
## and see the results of the expansion at each step.
## When you hit return, they will be inserted into the command line.
autoload -U insert-files
zle -N insert-files
bindkey "^Xf" insert-files ## C-x-f
## This function allows you type a file pattern,
## and see the results of the expansion at each step.
## When you hit return, they will be inserted into the command line.
autoload -U insert-files
zle -N insert-files
bindkey "^Xf" insert-files ## C-x-f
## This is a multiple move based on zsh pattern matching. To get the full
## power of it, you need a postgraduate degree in zsh.
## Read /path_to_zsh_functions/zmv for some basic examples.
autoload -U zmv
## funstuff
#this will enable tetris upon ^x-t
autoload -U tetris
zle -N tetris
bindkey "^Xt" tetris ## C-x-t to play
#rm () { mv $* /tmp/wastebasket } # this will move everything to that directory, instead..
#### along with %c (Trailing component of $PWD. If you want n tailing componenets, put an interger 'n' after the %.)
#### this might be _very_ convenient..
#PR_FILLBAR=""
#PR_PWDLEN=""
#
#local promptsize=${#${(%):---(%n@%m:%l)---()--}}
#local pwdsize=${#${(%):-%~}}
#
#if [[ "$promptsize + $pwdsize" -gt $TERMWIDTH ]]; then
# ((PR_PWDLEN=$TERMWIDTH - $promptsize))
#else
# PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize)))..${PR_HBAR}.)}"
#fi
####
# cheatsheet:
#
# % xx=Test
# % echo $xx:u
# TEST
# % echo $xx:l
# test
#
# cat *<tab>
#
# esc-' will bring back the last string and fully quote it
#
# $RANDOM
#
# Also, the string **/ forces a recursive search of subdirectories:
#
# Note that *(x) and *(*) both match executables. *(X) matches files executable by others, as opposed to *(x), which matches files executable by the owner. *(R) and *(r) match readable files; *(W) and *(w), which checks for writable files. *(W) is especially important, since it checks for world-writable files:
# To find all plain files, you can use *(.)
# *(U) matches all files owned by you. To search for all files not owned by you, use *(^U)
# *(s) searches for setuid files:
# *(u$UID)
#
# ^q will put the current command onto the stack. it reappears after hitting enter
#
#
##maybe we want to use this at some point
# prompt (if running screen, show window #)
#if [ x$WINDOW != x ]; then
# export PS1="%m[$WINDOW]%# "
#else
# export PS1='%m%# '
#fi
#
# preexec hook shows command in title as it's running, and precmd sets it to
# something else when it's done. this should work with screen and
# gnome-terminal2/multi-gnome-terminal
#
#case $TERM in
# xterm*|screen*)
# preexec () {
# export CURRENTCMD="$1"
# if [ x$WINDOW != x ]; then
# print -Pn "\ek$1\e\\"
# else
# print -Pn "\e]0;$1\a"
# fi
# }
# precmd () {
# if [[ ! -z $CURRENTCMD ]]; then
# if [ x$WINDOW != x ]; then
# print -Pn "\ek($CURRENTCMD)\e\\"
# else
# print -Pn "\e]0;($CURRENTCMD)\a"
# fi
# fi
# }
# ;;
#esac
## functions for displaying neat stuff in *term title
#case $TERM in
# *xterm*|rxvt|(dt|k|E)term)
# ## display user@host and full dir in *term title
# precmd () {
# print -Pn "\033]0;%n@%m %~\007"
# #print -Pn "\033]0;%n@%m%# %~ %l %w :: %T\a" ## or use this
# }
# ## display user@host and name of current process in *term title
# preexec () {
# print -Pn "\033]0;%n@%m <$1> %~\007"
# #print -Pn "\033]0;%n@%m%# <$1> %~ %l %w :: %T\a" ## or use this
# }
# ;;
#esac
## TODO use vared! :)
#3:13:04 < RichiH> e1f: you know how the name of xterm et al can be changed according to current dir? i would want to add what is running in the shell
#23:25:52 < caphuso> $1, $2 or $3 in preexec
#23:54:05 < e1f> yes, standard escape sequences
#23:55:02 < e1f> i have a function called xtt that is: print -nR $'\033]0;'$*$'\a'
#23:55:21 < e1f> if you say xtt foo, then the xterm title will be "foo"
#suggestion for ls colors
# export LS_COLORS='no=0:fi=0:di=32:ln=36:or=1;40:mi=1;40:pi=31:so=33:bd=44;37:cd=44;37:ex=35:*.jpg=1;32:*.jpeg=1;32:*.JPG=1;32:*.gif=1;32:*.png=1;32:*.jpeg=1;32:*.ppm=1;32:*.pgm=1;32:*.pbm=1;32:*.c=1;33:*.C=1;33:*.h=1;33:*.cc=1;33:*.awk=1;33:*.pl=1;33:*.bz2=1;35:*.gz=1;31:*.tar=1;31:*.zip=1;31:*.lha=1;31:*.lzh=1;31:*.arj=1;31:*.tgz=1;31:*.taz=1;31:*.html=1;34:*.htm=1;34:*.doc=1;34:*.txt=1;34:*.o=1;36:*.a=1;36:*.php3=1;31'
# precmd () {
# TMPPATH=" "$PWD
# # SHORTPATH=${(M)TMPPATH%???????????}
# SHORTPATH=${(M)TMPPATH%?????????}
# #PS1=$(echo "%{\033[0;36m%}$SHORTPATH%{\033[0m%},%{\033[0;31m%}%j%{\033[0m%}%% ")
# PS1=$(echo "$cyan$SHORTPATH$nocolor,$red%j$nocolor%# ")
# }
###################################################
# # The following lines were added by compinstall
#
# zstyle ':completion:*' add-space true
# zstyle ':completion:*' auto-description 'specify '\''%d'\'''
# zstyle ':completion:*' completer _list _oldlist _expand _complete _match _correct _approximate _prefix
# zstyle ':completion:*' completions 1
# zstyle ':completion:*' expand prefix suffix
# zstyle ':completion:*' file-sort name
# zstyle ':completion:*' format 'I would use completion '\''%d'\'' for this completion'
# zstyle ':completion:*' glob 1
# zstyle ':completion:*' group-name ''
# zstyle ':completion:*' ignore-parents parent pwd ..
# zstyle ':completion:*' insert-unambiguous true
# zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
# zstyle ':completion:*' list-suffixes true
# zstyle ':completion:*' match-original both
# zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' '+m:{a-zA-Z}={A-Za-z}' '+r:|[._-]=** r:|=**'
# zstyle ':completion:*' max-errors 2
# zstyle ':completion:*' menu select=10
# zstyle ':completion:*' original false
# zstyle ':completion:*' preserve-prefix '//[^/]##/'
# zstyle ':completion:*' prompt 'Found %e errors in your completion, correct?'
# zstyle ':completion:*' select-prompt %SScrolling active: current selection at %l \(%p\)%s
# zstyle ':completion:*' substitute 1
# zstyle ':completion:*' verbose true
# zstyle :compinstall filename '/home/richih/.zshrc'
#
# autoload -Uz compinit
# compinit
# # End of lines added by compinstall
# # Lines configured by zsh-newuser-install
# HISTFILE=~/.histfile
# HISTSIZE=1000
# SAVEHIST=1000
# setopt appendhistory autocd beep extendedglob nomatch notify
# bindkey -e
# # End of lines configured by zsh-newuser-install
# # RichiH comments on above:
# # zstyle ':completion:*' file-sort name can also do size, number of hard links, access, modification & inode change time
# # you must set COMPLETE_IN_WORD
# # RichiH comments end
###################################################
##
autoload run-help
echo ""
echo "read http://www.plenz.com/tmp/setup/zshrc"
echo ""
startup