Ticket #3121: .zshrc_arch

File .zshrc_arch, 11.0 KB (added by xor512, 5 years ago)

.zshrc from manjaro forum which probably do not depend on manjaro-zsh-config package and can be probably used on plain Arch

Line 
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
20setopt 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
21setopt autolist                                # Automatically list choices on an ambiguous completion
22setopt autoparamslash                        # If a parameter is completed whose content is the name of a directory, then add a trailing slash instead of a space
23setopt 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).
24setopt nobeep                                # Avoid "beep"ing
25setopt nohup                                 # Don't send SIGHUP to background processes when the shell exits (Don't kill processes when exiting)
26
27setopt unset                                 # don't error out when unset parameters are used
28
29#### Correction
30setopt correct                                 # Try to correct the spelling of commands. Note that, this may falsely report spelling errors the first time some commands are used
31setopt correctall                            # correct_all: Try to correct the spelling of all arguments in a line
32
33setopt menu_complete
34
35#### HISTORY
36setopt append_history                         # append history list to the history file: Immediately append history instead of overwriting
37setopt histignorealldups                    # If a new command line being added to the history list duplicates an older one, the older command is removed from the list
38setopt histignorespace                        # remove command lines from the history list when the first character on the line is a space
39setopt inc_append_history share_history        # import new commands from the history file also in other zsh-session
40
41
42setopt extended_glob                        # Extended globbing. Allows using regular expressions with *
43setopt nocaseglob                           # Case insensitive globbing
44
45setopt prompt_subst                            # enable substitution for prompt
46
47### Autoload zsh modules when they are referenced
48#################################################
49autoload -U colors
50autoload -U compinit
51autoload -U history-search-end
52zle -N history-beginning-search-backward-end history-search-end
53zle -N history-beginning-search-forward-end history-search-end
54
55### Reference modules
56###############
57colors                                         # Enable color support
58compinit -d                                 # The "-d" flag speeds up the completion system using a ".zcompdump" file.
59
60### Set variables
61#################
62PATH="/usr/local/bin:/usr/local/sbin/:$PATH"
63HISTFILE=~/.zhistory
64HISTSIZE=1000
65SAVEHIST=1000
66LS_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:';
67export EDITOR=/usr/bin/nano
68export VISUAL=/usr/bin/nano
69export LS_COLORS
70
71### Set alias
72#############
73alias ls='ls --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F'
74alias ll='ls -l'
75alias la='ls -lha'
76alias Z='source ~/.zshrc'
77alias cp="cp -i"                                                # Confirm before overwriting something
78alias df='df -h'                                                # Human-readable sizes
79alias free='free -m'                                            # Show sizes in MB
80alias x='startx ~/.xinitrc'                                     # Type name of desired desktop after x, xinitrc is configured for it
81alias cpz='cp /media/sf_SharedVM/zshcomparison/.zshrc ~/.zshrc'
82alias grep='grep --color=tty -d skip'
83
84### Bind keys
85#############
86bindkey "^?" backward-delete-char
87bindkey '^[OH' beginning-of-line
88bindkey '^[OF' end-of-line
89bindkey '^[[5~' up-line-or-history
90bindkey '^[[6~' down-line-or-history
91bindkey "^[[A" history-beginning-search-backward-end    #Up arrow
92bindkey "^[[B" history-beginning-search-forward-end        #Down arrow
93bindkey "^r" history-incremental-search-backward
94bindkey ' ' magic-space    # also do history expansion on space
95bindkey '^I' complete-word # complete on tab, leave expansion to _expand
96
97### Set prompt
98#################
99echo $(uname -srm) $(lsb_release -rs) # Print some system information when the shell is first started
100
101# Prompt with different colors for root
102PROMPT="%(!.[%{$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
107zstyle ':completion:*::::' completer _oldlist _expand _complete _files _ignored _approximate
108
109# formatting and messages
110zstyle ':completion:*' verbose yes
111
112zstyle ':completion:*:descriptions'    format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}'
113zstyle ':completion:*:messages'        format '%d'
114zstyle ':completion:*:warnings'        format 'No matches for: %d'
115zstyle ':completion:*:corrections'     format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
116
117# separate matches into groups
118zstyle ':completion:*:matches'         group 'yes'
119zstyle ':completion:*'                 group-name ''
120
121zstyle ':completion:*' menu select _complete _ignored _approximate # activate menu for selection
122
123zstyle -e ':completion:*:approximate:'    max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )' # allow one error for every three characters typed in approximate completer
124
125zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'       # Case insensitive tab completion
126zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"         # Colored completion (different colors for dirs/files/etc)
127zstyle ':completion:*' rehash true                              # automatically find new executables in path
128zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST
129zstyle ':completion::complete:*' use-cache on
130
131# Process management
132zstyle ':completion:*:processes'       command 'ps -au$USER' #on processes completion complete all user processes
133zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq' # Provide more processes in completion of programs like killall:
134zstyle ':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
138zstyle ':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#############
147export LESS_TERMCAP_mb=$'\E[01;32m'
148export LESS_TERMCAP_md=$'\E[01;32m'
149export LESS_TERMCAP_me=$'\E[0m'
150export LESS_TERMCAP_se=$'\E[0m'
151export LESS_TERMCAP_so=$'\E[01;47;34m'
152export LESS_TERMCAP_ue=$'\E[0m'
153export LESS_TERMCAP_us=$'\E[01;36m'
154export LESS=-r
155
156### GIT management
157#############
158
159# Modify the colors and symbols in these variables as desired.
160GIT_PROMPT_PREFIX="%{$fg[green]%}[%{$reset_color%}"
161GIT_PROMPT_SUFFIX="%{$fg[green]%}]%{$reset_color%}"
162GIT_PROMPT_AHEAD="%{$fg[red]%}ANUM%{$reset_color%}"                 # A"NUM"         - ahead by "NUM" commits
163GIT_PROMPT_BEHIND="%{$fg[cyan]%}BNUM%{$reset_color%}"               # B"NUM"         - behind by "NUM" commits
164if [[ ${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"
170else
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"
176fi
177
178parse_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
183parse_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
213git_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#############
225RPROMPT='$(git_prompt_string)%{$fg_bold[yellow]%}(%D{%d-%b %H:%M})%{$reset_color%}'
226
227## Plugins section:
228# Use syntax highlighting
229source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh