#---------------------------------------------------- # File: ~/.zshrc # Author: Florian "Bluewind" Pritz #---------------------------------------------------- # Don't show input while loading stty -echo ZDOTDIR="$HOME/.zsh" # Colors {{{ #use these in functions/shell scripts export NC='\e[0m' export white='\e[0;30m' export WHITE='\e[1;30m' export red='\e[0;31m' export RED='\e[1;31m' export green='\e[0;32m' export GREEN='\e[1;32m' export yellow='\e[0;33m' export YELLOW='\e[1;33m' export blue='\e[0;34m' export BLUE='\e[1;34m' export magenta='\e[0;35m' export MAGENTA='\e[1;35m' export cyan='\e[0;36m' export CYAN='\e[1;36m' export black='\e[0;37m' export BLACK='\e[1;37m' # these are for use in PROMPT p_nc=$'%{\e[0m%}' p_white=$'%{\e[0;30m%}' p_WHITE=$'%{\e[1;30m%}' p_red=$'%{\e[0;31m%}' p_RED=$'%{\e[1;31m%}' p_green=$'%{\e[0;32m%}' p_GREEN=$'%{\e[1;32m%}' p_yellow=$'%{\e[0;33m%}' p_YELLOW=$'%{\e[1;33m%}' p_blue=$'%{\e[0;34m%}' p_BLUE=$'%{\e[1;34m%}' p_magenta=$'%{\e[0;35m%}' p_MAGENTA=$'%{\e[1;35m%}' p_cyan=$'%{\e[0;36m%}' p_CYAN=$'%{\e[1;36m%}' p_black=$'%{\e[0;37m%}' p_white=$'%{\e[1;37m%}' # colors in framebuffer! if [[ $TERM = "linux" ]]; then ${HOME}/bin/parse_xdefaults.sh clear #for background artifacting fi # some better colors for ls eval "`dircolors -b`" # }}} # Keybindings {{{ bindkey -e bindkey '\e[1~' beginning-of-line bindkey '\e[4~' end-of-line bindkey '\e[3~' delete-char bindkey '\e[2~' overwrite-mode bindkey "^[[7~" beginning-of-line # Pos1 bindkey "^[[8~" end-of-line # End bindkey "^[[A" history-beginning-search-backward bindkey "^[[B" history-beginning-search-forward # HOWTO make your own: # bindkey '' action # for some actions run `bindkey` # "cd......" ;) _rationalise-dot() { if [[ $LBUFFER = "cd "* ]]; then if [[ $LBUFFER = *.. ]]; then LBUFFER+=/.. else LBUFFER+=. fi else LBUFFER+=. fi } zle -N _rationalise-dot bindkey . _rationalise-dot # add edit command line feature ("alt-e") autoload edit-command-line zle -N edit-command-line bindkey '\ee' edit-command-line # source: http://github.com/xfire/dotfiles/blob/master/.zsh/abbrev_expansion # power completion / abbreviation expansion / buffer expansion # see http://zshwiki.org/home/examples/zleiab for details # less risky than the global aliases but powerful as well # just type the abbreviation key and afterwards ',' to expand it typeset -Ag abbreviations abbreviations=( # 'M' '| most' 'dn' '&>/dev/null ' 'dn1' '1>/dev/null ' 'dn2' '2>/dev/null ' # 'NULL' '>/dev/null 2>&1' '21' '2>&1 ' 'l' '| less' 'll' '|& less' 'g' '| grep ' 'gi' '| grep -i ' 'eg' '| egrep ' 'h' '| head ' 'hh' '|& head ' 't' '| tail ' 'tt' '|& tail ' 'wc' '| wc' # 'wcb' '| wc -c' # 'wcc' '| wc -m' # 'wcw' '| wc -w' 'wcl' '| wc -l' 's' '| sort' 'su' '| sort -u' 'sl' '| sort | less' 'a' '| awk ' # 'A1' "| awk '{print \$1}'" # 'A2' "| awk '{print \$2}'" # 'A3' "| awk '{print \$3}'" # 'A4' "| awk '{print \$4}'" # 'A5' "| awk '{print \$5}'" # 'A6' "| awk '{print \$6}'" # 'A7' "| awk '{print \$7}'" # 'A8' "| awk '{print \$8}'" # 'A9' "| awk '{print \$9}'" # 'CA' "|& cat -A" 'v' '|& vim -' 'x' '| xargs' 'xx' '|& xargs' 'hide' "echo -en '\033]50;nil2\007'" 'tiny' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-80-*-*-c-*-iso8859-15\007"' 'small' 'echo -en "\033]50;6x10\007"' 'medium' 'echo -en "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-15\007"' 'default' 'echo -e "\033]50;-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-15\007"' 'large' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-150-*-*-c-*-iso8859-15\007"' 'huge' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-210-*-*-c-*-iso8859-15\007"' 'smartfont' 'echo -en "\033]50;-artwiz-smoothansi-*-*-*-*-*-*-*-*-*-*-*-*\007"' 'semifont' 'echo -en "\033]50;-misc-fixed-medium-r-semicondensed-*-*-120-*-*-*-*-iso8859-15\007"' 'da' 'du -sch ' 'j' 'jobs -l ' 'co' "./configure && make && sudo make install" 'ch' "./configure --help" 'rw-' 'chmod 600 ' '600' 'chmod u+rw-x,g-rwx,o-rwx ' 'rwx' 'chmod u+rwx ' '700' 'chmod u+rwx,g-rwx,o-rwx ' 'r--' 'chmod u+r-wx,g-rwx,o-rwx ' '644' 'chmod u+rw-x,g+r-wx,o+r-wx\n # 4=r,2=w,1=x ' '755' 'chmod u+rwx,g+r-w+x,o+r-w+x ' 'cx' 'chmod +x ' 'de' 'export DISPLAY=:0.0' 'd' 'DISPLAY=:0.0' ) globalias() { local MATCH LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#} LBUFFER+=${abbreviations[$MATCH]:-$MATCH,} } zle -N globalias bindkey "," globalias # }}} # Variables {{{ #export CDPATH=.:$HOME export OOO_FORCE_DESKTOP=gnome export PATH=${HOME}/misc/scripts:${PATH} export EDITOR=vim export VISUAL=$EDITOR export PAGER=vimpager export LESSCHARSET="UTF-8" export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-' export LESS='-F -i -n -w -g -M -R -P%t?f%f \ :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...' # }}} # Terminal title {{{ # also found somewhere prompt_eof_setup() { # preexec() is run after you press enter on your command but before the command is run. preexec() { # define screen/terminal title with the current command (http://aperiodic.net/phil/prompt/) case $TERM in rxvt-unicode*) printf '\33]2;%s\007' $1 ;; screen*) local CMD=${1[(wr)^(*=*|sudo|ssh|exec|-*)]} printf '\ek%s\e\\' $CMD;; esac } } prompt_eof_setup "$@" # }}} # Prompt {{{ EXITCODE="%(?..(%?%1) )" # function to show the current git branch in prompt parse_git_branch() { git branch 2> /dev/null | sed -n 's/\* \(.*\)/\(\1\)/p' } # necessary if you want to use functions in the prompt # without this they wouldn't be run again precmd () { # this has to be on the edge or you have some spaces in the prompt # if you have any workaround please tell if [[ $UID != 0 ]]; then local username_color=$p_blue else local username_color=$p_red fi local host_color=$p_GREEN local path_color=$p_BLUE local gitbranch_color=$p_magenta local exitcode_color=$p_red PROMPT="${username_color}$USERNAME${p_nc}@${host_color}%m${p_nc}\ ${path_color}%~${p_nc} ${gitbranch_color}$(parse_git_branch)${p_nc} ${exitcode_color}$EXITCODE${p_nc}> " } ## Spelling prompt SPROMPT='zsh: correct '%R' to '%r' ? ([Y]es/[N]o/[E]dit/[A]bort) ' # }}} # Functions {{{ # always /etc/rc.d/blub is a bit too much work ;) rc() { sudo /etc/rc.d/$1 $2 } # add current time to a file mbk() { mv -b "${1}" "$(echo $1 | sed -r "s/(.*)(\.|$)(.*)/\1_`date +%Y-%m-%d_%T`\2\3/")" } # easily make backups bk() { cp -br "${1}" "$(echo $1 | sed -r "s/(.*)(\.|$)(.*)/\1_`date +%Y-%m-%d_%T`\2\3/")" } # chpwd () => a function which is executed whenever the directory is changed chpwd() { ls } # idea by Gigamo http://bbs.archlinux.org/viewtopic.php?pid=478094#p478094 ls () { /bin/ls -rhbtF --color=auto $@ && echo "${MAGENTA}Files: ${BLUE}$(/bin/ls -l $@ | grep -v "^[l|d|total]" | wc -l) ${GREEN}--- ${MAGENTA}Directories: ${BLUE}$(/bin/ls -l $@ | grep "^d" | wc -l)${NC}" } ctailf() { tailf "$@" | ccze -A } password() { if [[ -z $1 ]]; then count=8 else count="$1" fi echo $(< /dev/urandom tr -dc A-Za-z0-9_ | head -c$count) } # jump between directories # Copyright 2005 Nikolai Weibull # notice: option AUTO_PUSHD has to be set d(){ emulate -L zsh autoload -U colors local color=$fg_bold[blue] integer i=0 dirs -p | while read dir; do local num="${$(printf "%-4d " $i)/ /.}" printf " %s $color%s$reset_color\n" $num $dir (( i++ )) done integer dir=-1 read -r 'dir?Jump to directory: ' || return (( dir == -1 )) && return if (( dir < 0 || dir >= i )); then echo d: no such directory stack entry: $dir return 1 fi cd ~$dir } # from the grml zshrc iirc hglob() { 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}'<" } # let vim highlight any file for us and save it as html 2html() { vim -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 > /dev/null 2> /dev/null } # download any package's PKGBUILD and go into that dir yd(){ pbget --aur $1 builtin cd $1 } # some script to make this damn agent work easier if [[ -z $DISPLAY ]]; then source ${HOME}/bin/gpg-agent.sh fi # yeah I know you shouldn't use it... google(){ firefox "http://www.google.com/search?&num=100&q=$*" & disown firefox } # swaps 2 files swap() { if [[ -z $1 ]] || [[ -z $2 ]] || [[ $1 = "-h" ]]; then echo -e "${blue}Usage:$NC swap "; echo -e "Swaps files"; return 1 fi if [[ -f $1 ]] && [[ -f $2 ]]; then local TMPFILE=tmp.$$ mv "$1" $TMPFILE mv "$2" "$1" mv $TMPFILE "$2" else echo -e "${RED}Error:$NC One or more files don't exist" return 1 fi } # get your internal and external IPs # also found somewhere on the net my_ip() { MY_IP=$(/sbin/ifconfig eth0 | awk '/inet/ { print $2 } ' | \ sed -e s/addr://) MY_ISP=$(curl www.wieistmeineip.de | awk '(/[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]/) {print}' | awk 'gsub(/[>||<]/," ")' | awk '{print $3}') } ii() { echo -e "\nUser ${RED}"${USER:-"N/A"}"$NC on "${RED}${HOST:-"N/A"}"$NC" echo -e "\n${RED}Additionnal information:$NC " ; uname -a echo -e "\n${RED}Users logged on:$NC " ; w -h echo -e "\n${RED}Current date:$NC " ; date echo -e "\n${RED}Machine stats:$NC " ; uptime echo -e "\n${RED}Memory stats:$NC " ; free my_ip 2>&- ; echo -e "\n${RED}Local IP Address:$NC" ; echo ${MY_IP:-"N/A"} echo -e "\n${RED}ISP Address:$NC" ; echo ${MY_ISP:-"N/A"} echo } # short info to display when opening a new shell short_ii() { echo -e "\nUser ${RED}"${USER:-"N/A"}"$NC on "${RED}${HOST:-"N/A"}"$NC" echo -e "\n${RED}Machine stats:$NC " ; uptime echo } # }}} # History {{{ export HISTFILE=~/.zsh/histfile # for some odd reason allocating RAM to save the histfile takes ages.. export HISTSIZE=5000 export SAVEHIST=$HISTSIZE # }}} # Other ZSH options {{{ autoload colors colors # .. -> cd ../ setopt autocd setopt correct_all # cd /etc/**/foo/blub searches ;) setopt extendedglob # push cds to directory stack setopt auto_pushd # don't push something twice setopt pushd_ignore_dups # don't kill jobs when exiting shell setopt no_hup # and don't warn setopt no_check_jobs # show us when some command didn't exit with 0 setopt print_exit_value # makepkg -g > PKGBUILD # zsh: file exists: PKGBUILD # # work saved ;) setopt no_clobber setopt INC_APPEND_HISTORY setopt SHARE_HISTORY setopt EXTENDED_HISTORY setopt HIST_REDUCE_BLANKS setopt HIST_IGNORE_SPACE setopt nohistverify setopt prompt_subst setopt HIST_FCNTL_LOCK # show the output of time if commands takes longer than n secs (only user+system) REPORTTIME=5 # allow comments in interactive shells setopt interactivecomments # ignore lines starting with a space setopt hist_ignore_space # disable XON/XOFF flow control (^s/^q) stty -ixon # }}} # Aliases {{{ # better ask before we loose data alias rm='rm -Iv' alias cp='cp -iv' alias mv='mv -iv' # I don't like bytes alias dum='du -kh --max-depth=2' alias du='du -kh' alias dus='du -skh' #alias df='df -kTh' alias df='pydf' # function to make ls look nice is below alias ll='ls -l' alias la='ls -a' alias lla='ls -la' alias lld='ls -ld' alias newpkgb=' cp $HOME/misc/aur/PKGBUILD.proto PKGBUILD' # well I got used to that name ;) alias aurball='makepkg --source -f' alias pkgbuild='makepkg -fc && aurball' alias pushpkg='cp *.pkg.tar.gz *.src.tar.gz /mnt/mistral/srv/drop' alias build32='linux32 sudo makechrootpkg -r ~/misc/chroots/arch32' alias build64='linux64 sudo makechrootpkg -r ~/misc/chroots/arch64' alias install32='linux32 sudo makechrootpkg -r ~/misc/chroots/arch32 -I' alias install64='linux64 sudo makechrootpkg -r ~/misc/chroots/arch64 -I' alias clean32='sudo rm -r ~/misc/chroots/arch32/rw' alias clean64='sudo rm -r ~/misc/chroots/arch64/rw' alias shell32='linux32 sudo mkarchroot -r bash ~/misc/chroots/arch32/root' alias shell64='linux64 sudo mkarchroot -r bash ~/misc/chroots/arch64/root' #alias sudo="sudo " #Sudo wont recognize aliases without this alias s='sudo ' alias x='x -v' alias xx='x -Rv' alias u='upload.sh' alias mtr='mtr -t' alias wcl='wc -l' alias mdstat='cat /proc/mdstat' alias keymap='setxkbmap de -variant nodeadkeys' alias hexdump='hexdump -C' alias pager='${PAGER}' alias more='${PAGER}' alias less='${PAGER}' alias c='${PAGER}' alias v='vim' alias gv='gvim' alias sc='sudo ${PAGER}' alias sv='sudo vim' alias sgv='sudo gvim' alias g='git' # python is too long to type... alias q='python' alias e='exec' alias b='blaze' alias t='todo.sh -d $HOME/.config/todo.cfg' alias nsl='nslookup' alias hgrep="history 0 | grep" alias ncmpc='ncmpc -c' alias youtube='youtube-dl -b ' alias rscp='rsync --partial --progress --rsh="ssh -p 22223"' alias mkdir='nocorrect mkdir' alias wget='nocorrect noglob wget' # updating commands can be long... alias yup='yaourt -Syu --aur' alias yu='yaourt -Syu' # can't they make it use sudo on it's own like yaourt? alias p='sudo powerpill' alias pa='sudo powerpill -Syu' alias py='sudo powerpill -S' alias su='su -' alias y='yaourt' alias ys='yaourt -S' alias ysb='yaourt -Sb' alias ysi='yaourt -Si' alias yr='yaourt -Rs' alias yrc='yaourt -Rcs' alias yrn='yaourt -Rns' alias yqo='yaourt -Qo' alias yql='yaourt -Ql' # too long to remember alias asciidoc_full='asciidoc -a icons -a toc' # other random aliases alias ☠='pkill -9' alias nocomment='egrep -v "^\s*(#|$)"' # global aliases work EVERYWHERE # e.g. dmesg tt # show last 20 lines of dmesg alias -g gg='| grep --color' alias -g eg='| egrep --color' alias -g tt='| tail -n 20' # I always hit y instead of | ... alias -g vv='|' # who doesn't need pastebins? alias -g sp="2>&1 | curl -F 'sprunge=<-' http://sprunge.us" alias -g pp="2>&1 | wgetpaste -X " # e.g. "blub.txt" opens the file instead of showing command not found alias -s txt=mousepad alias -s jpg=gpicview alias -s png=gpicview # }}} # Completion stuff {{{ autoload -Uz compinit compinit # correct 7etc/foo to /etc/foo # if anyone has a working solution for /etc7foo please contact me function _7slash { if [[ $words[CURRENT] = 7(#b)(*)(#e) ]] then compadd -U -X 'Correct leading 7 to /' -f /$match[1] fi } zstyle :compinstall filename '$HOME/.zshrc' # cache results because yaourt is slow zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path $HOME/.zsh/cache # completion colours zstyle ':completion:*' list-colors "${LS_COLORS}" zstyle ':completion:*' completer _complete _match _approximate _7slash zstyle ':completion:*:match:*' original only # allow more mistypes if longer command zstyle -e ':completion:*:approximate:*' \ max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)' # ignore completion for commands we don't have zstyle ':completion:*:functions' ignored-patterns '_*' # show menu when tabbing zstyle ':completion:*' menu yes select # better completion for kill zstyle ':completion:*:*:kill:*' command 'ps -u$USER -o pid,%cpu,tty,cputime,cmd' # Provide more processes in completion of programs like killall: zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq' # bugged with zsh 4.3.10 for whatever reason #zstyle ':completion:*' file-sort time zstyle ':completion:*' file-sort name # Ignore same file on rm zstyle ':completion:*:(rm|kill|diff):*' ignore-line yes zstyle ':completion:*:rm:*' file-patterns '*:all-files' zstyle ':completion:*:wine:*' file-patterns '*.(exe|EXE):exe' # automagic url quoter autoload -U url-quote-magic zle -N self-insert url-quote-magic # e.g. ls foo//bar -> ls foo/bar zstyle ':completion:*' squeeze-slashes true # if in foo/bar don't show bar when cd ../ zstyle ':completion:*:cd:*' ignore-parents parent pwd # Prevent lost+found directory from being completed zstyle ':completion:*:cd:*' ignored-patterns '(*/)#lost+found' # ignore case when completing zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' # make some stuff look better zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}' zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d' # complete my little rc function (archlinux startscripts) function _rc () { case $CURRENT in 2) compadd $(find /etc/rc.d/ -maxdepth 1 -type f -executable -printf '%f ');; 3) compadd $(/etc/rc.d/$words[2] 2> /dev/null | grep -i usage | sed 's/.*{\(.*\)}/\1/; s/|/ /g');; esac } compdef _rc rc # easier way to use sshfs ;) function _ssh-mount () { compadd $(cat ${HOME}/bin/ssh-mount.sh | egrep "Servers:.*" | sed "s#echo \-e \"\${green}Servers\:\$NC##g; s#\"\;##g; s#,##g") } compdef _ssh-mount ssh-mount.sh function _wake () { compadd $(wake) } compdef _wake wake # machine dependent stuff . $HOME/.private_stuff.zsh # }}} # Greetings {{{ #cat /etc/motd #echo -e "${CYAN}Welcome to ZSH ${RED}${ZSH_VERSION}$NC" sysinfo # don't want to read the same every time I open a new shell if [ -x /usr/bin/fortune ]; then /usr/bin/fortune -s fi echo # }}} # {{{ Other stuff that doesn't fit anywhere else #umask 077 stty -ctlecho # }}} # Show again stty echo # vim: set ft=sh: