1 | ####################################################### |
---|
2 | ####### Arch ZSH ONF's configuration file ####### |
---|
3 | ####################################################### |
---|
4 | |
---|
5 | ###### References |
---|
6 | ## http://zsh.sourceforge.net/ |
---|
7 | ## https://grml.org/zsh/ |
---|
8 | ## https://github.com/robbyrussell/oh-my-zsh |
---|
9 | ## https://github.com/git/git/tree/master/contrib/completion |
---|
10 | ### https://github.com/meskarune/dotfiles |
---|
11 | ### https://github.com/olivierverdier/zsh-git-prompt |
---|
12 | #### https://github.com/Chrysostomus/manjaro-zsh-config |
---|
13 | |
---|
14 | ###### |
---|
15 | |
---|
16 | ### Set/unset ZSH options |
---|
17 | ######################## |
---|
18 | |
---|
19 | ### Shell |
---|
20 | setopt auto_cd # if a command is issued that can't be executed as a normal command, and the command is the name of a directory, perform the cd command to that directory |
---|
21 | setopt autolist # Automatically list choices on an ambiguous completion |
---|
22 | setopt autoparamslash # If a parameter is completed whose content is the name of a directory, then add a trailing slash instead of a space |
---|
23 | setopt cdable_vars # If the argument to a cd command (or an implied cd with the AUTO_CD option set) is not a directory, and does not begin with a slash, try to expand the expression as if it were preceded by a ‘~’ (see Filename Expansion). |
---|
24 | setopt nobeep # Avoid "beep"ing |
---|
25 | setopt nohup # Don't send SIGHUP to background processes when the shell exits (Don't kill processes when exiting) |
---|
26 | |
---|
27 | setopt unset # don't error out when unset parameters are used |
---|
28 | |
---|
29 | #### Correction |
---|
30 | setopt correct # Try to correct the spelling of commands. Note that, this may falsely report spelling errors the first time some commands are used |
---|
31 | setopt correctall # correct_all: Try to correct the spelling of all arguments in a line |
---|
32 | |
---|
33 | setopt menu_complete |
---|
34 | |
---|
35 | #### HISTORY |
---|
36 | setopt append_history # append history list to the history file: Immediately append history instead of overwriting |
---|
37 | setopt histignorealldups # If a new command line being added to the history list duplicates an older one, the older command is removed from the list |
---|
38 | setopt histignorespace # remove command lines from the history list when the first character on the line is a space |
---|
39 | setopt inc_append_history share_history # import new commands from the history file also in other zsh-session |
---|
40 | |
---|
41 | |
---|
42 | setopt extended_glob # Extended globbing. Allows using regular expressions with * |
---|
43 | setopt nocaseglob # Case insensitive globbing |
---|
44 | |
---|
45 | setopt prompt_subst # enable substitution for prompt |
---|
46 | |
---|
47 | ### Autoload zsh modules when they are referenced |
---|
48 | ################################################# |
---|
49 | autoload -U colors |
---|
50 | autoload -U compinit |
---|
51 | autoload -U history-search-end |
---|
52 | zle -N history-beginning-search-backward-end history-search-end |
---|
53 | zle -N history-beginning-search-forward-end history-search-end |
---|
54 | |
---|
55 | ### Reference modules |
---|
56 | ############### |
---|
57 | colors # Enable color support |
---|
58 | compinit -d # The "-d" flag speeds up the completion system using a ".zcompdump" file. |
---|
59 | |
---|
60 | ### Set variables |
---|
61 | ################# |
---|
62 | PATH="/usr/local/bin:/usr/local/sbin/:$PATH" |
---|
63 | HISTFILE=~/.zhistory |
---|
64 | HISTSIZE=1000 |
---|
65 | SAVEHIST=1000 |
---|
66 | LS_COLORS='rs=0:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:fi=96:'; |
---|
67 | export EDITOR=/usr/bin/nano |
---|
68 | export VISUAL=/usr/bin/nano |
---|
69 | export LS_COLORS |
---|
70 | |
---|
71 | ### Set alias |
---|
72 | ############# |
---|
73 | alias ls='ls --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F' |
---|
74 | alias ll='ls -l' |
---|
75 | alias la='ls -lha' |
---|
76 | alias Z='source ~/.zshrc' |
---|
77 | alias cp="cp -i" # Confirm before overwriting something |
---|
78 | alias df='df -h' # Human-readable sizes |
---|
79 | alias free='free -m' # Show sizes in MB |
---|
80 | alias x='startx ~/.xinitrc' # Type name of desired desktop after x, xinitrc is configured for it |
---|
81 | alias cpz='cp /media/sf_SharedVM/zshcomparison/.zshrc ~/.zshrc' |
---|
82 | alias grep='grep --color=tty -d skip' |
---|
83 | |
---|
84 | ### Bind keys |
---|
85 | ############# |
---|
86 | bindkey "^?" backward-delete-char |
---|
87 | bindkey '^[OH' beginning-of-line |
---|
88 | bindkey '^[OF' end-of-line |
---|
89 | bindkey '^[[5~' up-line-or-history |
---|
90 | bindkey '^[[6~' down-line-or-history |
---|
91 | bindkey "^[[A" history-beginning-search-backward-end #Up arrow |
---|
92 | bindkey "^[[B" history-beginning-search-forward-end #Down arrow |
---|
93 | bindkey "^r" history-incremental-search-backward |
---|
94 | bindkey ' ' magic-space # also do history expansion on space |
---|
95 | bindkey '^I' complete-word # complete on tab, leave expansion to _expand |
---|
96 | |
---|
97 | ### Set prompt |
---|
98 | ################# |
---|
99 | echo $(uname -srm) $(lsb_release -rs) # Print some system information when the shell is first started |
---|
100 | |
---|
101 | # Prompt with different colors for root |
---|
102 | PROMPT="%(!.[%{$fg[red]%}%n %{$fg[cyan]%}%(4~|%-1~/.../%2~|%~)%{$reset_color%}]# .[%{$fg[green]%}%n %{$fg[cyan]%}%(4~|%-1~/.../%2~|%~)%{$reset_color%}]$ " |
---|
103 | |
---|
104 | ### Set completion |
---|
105 | ############# |
---|
106 | # list of completers to use |
---|
107 | zstyle ':completion:*::::' completer _oldlist _expand _complete _files _ignored _approximate |
---|
108 | |
---|
109 | # formatting and messages |
---|
110 | zstyle ':completion:*' verbose yes |
---|
111 | |
---|
112 | zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}' |
---|
113 | zstyle ':completion:*:messages' format '%d' |
---|
114 | zstyle ':completion:*:warnings' format 'No matches for: %d' |
---|
115 | zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}' |
---|
116 | |
---|
117 | # separate matches into groups |
---|
118 | zstyle ':completion:*:matches' group 'yes' |
---|
119 | zstyle ':completion:*' group-name '' |
---|
120 | |
---|
121 | zstyle ':completion:*' menu select _complete _ignored _approximate # activate menu for selection |
---|
122 | |
---|
123 | zstyle -e ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )' # allow one error for every three characters typed in approximate completer |
---|
124 | |
---|
125 | zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' # Case insensitive tab completion |
---|
126 | zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" # Colored completion (different colors for dirs/files/etc) |
---|
127 | zstyle ':completion:*' rehash true # automatically find new executables in path |
---|
128 | zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST |
---|
129 | zstyle ':completion::complete:*' use-cache on |
---|
130 | |
---|
131 | # Process management |
---|
132 | zstyle ':completion:*:processes' command 'ps -au$USER' #on processes completion complete all user processes |
---|
133 | zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq' # Provide more processes in completion of programs like killall: |
---|
134 | zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' ## add colors to processes for kill completion |
---|
135 | |
---|
136 | |
---|
137 | # Search path for sudo completion |
---|
138 | zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \ |
---|
139 | /usr/local/bin \ |
---|
140 | /usr/sbin \ |
---|
141 | /usr/bin \ |
---|
142 | /sbin \ |
---|
143 | /bin |
---|
144 | |
---|
145 | ### Color man pages |
---|
146 | ############# |
---|
147 | export LESS_TERMCAP_mb=$'\E[01;32m' |
---|
148 | export LESS_TERMCAP_md=$'\E[01;32m' |
---|
149 | export LESS_TERMCAP_me=$'\E[0m' |
---|
150 | export LESS_TERMCAP_se=$'\E[0m' |
---|
151 | export LESS_TERMCAP_so=$'\E[01;47;34m' |
---|
152 | export LESS_TERMCAP_ue=$'\E[0m' |
---|
153 | export LESS_TERMCAP_us=$'\E[01;36m' |
---|
154 | export LESS=-r |
---|
155 | |
---|
156 | ### GIT management |
---|
157 | ############# |
---|
158 | |
---|
159 | # Modify the colors and symbols in these variables as desired. |
---|
160 | GIT_PROMPT_PREFIX="%{$fg[green]%}[%{$reset_color%}" |
---|
161 | GIT_PROMPT_SUFFIX="%{$fg[green]%}]%{$reset_color%}" |
---|
162 | GIT_PROMPT_AHEAD="%{$fg[red]%}ANUM%{$reset_color%}" # A"NUM" - ahead by "NUM" commits |
---|
163 | GIT_PROMPT_BEHIND="%{$fg[cyan]%}BNUM%{$reset_color%}" # B"NUM" - behind by "NUM" commits |
---|
164 | if [[ ${TERM} == "linux" ]]; then |
---|
165 | GIT_PROMPT_SYMBOL="%{$fg[cyan]%}C" # plus/minus - clean repo |
---|
166 | GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}Y︎%{$reset_color%}" # lightning bolt - merge conflict |
---|
167 | GIT_PROMPT_UNTRACKED="%{$fg_bold[yellow]%}+%{$reset_color%}" # red circle - untracked files |
---|
168 | GIT_PROMPT_MODIFIED="%{$fg_bold[red]%}!%{$reset_color%}" # yellow circle - modified files (which are tracked) |
---|
169 | GIT_PROMPT_STAGED="%{$fg_bold[green]%}=%{$reset_color%}" # green circle - staged changes present = ready for "git push" |
---|
170 | else |
---|
171 | GIT_PROMPT_SYMBOL="%{$fg[cyan]%}⎇" # plus/minus - clean repo |
---|
172 | GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}🜉%{$reset_color%}" # lightning bolt - merge conflict |
---|
173 | GIT_PROMPT_UNTRACKED="%{$fg_bold[yellow]%}✗%{$reset_color%}" # red circle - untracked files |
---|
174 | GIT_PROMPT_MODIFIED="%{$fg_bold[red]%}●%{$reset_color%}" # yellow circle - modified files (which are tracked) |
---|
175 | GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}" # green circle - staged changes present = ready for "git push" |
---|
176 | fi |
---|
177 | |
---|
178 | parse_git_branch() { |
---|
179 | # Show Git branch/tag, or name-rev if on detached head |
---|
180 | ( git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD ) 2> /dev/null |
---|
181 | } |
---|
182 | |
---|
183 | parse_git_state() { |
---|
184 | # Show different symbols as appropriate for various Git repository states |
---|
185 | # Compose this value via multiple conditional appends. |
---|
186 | local GIT_STATE="" |
---|
187 | local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')" |
---|
188 | if [ "$NUM_AHEAD" -gt 0 ]; then |
---|
189 | GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD} |
---|
190 | fi |
---|
191 | local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')" |
---|
192 | if [ "$NUM_BEHIND" -gt 0 ]; then |
---|
193 | GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND} |
---|
194 | fi |
---|
195 | local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)" |
---|
196 | if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then |
---|
197 | GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING |
---|
198 | fi |
---|
199 | if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then |
---|
200 | GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED |
---|
201 | fi |
---|
202 | if ! git diff --quiet 2> /dev/null; then |
---|
203 | GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED |
---|
204 | fi |
---|
205 | if ! git diff --cached --quiet 2> /dev/null; then |
---|
206 | GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED |
---|
207 | fi |
---|
208 | if [[ -n $GIT_STATE ]]; then |
---|
209 | echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX" |
---|
210 | fi |
---|
211 | } |
---|
212 | |
---|
213 | git_prompt_string() { |
---|
214 | local git_where="$(parse_git_branch)" |
---|
215 | |
---|
216 | # If inside a Git repository, print its branch and state |
---|
217 | [ -n "$git_where" ] && echo "$GIT_PROMPT_SYMBOL$(parse_git_state)$GIT_PROMPT_PREFIX%{$fg[yellow]%}${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX" |
---|
218 | |
---|
219 | # If not inside the Git repo, print exit codes of last command (only if it failed) |
---|
220 | [ ! -n "$git_where" ] && echo "%{$fg[red]%} %(?..[%?])" |
---|
221 | } |
---|
222 | |
---|
223 | ### Display right promp with git info if in a git folder |
---|
224 | ############# |
---|
225 | RPROMPT='$(git_prompt_string)%{$fg_bold[yellow]%}(%D{%d-%b %H:%M})%{$reset_color%}' |
---|
226 | |
---|
227 | ## Plugins section: |
---|
228 | # Use syntax highlighting |
---|
229 | source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh |
---|