########################################################## # Prompt function () { 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. local pr_baseprompt 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 local pr_titleinfo='%(!.[ROOT] | .)%l) %n@%m:%30<...<%~%<<' local 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}%(!.[ROOT] | .)%l) %n@%m: %40>...>${(V)1//\%/%%}%<<${pr_wt_out}"; } } ########################################################## # Options # Changing Directories setopt autocd # Exec directory to cd there # Prompting setopt nopromptcr # No cr before prompt. # Completion setopt autolist # Automatically show choices for completion setopt automenu # Filename completion: the best of csh and 4dos! setopt nolistbeep # Don't beep on ambiguous completion setopt list_packed # Make completion lists smaller # Expansion and globbing #setopt extendedglob # Lots of cool extra wildcards # History setopt share_history # Continually read and write from history file setopt hist_ignore_dups # Do not add duplicate contiguous commands to history setopt hist_allow_clobber # Add '|' to output redirections in history setopt hist_reduce_blanks # Remove extra blanks from history entries #setopt nobanghist # No bang-history, thanks # Input/Output setopt noclobber # Require '!' after redirections to overwrite files setopt noflowcontrol # Disable ^S/^Q in editor setopt correct # Spell check commands setopt nomailwarning # Alert on new mail #setopt print_exit_value # Print non-zero exit values # Job control setopt autoresume # Resume existing jobs with bare command setopt nobgnice # Don't nice bg jobs # Zle (ZSH Line Editor) setopt nobeep # No beep on error ########################################################## # Misc limit core 0 # no core dumps umask 022 # default umask #cdpath=(.. ~) # make cd search other directories # Keep more than 1000 history items HISTSIZE=999999 SAVEHIST=$HISTSIZE # 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. function () { local hosts=(${${(f)"$(<~/.ssh/known_hosts)"//,/ }%%\ *}) zstyle ':completion:*:hosts' hosts $hosts } fi ########################################################## # Aliases alias whois='whois -h geektools.com' alias df='df -h' 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 ip='ip --color' alias ipb='ip --color --brief' alias dir='ls -lhga' alias du='du -h' alias ftp=ncftp alias mtr='mtr --curses' alias sysu='systemctl --user' alias fixssh='eval $(tmux showenv -s SSH_AUTH_SOCK)' # 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