# CREDITS # ======= # Some of this is mine , some is from , some is take from spider's # zshrc, and some from guckes's zshrc. Some bash # functions are nicked from ciaranm's bashrc. Some # stuff is totally random. It is definately NOT Pwnz3r's # . It pisses me off # quite a bit when people take things as-is or open and don't give # credit. Even if the work in question is not liscensed as such, it just # comes down to manners. # README # ====== # * Remember to change the stuff specific to me! It's all at the top of # this file. # * You can obviously only get the most out of this file if you take the # time to read through the comments. Of course, you can still see # zsh's superiority by simply plugging this file in and using it. # LOCAL # ===== # Man pages look a lot better in vim - change the path if you use a # different version of vim!. #export ECHANGELOG_USER="Michael Goffin " #LS_COLORS='no=00;32:fi=00:di=00;34:ln=01;36:pi=04;33:so=01;35:bd=33;04:cd=33;04:or=31;01:ex=00;32:*.rtf=00;33:*.txt=00;33:*.html=00;33:*.doc=00;33:*.pdf=00;33:*.ps=00;33:*.sit=00;31:*.hqx=00;31:*.bin=00;31:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.deb=00;31:*.dmg=00;36:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.ppm=00;35:*.tga=00;35:*.xbm=00;35:*.xpm=00;35:*.tif=00;35:*.mpg=00;37:*.avi=00;37:*.gl=00;37:*.dl=00;37:*.mov=00;37:*.mp3=00;35:' #export LS_COLORS; export LSCOLORS='ExFxCxdxBxegedabagacad' export LS_COLORS='di=1;36:ln=1;33:so=01;32:ex=32:bd=46;34:cd=43;34' # part of my ssh-agent + screen magic #export OLD_SSH_AUTH=$SSH_AUTH_SOCK #export SSH_AUTH_SOCK=~/.ssh/auth/$HOST-screen-resume-auth # zmodload -i zsh/complist #eval $(dircolors -b ~/.dir_colors) zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" zstyle ':completion:*:*:kill:*' list-colors '=%*=01;31' # Load the completion system # I'm not a big fan, it's very annoying, but left it commented out autoload -U compinit; compinit # Very powerful version of mv implemented in zsh. The main feature I # know of it that seperates it from the standard mv is that it saves you # time by being able to use patterns for both source and dest. So: # # slarti@pohl % zmv *foo *bar # # On a series of files like onefoo, twofoo, threefoo, fivefoo would be # renamed to onebar twobar threebar fourbar. # # Although that's nifty enough, I suspect there are other features I # don't know about yet... # # Read $fpath/zmv for some more basic examples of usage. autoload -U zmv # Command line calculator written in zsh, with a complete history # mechanism and other shell features. autoload -U zcalc # Like xargs, but instead of reading lines of arguments from standard input, # it takes them from the command line. This is possible/useful because, # especially with recursive glob operators, zsh often can construct a command # line for a shell function that is longer than can be accepted by an external # command. This is what's often referred to as the "shitty Linux exec limit" ;) # The limitation is on the number of characters or arguments. # # slarti@pohl % echo {1..30000} # zsh: argument list too long: /bin/echo # zsh: exit 127 /bin/echo {1..30000} autoload -U zargs # zed is a tiny command-line editor in pure ZSH; no other shell could do # this. zed itself is simple as anything, but it's killer feature for # me is that it can edit functions on the go with zed -f (or # fned . This is useful for me when I'm using and defining # functions interactively, for example, when I'm working through the # Portage tree in CVS. It allows me to edit a function on the fly, # without having to call the last definition back up from the history # and re-edit that in ZLE. It also indents the function, even if it was # defined on all one line in the line editor, making it easy as anything # to edit. # # ^X^W to save, ^C to abort. autoload -U zed # Incremental completion of a word. After starting this, a list of # completion choices can be shown after every character you type, which # can deleted with ^H or delete. Return will accept the current # completion. Hit tab for normal completion, ^G to get back where you # came from and ^D to list matches. autoload -U incremental-complete-word zle -N incremental-complete-word bindkey "^Xi" incremental-complete-word # 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 # This set of functions implements a sort of magic history searching. # After predict-on, typing characters causes the editor to look backward # in the history for the first line beginning with what you have typed so # far. After predict-off, editing returns to normal for the line found. # In fact, you often don't even need to use predict-off, because if the # line doesn't match something in the history, adding a key performs # standard completion - though editing in the middle is liable to delete # the rest of the line. autoload -U predict-on zle -N predict-on zle -N predict-off bindkey "^X^Z" predict-on bindkey "^Z" predict-off # run-help is a help finder, bound in ZLE to M-h. It doesn't need to be # autoloaded to work - the non-autoloaded version just looks up a man # page for the command under the cursor, then when that process is # finished it pulls your old command line back up from the buffer stack. # However, with the autoloaded function and: # # mkdir ~/zsh-help; cd ~/zsh-help MANPAGER="less" man zshbuiltins | # colcrt \ | perl /usr/share/zsh/4.2.1/Util/helpfiles # # It'll work for zsh builtins too. By the way, I've assumed some things # in that command. ~/zsh-help can be wherever you like, MANPAGER needs # to be any standard pager (less, pg, more, just not the MANPAGER I have # defined in this file), colcrt can be col -bx, and the path to # helpfiles may be different for you (Util may not even be installed # with your distribution; fair enough, make install doesn't install it. # Dig up a source tarball and everything's in there). # Define our helpdir unalias run-help HELPDIR=~/zsh-help # We need to get rid of the old run-help (NOTE: if you source ~/.zshrc # this will through up a warning about the alias not existing for # unaliasing. The solution is to form an if construct, with the # condition that run-help is aliased. I do not know how to do this. # unalias run-help # Load the new one autoload -U run-help # Colours autoload -U colors; colors # Path if [ -f ~/.zshpath ] ; then source ~/.zshpath fi # Exports # For those who want the default Gentoo prompt back: #autoload -U promptinit #promptinit #prompt gentoo # Prompt - Fairly similar to the default Gentoo prompt, but a little bit more # compact, whilst being just as helpful. Makes full use of RPROMPT. #PROMPT="%{%}%n@%M %{%}%#%{%} " #RPROMPT="[%{%}%~%{%}]" # prompt # results in a prompt like this # [username@fqdnhost:~]% [#|#] # ^ ^ # | | # # of directories in folder--- | # # of files in folder----------- #FILE=$(/bin/ls -la | awk '{if (substr($1,1,1) == "-") {print}}' | wc -l|sed 's/^[ \t]*//') #DIRS=$(/bin/ls -ld */. | wc -l|sed 's/^[ \t]*//') # #PROMPT WITHOUT TIME #PROMPT=$'%{\e[0;36m%}%B[%b%{\e[0m%}%B%n%b%{\e[0;36m%}%B@%b%{\e[0m%}%B%m%b%{\e[0;36m%}%B]%b%{\e[0;36m%}%B[%b%{\e[0m%}%B%!%b%{\e[0;36m%}%B]%b%{\e[0m%}%B%#%b ' #local hname="$(host `hostname` | grep alias | head -1 | cut -d. -f1)" local smiley="%(?,%{$fg[green]%}:%)%{$reset_color%},%{$fg[red]%}:(%{$reset_color%})" #if [[ $hname == "" ]]; then PROMPT=$'%{\e[0;36m%}%B[%b%{\e[0m%}%B%n%b%{\e[0;36m%}%B@%b%{\e[0m%}%B%1m%b%{\e[0;36m%}%B]%b%{\e[0;36m%}%B[%b%{\e[0m%}%B${smiley}%b%{\e[0;36m%}%B] %b%{\e[0m%}%B%#%b ' #else # PROMPT=$'%{\e[0;36m%}%B[%b%{\e[0m%}%B%n%b%{\e[0;36m%}%B@%b%{\e[0m%}%B{hname}%b%{\e[0;36m%}%B]%b%{\e[0;36m%}%B[%b%{\e[0m%}%B${smiley}%b%{\e[0;36m%}%B] %b%{\e[0m%}%B%#%b ' #fi #PROMPT WITH TIME #PROMPT=$'%{\e[0;36m%}%B[%b%{\e[0m%}%B%T%b%{\e[0;36m%}%B]%b%{\e[0;36m%}%B[%b%{\e[0m%}%B%n%b%{\e[0;36m%}%B@%b%{\e[0m%}%B%m%b%{\e[0;36m%}%B]%b%{\e[0;36m%}%B[%b%{\e[0m%}%B%!%b%{\e[0;36m%}%B]%b%{\e[0m%}%B%#%b ' #RPROMPT="[$DIRS|$FILE]" export COLORTERM=yes export CVS_RSH=rsh export CVS_SERVER=/usr/local/bin/cvs export EDITOR=vim export HOSTTYPE="$(uname -m)" export LINKS_XTERM=screen export ORACLE_HOME=/usr/local/oracle export PAGER=less export SYBASE=/usr/local/sybase export SYBASE_OCS=OCS export VISUAL=vim # SCREENDIR will mess screen up unset SCREENDIR # Colours # -- # I haven't actually used these yet, apart from for reference. You can use # these when prompting. Capitalised stuff is bold. export red=$'%{%}' export RED=$'%{%}' export green=$'%{%}' export GREEN=$'%{%}' export blue=$'%{%}' export BLUE=$'%{%}' export purple=$'%{%}' export PURPLE=$'%{}' export cyan=$'%{%}' export CYAN=$'%{}' export WHITE=$'%{}' export white=$'%{}' export NC=$'%{%}' # Make sure no cores can be dumped limit coredumpsize 0 # Completion options -- I should convert these to the new, more # versatile compsys. compctl -g '*(-/D)' cd compctl -c which compctl -b bindkey compctl -v export unset vared compctl -o setopt unsetopt compctl -c sudo # Hostname Completion via .ssh/known_hosts #local known_hosts #known_hosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} ) #zstyle ':completion:*' hosts #known_hosts=($(awk '/^[^#]/ {print $2 $3" "$4" "$5}' /etc/hosts | grep -v ip6- && grep "^#%" /etc/hosts | awk -F% '{print $2}')) #known_hosts=(awk '{split($7,a,")");if(a[1] ne "") print a[1]}' /usr/local/oracle/config/tnsnames.ora) #zstyle ':completion:*' hosts $known_hosts # # Set up completion for hostnames in ~/.ssh/known_hosts myhosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} ) zstyle ':completion:*' hosts $myhosts #zstyle -e ':completion::*:hosts' hosts 'reply=($(sed -e "/^#/d" -e "s/ .*\$//" -e "s/,/ /g" /etc/ssh_known_hosts(N) ~/.ssh/known_hosts(N) 2>/dev/null | xargs) $(grep \^Host ~/.ssh/config(N) | cut -f2 -d\ 2>/dev/null | xargs))' # History things HISTFILE=$HOME/.zshistory SAVEHIST=1000 HISTSIZE=1600 TMPPREFIX=$HOME/tmp # Key bindings.. looking healthier now. # You can use: # % autoload -U zkbd # % zkbd # to discover your keys. # I'm not a fan of emacs at all, so I prefer the vi keybindings for zsh # zle bindkey -v bindkey "\e_" insert-last-word bindkey "\e*" expand-word bindkey "\e=" list-choices bindkey -M vicmd k vi-up-line-or-history bindkey -M vicmd j vi-down-line-or-history # Up, down left, right. # echotc is part of the zsh/termcap module. It outputs the termcap value # corresponding to the capability it was given as an argument. man zshmodules. zmodload -i zsh/termcap bindkey "$(echotc kl)" backward-char bindkey "$(echotc kr)" forward-char bindkey "$(echotc ku)" up-history bindkey "$(echotc kd)" down-history #bindkey "$(echotc ku)" up-line-or-history #bindkey "$(echotc kd)" down-line-or-history bindkey '\e[3~' delete-char # Delete #if [[ "$TERM" == "rxvt-unicode" ]]; then bindkey '\e[7~' beginning-of-line # Home bindkey '\e[8~' end-of-line # End #else # At least xterm; probably other terms too # bindkey '\e[H~' beginning-of-line # Home # bindkey '\e[F~' end-of-line # End #fi bindkey '\e[5~' up-history # PageUp bindkey '\e[6~' down-history # PageDown # Aliases alias attach='$HOME/sh/grabssh.sh; screen -x' if [ "$WINDOW" != '' ]; then alias ssh=". $HOME/sh/fixssh; ssh" fi alias vi="vim" alias svi="sudo vim" alias s="sudo" alias commit="cvs commit" alias rezsh=". ~/.zshrc" alias revim=". ~/.vimrc" alias syn="ssh mjg@syn.csh.rit.edu" alias ssh-tunnel="ssh -D 8080 -f -C -g -N mjg@syn" # Host aliases config_FreeBSD() { PSARGS=-ax alias d="ls -GaFh" alias ld="ls -GaFhld" alias sld="sudo ls -GahFld" alias ls="ls -GahF" alias ll="ls -FlhaG" alias sll="sudo ls -FhlaG" } config_Linux() { PSARGS=ax alias d="ls --color=auto -aFh" alias ld="ls --color -aFlhd" alias sld="sudo ls --color -ahFld" alias ls="ls --color=auto -ahF" alias ll="ls --color -Fhla" alias sll="sudo ls --color -Fhla" } config_SunOS() { PSARGS=ax alias d="ls --color=always -Fah" alias ld="ls --color=always -Fahld" alias sld="sudo ls --color=always -Fahld" alias ls="ls --color=always -Fha" alias ll="ls --color=always -Fhal" alias sll="sudo ls --color=always -Fhal" } UNAME=`uname` case $UNAME in FreeBSD) config_FreeBSD ;; Darwin) config_FreeBSD ;; Linux) config_Linux ;; SunOS) config_SunOS ;; esac # This function sets the window tile to user@host:/workingdir before each # prompt. If you're using screen, it sets the window title (works # wonderfully for hardstatus lines :) precmd () { # From plasmaroo.. not quite working the way I want though. #[ $? -eq 0 ] && export RPS1='' && export RPS1='' || export RPS1="$(print \ #'%{\e[1;33m%}'$?'%{\e[0m%}')" [[ -t 1 ]] || return case $TERM in *xterm*|rxvt*|(dt|k|E|a)term) print -Pn "]2;%n@%M:%~\a" ;; screen*) print -Pn "\"%n@%M:%~\134" # Screen's being annoying with unicode or I'm being dumb. alias centericq="TERM=rxvt centericq" ;; esac } # This sets the window title to the last run command. [[ -t 1 ]] || return case $TERM in *xterm*|rxvt*|(dt|k|E|a)term) preexec () { print -Pn "]2;$1\a" } ;; screen*) preexec () { print -Pn "\"$1\134" } ;; esac # colorize STDERR - causes issues with input prompts #exec 2>>(while read line; do # print '\e[91m'${(q)line}'\e[0m' > /dev/tty; done &) # Some home cooked functions - pinched from Ciaran McCreesh # because I've got no imagination. google() { w3m "http://www.google.com/search?q=$@" } # Pretty menu! zstyle ':completion:*' menu select=1 # Completion options zstyle ':completion:*' completer _complete _prefix zstyle ':completion::prefix-1:*' completer _complete zstyle ':completion:incremental:*' completer _complete _correct zstyle ':completion:predict:*' completer _complete # Completion caching zstyle ':completion::complete:*' use-cache 1 zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST # Expand partial paths zstyle ':completion:*' expand 'yes' zstyle ':completion:*' squeeze-slashes 'yes' # Include non-hidden directories in globbed file completions # for certain commands zstyle ':completion::complete:*' '\\' # Use menuselection for pid completion zstyle ':completion:*:*:kill:*' menu yes select zstyle ':completion:*:kill:*' force-list always # tag-order 'globbed-files directories' all-files zstyle ':completion::complete:*:tar:directories' file-patterns '*~.*(-/)' # Don't complete backup files as executables zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~' # Separate matches into groups zstyle ':completion:*:matches' group 'yes' # With commands like rm, it's annoying if you keep getting offered the same # file multiple times. This fixes it. Also good for cp, et cetera.. zstyle ':completion:*:rm:*' ignore-line yes zstyle ':completion:*:cp:*' ignore-line yes # Describe each match group. zstyle ':completion:*:descriptions' format "%B---- %d%b" # Messages/warnings format zstyle ':completion:*:messages' format '%B%U---- %d%u%b' zstyle ':completion:*:warnings' format '%B%U---- no match for: %d%u%b' # Describe options in full zstyle ':completion:*:options' description 'yes' zstyle ':completion:*:options' auto-description '%d' # Simulate spider's old abbrev-expand 3.0.5 patch zstyle ':completion:*:history-words' stop verbose zstyle ':completion:*:history-words' remove-all-dups yes zstyle ':completion:*:history-words' list false # Options setopt \ NO_all_export \ always_last_prompt \ always_to_end \ append_history \ auto_cd \ auto_list \ auto_menu \ auto_name_dirs \ auto_param_keys \ auto_param_slash \ auto_pushd \ auto_remove_slash \ NO_auto_resume \ bad_pattern \ bang_hist \ NO_beep \ brace_ccl \ correct_all \ NO_bsd_echo \ cdable_vars \ NO_chase_links \ clobber \ complete_aliases \ complete_in_word \ correct \ NO_correct_all \ csh_junkie_history \ NO_csh_junkie_loops \ NO_csh_junkie_quotes \ NO_csh_null_glob \ equals \ extended_glob \ extended_history \ function_argzero \ glob \ NO_glob_assign \ glob_complete \ NO_glob_dots \ NO_glob_subst \ NO_hash_cmds \ NO_hash_dirs \ hash_list_all \ hist_allow_clobber \ hist_beep \ hist_ignore_dups \ hist_ignore_space \ NO_hist_no_store \ hist_verify \ NO_hup \ NO_ignore_braces \ NO_ignore_eof \ interactive_comments \ inc_append_history \ NO_list_ambiguous \ NO_list_beep \ list_types \ long_list_jobs \ magic_equal_subst \ NO_mail_warning \ NO_mark_dirs \ menu_complete \ multios \ NO_nomatch \ notify \ NO_null_glob \ numeric_glob_sort \ NO_overstrike \ path_dirs \ posix_builtins \ NO_print_exit_value \ NO_prompt_cr \ prompt_subst \ pushd_ignore_dups \ NO_pushd_minus \ pushd_silent \ pushd_to_home \ rc_expand_param \ NO_rc_quotes \ NO_rm_star_silent \ NO_sh_file_expansion \ sh_option_letters \ short_loops \ NO_sh_word_split \ NO_single_line_zle \ NO_sun_keyboard_hack \ NO_verbose \ zle