From 1a80abd95d93db9e0a3b0646bd346ee9e6a5fcd5 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 30 Jan 2016 16:45:56 +0800 Subject: Rip out the heavy oh-my-zsh ... Credits: [1] https://github.com/spicycode/ze-best-zsh-config [2] Zsh Configuration from the Ground Up http://zanshin.net/2013/02/02/zsh-configuration-from-the-ground-up/ --- _zsh/aliases.zsh | 32 ++++++++++++++++++ _zsh/bindkeys.zsh | 25 ++++++++++++++ _zsh/checks.zsh | 17 ++++++++++ _zsh/colors.zsh | 27 ++++++++++++++++ _zsh/completion.zsh | 60 ++++++++++++++++++++++++++++++++++ _zsh/exports.zsh | 14 ++++++++ _zsh/functions.zsh | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ _zsh/history.zsh | 10 ++++++ _zsh/hooks.zsh | 28 ++++++++++++++++ _zsh/prompt.zsh | 34 ++++++++++++++++++++ _zsh/setopt.zsh | 56 ++++++++++++++++++++++++++++++++ _zshrc | 89 ++++++++++++-------------------------------------- _zshrc.local | 28 ++-------------- 13 files changed, 419 insertions(+), 94 deletions(-) create mode 100644 _zsh/aliases.zsh create mode 100644 _zsh/bindkeys.zsh create mode 100644 _zsh/checks.zsh create mode 100644 _zsh/colors.zsh create mode 100644 _zsh/completion.zsh create mode 100644 _zsh/exports.zsh create mode 100644 _zsh/functions.zsh create mode 100644 _zsh/history.zsh create mode 100644 _zsh/hooks.zsh create mode 100644 _zsh/prompt.zsh create mode 100644 _zsh/setopt.zsh diff --git a/_zsh/aliases.zsh b/_zsh/aliases.zsh new file mode 100644 index 0000000..7b1b26f --- /dev/null +++ b/_zsh/aliases.zsh @@ -0,0 +1,32 @@ +# +# zsh/aliases.zsh +# + +alias ..='cd ../' +alias ...='cd ../../' +alias ....='cd ../../../' +alias cd..='cd ..' +alias d='dirs -v | head -10' +alias po=popd +alias pu=pushd + +#alias history='fc -l 1' + +alias ls='ls --color=auto' +alias l='ls -lah' +alias la='ls -lAh' +alias ll='ls -lh' +alias lsa='ls -lah' + +alias grep='grep --color=auto' + +alias e='emacs' +alias v='vim' + +alias ta='tmux attach -t' +alias tl='tmux list-sessions' +alias ts='tmux new-session -s' +alias tkss='tmux kill-session -t' +alias tksv='tmux kill-server' + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/bindkeys.zsh b/_zsh/bindkeys.zsh new file mode 100644 index 0000000..781d260 --- /dev/null +++ b/_zsh/bindkeys.zsh @@ -0,0 +1,25 @@ +# +# zsh/bindkeys.zsh +# +# To see the key combo you want to use just do: +# cat > /dev/null +# And press it +# + +bindkey "^K" kill-whole-line # ctrl-k +bindkey "^R" history-incremental-search-backward # ctrl-r +bindkey "^A" beginning-of-line # ctrl-a +bindkey "^E" end-of-line # ctrl-e +bindkey "[B" history-search-forward # down arrow +bindkey "[A" history-search-backward # up arrow +bindkey "^D" delete-char # ctrl-d +bindkey "^F" forward-char # ctrl-f +bindkey "^B" backward-char # ctrl-b +bindkey '^P' up-history +bindkey '^N' down-history +bindkey '^W' backward-kill-word + +## vi mode +bindkey -v + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/checks.zsh b/_zsh/checks.zsh new file mode 100644 index 0000000..6868e2c --- /dev/null +++ b/_zsh/checks.zsh @@ -0,0 +1,17 @@ +# +# zsh/checks.zsh +# +# Credits: http://zanshin.net/2013/02/02/zsh-configuration-from-the-ground-up/ +# + +if [[ $(uname) = 'Linux' ]]; then + IS_LINUX=1 +elif [[ $(uname) = 'FreeBSD' ]]; then + IS_FREEBSD=1 + IS_BSD=1 +elif [[ $(uname) = 'DragonFly' ]]; then + IS_DRAGONFLY=1 + IS_BSD=1 +fi + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/colors.zsh b/_zsh/colors.zsh new file mode 100644 index 0000000..b9a4797 --- /dev/null +++ b/_zsh/colors.zsh @@ -0,0 +1,27 @@ +# +# zsh/colors.sh +# + +autoload -U colors && colors + +# The variables are wrapped in %{%}. This should be the case for every +# variable that does not contain space. +for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do + eval PR_$COLOR='%{$fg_no_bold[${(L)COLOR}]%}' + eval PR_BOLD_$COLOR='%{$fg_bold[${(L)COLOR}]%}' +done + +eval RESET='$reset_color' +export PR_RED PR_GREEN PR_YELLOW PR_BLUE PR_WHITE PR_BLACK +export PR_BOLD_RED PR_BOLD_GREEN PR_BOLD_YELLOW PR_BOLD_BLUE +export PR_BOLD_WHITE PR_BOLD_BLACK + +# colors for BSD ls +if [[ -n "${IS_BSD}" ]]; then + export CLICOLOR=1 + #export LSCOLORS=Gxfxcxdxbxegedabagacad + export LSCOLORS=exfxcxdxbxegedabagacad +fi + + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/completion.zsh b/_zsh/completion.zsh new file mode 100644 index 0000000..7435125 --- /dev/null +++ b/_zsh/completion.zsh @@ -0,0 +1,60 @@ +# +# zsh/completion.zsh +# + +autoload -U compinit && compinit +zmodload -i zsh/complist + +# man zshcontrib +zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f ' +zstyle ':vcs_info:*' formats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f ' +zstyle ':vcs_info:*' enable git #svn cvs + +# enable completion caching, use rehash to clear +zstyle ':completion::complete:*' use-cache on +zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST + +# fallback to built in ls colors +zstyle ':completion:*' list-colors '' + +# make the list prompt friendly +zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s' + +# make the selection prompt friendly when there are a lot of choices +zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s' + +# add simple colors to kill +zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' + +# list of completers to use +zstyle ':completion:*::::' completer _expand _complete _ignored _approximate + +zstyle ':completion:*' menu select=1 _complete _ignored _approximate + +# insert all expansions for expand completer +#zstyle ':completion:*:expand:*' tag-order all-expansions + +# match uppercase from lowercase +zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' + +# offer indexes before parameters in subscripts +zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters + +# formatting and messages +zstyle ':completion:*' verbose yes +zstyle ':completion:*:descriptions' format '%B%d%b' +zstyle ':completion:*:messages' format '%d' +zstyle ':completion:*:warnings' format 'No matches for: %d' +zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b' +zstyle ':completion:*' group-name '' + +# ignore completion functions (until the _ignored completer) +zstyle ':completion:*:functions' ignored-patterns '_*' +zstyle ':completion:*:scp:*' tag-order files users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *' +zstyle ':completion:*:scp:*' group-order files all-files users hosts-domain hosts-host hosts-ipaddr +zstyle ':completion:*:ssh:*' tag-order users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *' +zstyle ':completion:*:ssh:*' group-order hosts-domain hosts-host users hosts-ipaddr +zstyle '*' single-ignored show + + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/exports.zsh b/_zsh/exports.zsh new file mode 100644 index 0000000..8dab42d --- /dev/null +++ b/_zsh/exports.zsh @@ -0,0 +1,14 @@ +# +# zsh/exports.zsh +# + +# set locale and PATH in '~/.profile' + +export EDITOR='vim' +export PAGER='less' +export LESS='--ignore-case --raw-control-chars' + +# Setup terminal, and turn on colors +export TERM='xterm-256color' + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/functions.zsh b/_zsh/functions.zsh new file mode 100644 index 0000000..9b817c1 --- /dev/null +++ b/_zsh/functions.zsh @@ -0,0 +1,93 @@ +# +# zsh/functions.zsh +# + +function zsh_recompile { + autoload -U zrecompile + rm -f ~/.zsh/*.zwc + [[ -f ~/.zshrc ]] && zrecompile -p ~/.zshrc + [[ -f ~/.zshrc.zwc.old ]] && rm -f ~/.zshrc.zwc.old + + for f in ~/.zsh/**/*.zsh; do + [[ -f $f ]] && zrecompile -p $f + [[ -f $f.zwc.old ]] && rm -f $f.zwc.old + done + + [[ -f ~/.zcompdump ]] && zrecompile -p ~/.zcompdump + [[ -f ~/.zcompdump.zwc.old ]] && rm -f ~/.zcompdump.zwc.old + + source ~/.zshrc +} + + +function extract { + echo Extracting $1 ... + if [ -f "$1" ] ; then + case "$1" in + *.tar.bz2) + tar xjf "$1";; + *.tar.gz) + tar xzf "$1";; + *.bz2) + bunzip2 "$1";; + *.rar) + unrar x "$1";; + *.gz) + gunzip "$1";; + *.tar) + tar xf "$1";; + *.tbz2) + tar xjf "$1";; + *.tgz) + tar xzf "$1";; + *.zip) + unzip "$1";; + *.Z) + uncompress "$1";; + *.7z) + 7z x "$1";; + *) + echo "'$1' cannot be extracted via extract()" ;; + esac + else + echo "'$1' is not a valid file" + fi +} + + +function trash () { + local path + for path in "$@"; do + # ignore any arguments + if [[ "${path}" = -* ]]; then + : + else + local dst="${path##*/}" + # append the time if necessary + while [ -e ~/.trash/"${dst}" ]; do + dst="${dst} "$(date +%H-%M-%S) + done + \mv "${path}" ~/.trash/"${dst}" + fi + done +} + + +function strip_diff_leading_symbols { + local color_code_regex="(\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K])" + + # simplify the unified patch diff header + sed -r "s/^($color_code_regex)diff --git .*$//g" | \ + sed -r "s/^($color_code_regex)index .*$/\n\1$(rule)/g" | \ + sed -r "s/^($color_code_regex)\+\+\+(.*)$/\1+++\5\n\1$(rule)\x1B\[m/g" |\ + # actually strips the leading symbols + sed -r "s/^($color_code_regex)[\+\-]/\1 /g" +} + + +## Print a horizontal rule +rule() { + printf "%$(tput cols)s\n" | tr ' ' '─' +} + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/history.zsh b/_zsh/history.zsh new file mode 100644 index 0000000..dd7997e --- /dev/null +++ b/_zsh/history.zsh @@ -0,0 +1,10 @@ +# +# zsh/history.zsh +# + +# history settings +HISTSIZE=10000 +SAVEHIST=9000 +HISTFILE=~/.zsh_history + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/hooks.zsh b/_zsh/hooks.zsh new file mode 100644 index 0000000..9e18053 --- /dev/null +++ b/_zsh/hooks.zsh @@ -0,0 +1,28 @@ +# +# zsh/hooks.zsh +# + +function precmd { + # vcs_info + # Put the string "hostname::/full/directory/path" in the title bar: + echo -ne "\e]2;$PWD\a" + + # Put the parentdir/currentdir in the tab + echo -ne "\e]1;$PWD:h:t/$PWD:t\a" +} + + +function set_running_app { + printf "\e]1; $PWD:t:$(history $HISTCMD | cut -b7- ) \a" +} + +function preexec { + set_running_app +} + +function postexec { + set_running_app +} + + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/prompt.zsh b/_zsh/prompt.zsh new file mode 100644 index 0000000..f1f581a --- /dev/null +++ b/_zsh/prompt.zsh @@ -0,0 +1,34 @@ +# +# zsh/prompt.zsh +# + +function git_prompt_info { + local ref=$(=git symbolic-ref HEAD 2> /dev/null) + local gitst="$(=git status 2> /dev/null)" + + if [[ -f .git/MERGE_HEAD ]]; then + if [[ ${gitst} =~ "unmerged" ]]; then + gitstatus=" %{$fg[red]%}unmerged%{$reset_color%}" + else + gitstatus=" %{$fg[green]%}merged%{$reset_color%}" + fi + elif [[ ${gitst} =~ "Changes to be committed" ]]; then + gitstatus=" %{$fg[blue]%}!%{$reset_color%}" + elif [[ ${gitst} =~ "use \"git add" ]]; then + gitstatus=" %{$fg[red]%}!%{$reset_color%}" + elif [[ -n `git checkout HEAD 2> /dev/null | grep ahead` ]]; then + gitstatus=" %{$fg[yellow]%}*%{$reset_color%}" + else + gitstatus='' + fi + + if [[ -n $ref ]]; then + echo "%{$fg_bold[green]%}/${ref#refs/heads/}%{$reset_color%}$gitstatus" + fi +} + +PROMPT='%{$fg_bold[blue]%}%~%<< $(git_prompt_info)${PR_BOLD_WHITE}>%{${reset_color}%} ' + +SPROMPT="zsh: correct $fg[red]%R$reset_color to $fg[green]%r$reset_color [(y)es (n)o (a)bort (e)dit]? " + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/setopt.zsh b/_zsh/setopt.zsh new file mode 100644 index 0000000..f80fda6 --- /dev/null +++ b/_zsh/setopt.zsh @@ -0,0 +1,56 @@ +# +# zsh/setopt.zsh +# + +## Basics +setopt NO_BEEP +setopt AUTO_CD +# don't push multiple copies of the same directory into the directory stack +setopt PUSHD_IGNORE_DUPS +# treat #, ~, and ^ as part of patterns for filename generation +setopt EXTENDED_GLOB +# allow comments even in interactive shells (especially for Muness) +setopt INTERACTIVE_COMMENTS + +## History +# allow multiple terminal sessions to all append to one zsh command history +setopt APPEND_HISTORY +# include timestamp of command and duration to history +setopt EXTENDED_HISTORY +# add comamnds as they are typed, don't wait until shell exit +setopt INC_APPEND_HISTORY +# do not write events to history that are duplicates of previous events +setopt HIST_IGNORE_DUPS +# remove command line from history list when it begins a space +setopt HIST_IGNORE_SPACE +# when searching history don't display results already cycled through twice +setopt HIST_FIND_NO_DUPS +# remove extra blanks from each command line being added to history +setopt HIST_REDUCE_BLANKS +# don't execute, just expand history +setopt HIST_VERIFY + + +## Completion +# allow completion from within a word/phrase +setopt COMPLETE_IN_WORD +# when completing from middle of a word, move cursor to the end of the word +setopt ALWAYS_TO_END +# show completion menu on successive tab press (needs 'unsetopt MENU_COMPLETE') +setopt AUTO_MENU +unsetopt MENU_COMPLETE + +## Correction +# spelling correction for commands +setopt CORRECT +# spelling correction for arguments +setopt CORRECTALL + +## Prompt +# enable parameter expansion, command substitution, and arithmetic expansion +# in the prompt +setopt PROMPT_SUBST +# remove any right prompt from display when accepting a command line +setopt TRANSIENT_RPROMPT + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zshrc b/_zshrc index 8aa8ffd..d2dd537 100644 --- a/_zshrc +++ b/_zshrc @@ -3,83 +3,34 @@ ## ZSH configuration file ## oh-my-zsh: http://ohmyz.sh/ ## -## Zsh reads this file in all interactive shells, whether they are +## ZSH reads this file in all interactive shells, whether they are ## login shells or not. ## +## Credits: +## [1] https://github.com/spicycode/ze-best-zsh-config +## [2] Zsh Configuration from the Ground Up +## http://zanshin.net/2013/02/02/zsh-configuration-from-the-ground-up/ +## ## Aaron LI ## Created: 2014-05-31 -## Updated: 2016-01-26 +## Updated: 2016-01-30 ## -# Path to your oh-my-zsh installation. -export ZSH=$HOME/.oh-my-zsh - -# Set name of the theme to load. -# Look in ~/.oh-my-zsh/themes/ -# Optionally, if you set this to "random", it'll load a random theme each -# time that oh-my-zsh is loaded. -#ZSH_THEME="robbyrussell" -ZSH_THEME="gentoo" - -# Uncomment the following line to use case-sensitive completion. -# CASE_SENSITIVE="true" - -# Uncomment the following line to disable bi-weekly auto-update checks. -DISABLE_AUTO_UPDATE="true" - -# Uncomment the following line to change how often to auto-update (in days). -# export UPDATE_ZSH_DAYS=13 - -# Uncomment the following line to disable colors in ls. -# DISABLE_LS_COLORS="true" - -# Uncomment the following line to disable auto-setting terminal title. -# DISABLE_AUTO_TITLE="true" - -# Uncomment the following line to disable command auto-correction. -# DISABLE_CORRECTION="true" - -# Uncomment the following line to display red dots whilst waiting for completion. -# COMPLETION_WAITING_DOTS="true" - -# Uncomment the following line if you want to disable marking untracked files -# under VCS as dirty. This makes repository status check for large repositories -# much, much faster. -# DISABLE_UNTRACKED_FILES_DIRTY="true" - -# Uncomment the following line if you want to change the command execution time -# stamp shown in the history command output. -# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" -# HIST_STAMPS="mm/dd/yyyy" - -# Would you like to use another custom folder than $ZSH/custom? -# ZSH_CUSTOM=/path/to/new-custom-folder - -# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) -# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ -# Example format: plugins=(rails git textmate ruby lighthouse) -#plugins=(fasd git suse tmux vi-mode) -plugins=(fasd git tmux vi-mode) - -source $ZSH/oh-my-zsh.sh - - -### aliases -alias e='emacs' -alias v='vim' - -### Preferred editor for local and remote sessions -if [ -n $SSH_CONNECTION ]; then - export EDITOR='vim' -else - export EDITOR='vim' -fi +source ~/.zsh/checks.zsh +source ~/.zsh/colors.zsh +source ~/.zsh/setopt.zsh +source ~/.zsh/exports.zsh +source ~/.zsh/prompt.zsh +source ~/.zsh/completion.zsh +source ~/.zsh/aliases.zsh +source ~/.zsh/bindkeys.zsh +source ~/.zsh/functions.zsh +source ~/.zsh/history.zsh +source ~/.zsh/hooks.zsh +## Local configurations +[ -r ~/.zshrc.local ] && source ~/.zshrc.local -### Local configurations -if [ -r ~/.zshrc.local ]; then - source ~/.zshrc.local -fi # vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zshrc.local b/_zshrc.local index addfa6b..06d3411 100644 --- a/_zshrc.local +++ b/_zshrc.local @@ -4,30 +4,9 @@ ## ## Aaron LI ## Created: 2014-05-31 -## Updated: 2016-01-27 +## Updated: 2016-01-30 ## -### vi mode {{{ -# oh-my-zsh: plugin: vi-mode -# Vim's text-objects-ish for zsh: https://github.com/hchbaw/opp.zsh - -#bindkey -v -# Reduce delay to 0.1 seconds -export KEYTIMEOUT=1 -## Key Bindings -# Use vim cli mode -bindkey '^P' up-history -bindkey '^N' down-history -# backspace and ^h working even after -# returning from command mode -bindkey '^?' backward-delete-char -bindkey '^h' backward-delete-char -# ctrl-w removed word backwards -bindkey '^w' backward-kill-word -# ctrl-r starts searching history backward -bindkey '^r' history-incremental-search-backward -### vi mode }}} - ### python-virtualenv {{{ if [ -x /usr/bin/virtualenvwrapper.sh ]; then export WORKON_HOME="$HOME/.virtualenvs" @@ -77,9 +56,7 @@ function ciaoinit() { ## chandra_acis_process scripts export MASS_PROFILE_DIR="$HOME/bin/mass" export CHANDRA_SCRIPT_DIR="$HOME/bin" -### astro }}} -### aliases {{{ alias qmass='qdp summary_mass_profile.qdp' alias qnfw='qdp nfw_fit_center.qdp' alias qsbp='qdp sbp_fit_center.qdp' @@ -92,6 +69,7 @@ alias calclxfx="${MASS_PROFILE_DIR}/calc_lxfx_simple.sh" alias getlxfx="${MASS_PROFILE_DIR}/get_lxfx_data.sh" alias chcld="${CHANDRA_SCRIPT_DIR}/chandra_collect_data_v3.sh" alias chr500="${CHANDRA_SCRIPT_DIR}/ciao_r500avgt_v3.sh" -### aliases }}} +### astro }}} + # vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # -- cgit v1.2.2