#=============================================================================== # # ~/.zshrc # Written by Minoru (eual.jp@gmail.com) # # DEPENDENCIES: # ~/.dir_colors # # zsh 4.3.10 # #=============================================================================== #------------------------------------------------------------------------------- # # HISTORY # # History file HISTFILE=~/.zhistory # The number of lines the shell will keep within one session HISTSIZE=10240 # The number of lines of history will be saved SAVEHIST=8192 # All running zsh sessions will have exactly the same history # Don't worry - '!' command and so will work only with current session's history setopt SHARE_HISTORY # Remove all duplicates of current command from history, add current to end setopt HIST_IGNORE_ALL_DUPS # Don't save any commands beginning with space setopt HIST_IGNORE_SPACE # Don't save 'history' and 'fc' commands setopt HIST_NO_STORE #------------------------------------------------------------------------------- # # PROMPT # # Load and initialize colors - we will use it soon autoload colors && colors # Prompt on the left is % if regular user or # if root PROMPT="%{$fg[green]%}%# %{$reset_color%}" # if connected via ssh, make prompt red [[ -n ${SSH_CONNECTION} ]] && PROMPT="%{$fg[red]%}%# %{$reset_color%}" # Prompt on the right is current directory (green font) RPROMPT="%{$fg[green]%}%~%{$reset_color%}" #------------------------------------------------------------------------------- # # ALIASES # # NOTE: if you don't want an alias to be used (for example, you went just 'du', # but alias is 'du -h') you have two ways: # - use full path to binaries (continuing example above, it will look like # '/bin/du') # - use 'noglob' before command name (e.g., 'noglob du') # Regular aliases alias ls="ls -lF --color" alias l="ls" alias sl="ls" alias lsa="ls -a" alias bzip2='bzip2 -vv --best' alias bunzip2='bunzip2 -vv' alias gzip='gzip --best -v' alias gunzip='gunzip -v' alias less='less -R' alias feh='feh -F' # Some nocorrect aliases (needed only if CORRECT is set) alias df='nocorrect df -h' alias du='nocorrect du -h' alias mv='nocorrect mv -i' alias cp='nocorrect cp -i' alias rm='nocorrect rm -i' alias vim='nocorrect vim' alias mc='nocorrect mc' alias mkdir='nocorrect mkdir -p' # You need run-help module to be loaded to have 'run-help' command # See MISCELLANEOUS section below alias help="run-help" # Some more complicated but still useful aliases # Start x; works only if user aren't root and command given from tty #alias x='if [[ $UID != 0 && $TERM == "linux" ]]; then rm -f ~/.xsession-errors; startx; else echo "You are not allowed to start X session"; fi' if [ "$TERM" = "linux" ]; then alias mplayer='mplayer -vo fbdev2' fi # Suffix aliases for easier files processing # PDF alias -s pdf=evince # FB 2.1 alias -s fb2=fbless alias -s fb2.bz2=fbless # DejaVu alias -s djvu=evince #------------------------------------------------------------------------------- # # FUNCTIONS # # This code will change terminal emulator's title # As far as this action makes sense only in X terminal (and screen, but I don't # use it), case used for checking are we in X terminal or where # NOTE: if we're in the tty, $TERM will be "linux" case $TERM in xterm* | rxvt*) # Precmd is called just before the prompt is printed precmd() { print -Pn "\e]0;zsh\a" } # Preexec is called just before any command line is executed # $1 is command name # sed used to cut off parameters of command preexec() { print -Pn "\e]0;`echo $1 | head -n1 | sed -r 's/^(sudo [^[:space:]]+|[^[:space:]]+).*/\1/'`\a" } # There are postexec too, but I don't need it as far as I configured precmd ;; esac function mcd() { # Create directory and cd to it mkdir -p "$1" && cd "$1" } function lcd() { # cd to directory and do ls cd "$1" && ls } #------------------------------------------------------------------------------- # # MISCELLANEOUS # # Don't beep even if zsh don't like something setopt NO_BEEP # Change directory even if user forgot to put 'cd' command in front, but entered # path is valid setopt AUTO_CD # If possible, correct commands setopt CORRECT # Colors for ls # When moving this to other machine, don't forget to keep ~/.dir_colors - some # interesting things there, such as black-at-white setting for showing names of # directories eval `dircolors ~/.dir_colors` zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} # Making things like "{1-3}" and "{a-d}" working (it expands to "1 2 3" and "a b # c d") setopt BRACECCL # All files created by zsh (it happens when you use redirection of command's # output to non-existent file) will have ug+rwX,o-rwx (or 750 for directories # and 640 for files) perrmissions umask 0027 # Load help system, which can show parts of man pages where specified command # described. Also, add help="run-help" alias (see above in ALIASES section) autoload run-help # key bindings # needed when connected by ssh, don't hurt if you're connected locally bindkey "\e[1~" beginning-of-line bindkey "\e[4~" end-of-line bindkey "\e[5~" beginning-of-history bindkey "\e[6~" end-of-history bindkey "\e[3~" delete-char #bindkey "\e[2~" quoted-insert bindkey "\e[5C" forward-word bindkey "\e[5D" backward-word bindkey "\e\e[C" forward-word # for urxvt bindkey "\e[8~" end-of-line bindkey "\e[7~" beginning-of-line #------------------------------------------------------------------------------- # # COMPLETION # # Sets autocompletion autoload -Uz compinit && compinit