From c381c0c531a78ff4b1a1907c10da4ff54a112f0a Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 30 Apr 2016 15:13:55 +0800 Subject: _zsh: simplify initialization; order by perfix --- _zsh/00-checks.zsh | 17 +++++++++ _zsh/10-setopt.zsh | 63 +++++++++++++++++++++++++++++++++ _zsh/20-colors.zsh | 27 ++++++++++++++ _zsh/30-prompt.zsh | 34 ++++++++++++++++++ _zsh/40-completion.zsh | 60 +++++++++++++++++++++++++++++++ _zsh/40-functions.zsh | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ _zsh/40-history.zsh | 12 +++++++ _zsh/40-hooks.zsh | 34 ++++++++++++++++++ _zsh/50-bindkeys.zsh | 24 +++++++++++++ _zsh/50-vi-mode.zsh | 53 ++++++++++++++++++++++++++++ _zsh/80-emacs.zsh | 37 ++++++++++++++++++++ _zsh/90-aliases.zsh | 31 ++++++++++++++++ _zsh/90-exports.zsh | 14 ++++++++ _zsh/aliases.zsh | 31 ---------------- _zsh/bindkeys.zsh | 24 ------------- _zsh/checks.zsh | 17 --------- _zsh/colors.zsh | 27 -------------- _zsh/completion.zsh | 60 ------------------------------- _zsh/emacs.zsh | 39 --------------------- _zsh/exports.zsh | 14 -------- _zsh/functions.zsh | 95 -------------------------------------------------- _zsh/history.zsh | 12 ------- _zsh/hooks.zsh | 34 ------------------ _zsh/prompt.zsh | 34 ------------------ _zsh/setopt.zsh | 63 --------------------------------- _zsh/vi-mode.zsh | 53 ---------------------------- _zshrc | 22 ++++-------- 27 files changed, 508 insertions(+), 518 deletions(-) create mode 100644 _zsh/00-checks.zsh create mode 100644 _zsh/10-setopt.zsh create mode 100644 _zsh/20-colors.zsh create mode 100644 _zsh/30-prompt.zsh create mode 100644 _zsh/40-completion.zsh create mode 100644 _zsh/40-functions.zsh create mode 100644 _zsh/40-history.zsh create mode 100644 _zsh/40-hooks.zsh create mode 100644 _zsh/50-bindkeys.zsh create mode 100644 _zsh/50-vi-mode.zsh create mode 100644 _zsh/80-emacs.zsh create mode 100644 _zsh/90-aliases.zsh create mode 100644 _zsh/90-exports.zsh delete mode 100644 _zsh/aliases.zsh delete mode 100644 _zsh/bindkeys.zsh delete mode 100644 _zsh/checks.zsh delete mode 100644 _zsh/colors.zsh delete mode 100644 _zsh/completion.zsh delete mode 100644 _zsh/emacs.zsh delete mode 100644 _zsh/exports.zsh delete mode 100644 _zsh/functions.zsh delete mode 100644 _zsh/history.zsh delete mode 100644 _zsh/hooks.zsh delete mode 100644 _zsh/prompt.zsh delete mode 100644 _zsh/setopt.zsh delete mode 100644 _zsh/vi-mode.zsh diff --git a/_zsh/00-checks.zsh b/_zsh/00-checks.zsh new file mode 100644 index 0000000..6868e2c --- /dev/null +++ b/_zsh/00-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/10-setopt.zsh b/_zsh/10-setopt.zsh new file mode 100644 index 0000000..fb8b5e8 --- /dev/null +++ b/_zsh/10-setopt.zsh @@ -0,0 +1,63 @@ +# +# zsh/setopt.zsh +# see man zshoptions(1) +# + +## Basics +setopt NO_BEEP +setopt AUTO_CD +# make cd push the old directory onto the directory stack +setopt AUTO_PUSHD +# 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 +# display PID when suspending processes as well +setopt LONG_LIST_JOBS + +## 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 +# * shouldn't match dotfiles. ever. +setopt NO_GLOB_DOTS +# 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/_zsh/20-colors.zsh b/_zsh/20-colors.zsh new file mode 100644 index 0000000..b9a4797 --- /dev/null +++ b/_zsh/20-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/30-prompt.zsh b/_zsh/30-prompt.zsh new file mode 100644 index 0000000..6c1911a --- /dev/null +++ b/_zsh/30-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)%{$fg_bold[red]%}%(?..[%?])${PR_BOLD_WHITE}>%{$reset_color%} ' + +SPROMPT="zsh: correct %{$fg_bold[red]%}%R%{$reset_color%} to %{$fg_bold[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/40-completion.zsh b/_zsh/40-completion.zsh new file mode 100644 index 0000000..7435125 --- /dev/null +++ b/_zsh/40-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/40-functions.zsh b/_zsh/40-functions.zsh new file mode 100644 index 0000000..46da01c --- /dev/null +++ b/_zsh/40-functions.zsh @@ -0,0 +1,95 @@ +# +# zsh/functions.zsh +# +# execute 'functions ' to show function details. +# + +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 + command 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 +function rule() { + printf "%$(tput cols)s\n" | tr ' ' '-' +} + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/40-history.zsh b/_zsh/40-history.zsh new file mode 100644 index 0000000..e1275a6 --- /dev/null +++ b/_zsh/40-history.zsh @@ -0,0 +1,12 @@ +# +# zsh/history.zsh +# + +HISTFILE=~/.zsh_history + +HISTSIZE=10000 +SAVEHIST=9000 +# ignore these commands without arguments +HISTIGNORE="cd:ls:ll" + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/40-hooks.zsh b/_zsh/40-hooks.zsh new file mode 100644 index 0000000..defee0b --- /dev/null +++ b/_zsh/40-hooks.zsh @@ -0,0 +1,34 @@ +# +# zsh/hooks.zsh +# + +# Put the string "hostname::/full/directory/path" in the title bar: +function set_term_title { + echo -ne "\e]2;$PWD\a" +} + +# Put the parentdir/currentdir in the tab +function set_term_tab { + echo -ne "\e]1;$PWD:h:t/$PWD:t\a" +} + +function precmd { + set_term_title + set_term_tab +} + + +#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/50-bindkeys.zsh b/_zsh/50-bindkeys.zsh new file mode 100644 index 0000000..c53d3bf --- /dev/null +++ b/_zsh/50-bindkeys.zsh @@ -0,0 +1,24 @@ +# +# 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 + +# see zshcontrib(1) +autoload -U select-word-style +# bash-style word killing: word characters are alphanumeric characters only +select-word-style bash + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/50-vi-mode.zsh b/_zsh/50-vi-mode.zsh new file mode 100644 index 0000000..d786102 --- /dev/null +++ b/_zsh/50-vi-mode.zsh @@ -0,0 +1,53 @@ +# +# zsh/vi-mode.zsh +# +# Credits: +# https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/vi-mode/vi-mode.plugin.zsh +# 2015-11-18 +# + +# Updates editor information when the keymap changes. +function zle-keymap-select() { + zle reset-prompt + zle -R +} + +# Ensure that the prompt is redrawn when the terminal size changes. +TRAPWINCH() { + zle && { zle reset-prompt; zle -R } +} + +zle -N zle-keymap-select +zle -N edit-command-line + + +bindkey -v + +# allow v to edit the command line (standard behaviour) +autoload -Uz edit-command-line +bindkey -M vicmd 'v' edit-command-line + +# allow ctrl-p, ctrl-n for navigate history (standard behaviour) +bindkey '^P' up-history +bindkey '^N' down-history + +# allow ctrl-h, ctrl-w, ctrl-? for char and word deletion (standard behaviour) +bindkey '^?' backward-delete-char +bindkey '^h' backward-delete-char +bindkey '^w' backward-kill-word + +# if mode indicator wasn't setup by theme, define default +if [[ "$MODE_INDICATOR" == "" ]]; then + MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}" +fi + +function vi_mode_prompt_info() { + echo "${${KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}" +} + +# define right prompt, if it wasn't defined by a theme +if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then + RPS1='$(vi_mode_prompt_info)' +fi + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/80-emacs.zsh b/_zsh/80-emacs.zsh new file mode 100644 index 0000000..501ddb2 --- /dev/null +++ b/_zsh/80-emacs.zsh @@ -0,0 +1,37 @@ +# +# zsh/emacs.zsh +# +# Credits: +# https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/emacs +# +# 2016-02-21 +# + +function _emacsclient() { + # Get list of available X windows. + X=`emacsclient --alternate-editor '' --eval '(x-display-list)' 2>/dev/null` + + if [ -z "$X" ] || [ "$X" = "nil" ]; then + # Create one if there is no X window yet. + command emacsclient --alternate-editor "" --create-frame "$@" + else + # Prevent creating another X frame if there is at least one present. + command emacsclient --alternate-editor "" "$@" + fi +} + +alias emacs='_emacsclient -t' +alias e=emacs +# Same as 'M-x eval' but outside of Emacs +alias eeval='_emacsclient --eval' +# Create a new X frame +alias eframe='_emacsclient --create-frame --no-wait' + +# Write to stdout the path to the file opened in the current buffer +function efile() { + local cmd="(buffer-file-name (window-buffer))" + _emacsclient --eval "$cmd" | tr -d '"' +} + + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/90-aliases.zsh b/_zsh/90-aliases.zsh new file mode 100644 index 0000000..1327721 --- /dev/null +++ b/_zsh/90-aliases.zsh @@ -0,0 +1,31 @@ +# +# zsh/aliases.zsh +# + +alias zhelp='run-help' + +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 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/90-exports.zsh b/_zsh/90-exports.zsh new file mode 100644 index 0000000..8dab42d --- /dev/null +++ b/_zsh/90-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/aliases.zsh b/_zsh/aliases.zsh deleted file mode 100644 index 1327721..0000000 --- a/_zsh/aliases.zsh +++ /dev/null @@ -1,31 +0,0 @@ -# -# zsh/aliases.zsh -# - -alias zhelp='run-help' - -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 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 deleted file mode 100644 index c53d3bf..0000000 --- a/_zsh/bindkeys.zsh +++ /dev/null @@ -1,24 +0,0 @@ -# -# 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 - -# see zshcontrib(1) -autoload -U select-word-style -# bash-style word killing: word characters are alphanumeric characters only -select-word-style bash - -# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/checks.zsh b/_zsh/checks.zsh deleted file mode 100644 index 6868e2c..0000000 --- a/_zsh/checks.zsh +++ /dev/null @@ -1,17 +0,0 @@ -# -# 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 deleted file mode 100644 index b9a4797..0000000 --- a/_zsh/colors.zsh +++ /dev/null @@ -1,27 +0,0 @@ -# -# 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 deleted file mode 100644 index 7435125..0000000 --- a/_zsh/completion.zsh +++ /dev/null @@ -1,60 +0,0 @@ -# -# 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/emacs.zsh b/_zsh/emacs.zsh deleted file mode 100644 index b1ace40..0000000 --- a/_zsh/emacs.zsh +++ /dev/null @@ -1,39 +0,0 @@ -# -# zsh/emacs.zsh -# -# Credits: -# https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/emacs -# -# 2016-02-21 -# - -function _emacsclient() { - # Get list of available X windows. - X=`emacsclient --alternate-editor '' --eval '(x-display-list)' 2>/dev/null` - - if [ -z "$X" ] || [ "$X" = "nil" ]; then - # Create one if there is no X window yet. - command emacsclient --alternate-editor "" --create-frame "$@" - else - # Prevent creating another X frame if there is at least one present. - command emacsclient --alternate-editor "" "$@" - fi -} - -alias emacs='_emacsclient -t' -alias e=emacs -# Same as 'M-x eval' but outside of Emacs -alias eeval='_emacsclient --eval' -# Create a new X frame -alias eframe='_emacsclient --create-frame --no-wait' -# mu4e -alias mu4e='eframe -e "(mu4e)" -F "((width . 100) (height . 40))"' - -# Write to stdout the path to the file opened in the current buffer -function efile() { - local cmd="(buffer-file-name (window-buffer))" - _emacsclient --eval "$cmd" | tr -d '"' -} - - -# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/exports.zsh b/_zsh/exports.zsh deleted file mode 100644 index 8dab42d..0000000 --- a/_zsh/exports.zsh +++ /dev/null @@ -1,14 +0,0 @@ -# -# 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 deleted file mode 100644 index 46da01c..0000000 --- a/_zsh/functions.zsh +++ /dev/null @@ -1,95 +0,0 @@ -# -# zsh/functions.zsh -# -# execute 'functions ' to show function details. -# - -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 - command 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 -function 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 deleted file mode 100644 index e1275a6..0000000 --- a/_zsh/history.zsh +++ /dev/null @@ -1,12 +0,0 @@ -# -# zsh/history.zsh -# - -HISTFILE=~/.zsh_history - -HISTSIZE=10000 -SAVEHIST=9000 -# ignore these commands without arguments -HISTIGNORE="cd:ls:ll" - -# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zsh/hooks.zsh b/_zsh/hooks.zsh deleted file mode 100644 index defee0b..0000000 --- a/_zsh/hooks.zsh +++ /dev/null @@ -1,34 +0,0 @@ -# -# zsh/hooks.zsh -# - -# Put the string "hostname::/full/directory/path" in the title bar: -function set_term_title { - echo -ne "\e]2;$PWD\a" -} - -# Put the parentdir/currentdir in the tab -function set_term_tab { - echo -ne "\e]1;$PWD:h:t/$PWD:t\a" -} - -function precmd { - set_term_title - set_term_tab -} - - -#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 deleted file mode 100644 index 6c1911a..0000000 --- a/_zsh/prompt.zsh +++ /dev/null @@ -1,34 +0,0 @@ -# -# 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)%{$fg_bold[red]%}%(?..[%?])${PR_BOLD_WHITE}>%{$reset_color%} ' - -SPROMPT="zsh: correct %{$fg_bold[red]%}%R%{$reset_color%} to %{$fg_bold[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 deleted file mode 100644 index fb8b5e8..0000000 --- a/_zsh/setopt.zsh +++ /dev/null @@ -1,63 +0,0 @@ -# -# zsh/setopt.zsh -# see man zshoptions(1) -# - -## Basics -setopt NO_BEEP -setopt AUTO_CD -# make cd push the old directory onto the directory stack -setopt AUTO_PUSHD -# 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 -# display PID when suspending processes as well -setopt LONG_LIST_JOBS - -## 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 -# * shouldn't match dotfiles. ever. -setopt NO_GLOB_DOTS -# 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/_zsh/vi-mode.zsh b/_zsh/vi-mode.zsh deleted file mode 100644 index d786102..0000000 --- a/_zsh/vi-mode.zsh +++ /dev/null @@ -1,53 +0,0 @@ -# -# zsh/vi-mode.zsh -# -# Credits: -# https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/vi-mode/vi-mode.plugin.zsh -# 2015-11-18 -# - -# Updates editor information when the keymap changes. -function zle-keymap-select() { - zle reset-prompt - zle -R -} - -# Ensure that the prompt is redrawn when the terminal size changes. -TRAPWINCH() { - zle && { zle reset-prompt; zle -R } -} - -zle -N zle-keymap-select -zle -N edit-command-line - - -bindkey -v - -# allow v to edit the command line (standard behaviour) -autoload -Uz edit-command-line -bindkey -M vicmd 'v' edit-command-line - -# allow ctrl-p, ctrl-n for navigate history (standard behaviour) -bindkey '^P' up-history -bindkey '^N' down-history - -# allow ctrl-h, ctrl-w, ctrl-? for char and word deletion (standard behaviour) -bindkey '^?' backward-delete-char -bindkey '^h' backward-delete-char -bindkey '^w' backward-kill-word - -# if mode indicator wasn't setup by theme, define default -if [[ "$MODE_INDICATOR" == "" ]]; then - MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}" -fi - -function vi_mode_prompt_info() { - echo "${${KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}" -} - -# define right prompt, if it wasn't defined by a theme -if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then - RPS1='$(vi_mode_prompt_info)' -fi - -# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # diff --git a/_zshrc b/_zshrc index bd07b7e..9b549c6 100644 --- a/_zshrc +++ b/_zshrc @@ -18,26 +18,18 @@ ## https://robots.thoughtbot.com/the-unix-shells-humble-if ## ## Aaron LI -## Created: 2014-05-31 +## 2014-05-31 ## -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/bindkeys.zsh -source ~/.zsh/functions.zsh -source ~/.zsh/history.zsh -source ~/.zsh/hooks.zsh -source ~/.zsh/vi-mode.zsh -source ~/.zsh/emacs.zsh -source ~/.zsh/aliases.zsh +for f in ~/.zsh/[0-9][0-9]-*.zsh; do + source ${f} +done ## Local configurations -[ -r ~/.zshrc.local ] && source ~/.zshrc.local || : +if [ -r ~/.zshrc.local ]; then + source ~/.zshrc.local +fi # vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # -- cgit v1.2.2