########################################################## # Prompt setprompt () { setopt prompt_subst ### # See if we can use colors. autoload colors zsh/terminfo if [[ "$terminfo[colors]" -ge 8 ]]; then colors fi for color in red green yellow blue magenta cyan white; do eval local ${color}='%{$fg[${(L)color}]%}' eval local ${color}_bold='%{$terminfo[bold]$fg[${(L)color}]%}' done local nocolor="%{$terminfo[sgr0]%}" # Base prompt. pr_baseprompt="%(!.${red}%U%n%u.${green}%n)" # Username.. red underlining if uid 0 (root) pr_baseprompt+="${magenta}@${green}%m" # "@" pr_baseprompt+="${yellow}:${green}%30<...<%~%<<%" # truncated path pr_baseprompt+="(?.. ${red}%?)" # Exit code of previous command pr_baseprompt+="${yellow}>${nocolor} " # Finally, add a yellow "> " # Info for title bar/screen title pr_titleinfo='%(!.[ROOT] | .)%l) %n@%m:%30<...<%~%<<' pr_windowtitle='' pr_wt_in='' pr_wt_out='' case ${TERM} in xterm*|rxvt) pr_wt_in=$'\e]0;' pr_wt_out=$'\a' ;; tmux*) pr_wt_in=$'\e]2;' pr_wt_out=$'\e\\' ;; screen) # We also set the screen hardstatus format here.. it's a oncer. print -n "\e_screen \005S :\005 - \005t\e\\" pr_wt_in=$'\ek' pr_wt_out=$'\e\\' ;; esac if [[ -n "${pr_wt_in}" ]];then pr_windowtitle="${pr_wt_in}${pr_titleinfo}${pr_wt_out}" fi # Finally, set prompts PROMPT="%{${pr_windowtitle}%}${pr_baseprompt}" RPROMPT="${green}< ${red}%!${nocolor}" PS2="${yellow}%_ ${green}>${nocolor} " # Create the prexec hook function to set the title to the current command preexec () { [[ -n "${pr_wt_in}" ]] && print -nPR "${pr_wt_in}%l) %n@%m: %40>...>${(V)1//\%/%%}%<<${pr_wt_out}"; } } setprompt ########################################################## # Misc #cdpath=(.. ~) # make cd search other directories limit core 0 # no core dumps umask 022 # for user group system setopt nopromptcr # No cr before prompt. #setopt extendedglob # Lots of cool extra wildcards #setopt mailwarning # New mail? setopt correct # Correct commands #setopt nobanghist # No bang-history, thanks # Note that the following comment makes me cringe now, but is left in for # historical amusement value. (joeyh is funny) setopt autolist automenu # Filename completion: the best of csh and 4dos! setopt nobeep nolistbeep setopt autocd # Exec directory to cd there setopt noclobber noflowcontrol setopt autoresume #setopt print_exit_value setopt list_packed unsetopt bgnice # History setup. setopt share_history setopt hist_ignore_dups setopt hist_allow_clobber setopt hist_reduce_blanks # Make alt key function as meta key. #[[ $TERM = "xterm" ]] && stty pass8 && bindkey -me # ctrl-s will no longer freeze the terminal. stty -ixon kill ^K stty erase "^?" eval `dircolors 2>/dev/null` # set up color-ls variables watch=(notme) # watch for everybody but me LOGCHECK=120 # check every 2 min for login/logout activity # Turn on full-featured completion autoload -U compinit compinit if [ -e ~/.ssh/known_hosts ]; then # Use .ssh/known_hosts for hostnames. hosts=(${${(f)"$(<~/.ssh/known_hosts)"//,/ }%%\ *}) zstyle ':completion:*:hosts' hosts $hosts fi ########################################################## # Aliases alias whois='whois -h geektools.com' alias df='df -h' alias cls=clear alias cscs='clear;printf "\033[3J"' # Do we have GNU ls of a new enough version for color? (ls --help 2>/dev/null |grep -- --color=) >/dev/null && \ alias ls='ls -b -CF --color=auto' alias l=ls alias dir='ls -lhga' alias du='du -h' alias f=finger alias ftp=ncftp alias md=mkdir alias rd=rmdir alias k=killall alias mtr='mtr --curses' #alias su='su -' #if [ -e `which reportbug 2>/dev/null` ]; then # alias bug='reportbug -b' #fi alias stardate='date "+%y%m.%d/%H%M"' # I don't like the zsh builtin time command. if [ -e /usr/bin/time ] ; then alias time=/usr/bin/time ; fi # Use GPG2 in preference over GPG1 if [ -e /usr/bin/gpg2 ] ; then alias gpg=/usr/bin/gpg2 ; fi # Xterm/rxvt resizing-fu alias default='echo -ne "\033]50;fixed\007"' alias hide='echo -ne "\033]50;nil2\007"' alias tiny='echo -ne "\033]50;5x7\007"' alias small='echo -ne "\033]50;6x10\007"' alias medium='echo -ne "\033]50;7x13\007"' alias large='echo -ne "\033]50;9x15\007"' alias huge='echo -ne "\033]50;10x20\007"' ########################################################## # Key bindings autoload -U up-line-or-beginning-search autoload -U down-line-or-beginning-search zle -N up-line-or-beginning-search zle -N down-line-or-beginning-search bindkey "\eOA" up-line-or-beginning-search bindkey "\eOB" down-line-or-beginning-search bindkey "\e[A" history-search-backward bindkey "\e[B" history-search-forward bindkey '^K' kill-whole-line bindkey -s '^L' "|less\n" # ctrl-L pipes to less bindkey -s '^B' " &\n" # ctrl-B runs it in the background bindkey "\e[1~" beginning-of-line # Home bindkey "\e[H" beginning-of-line # Home (xterm) [[ $TERM = "rxvt" ]] && bindkey "\e[7~" beginning-of-line bindkey "\e[4~" end-of-line # End bindkey "\e[F" end-of-line # End (xterm) [[ $TERM = "rxvt" ]] && bindkey "\e[8~" end-of-line bindkey "\e[2~" overwrite-mode # Ins bindkey "\e[3~" delete-char # Delete ########################################################## # Functions # Return the size of a directory. dirsize() { pushd >/dev/null; chdir $1; du |tail --lines 1; popd >/dev/null; } # Calculator calc () { echo $* |bc -l } # This fingers @host. @ () { finger @$1 }