Ticket #3121: .zshrc

File .zshrc, 9.5 KB (added by xor512, 5 years ago)

/etc/skel/.zshrc from manjaro-zsh-config package

Line 
1## Options section
2setopt correct                                                  # Auto correct mistakes
3setopt extendedglob                                             # Extended globbing. Allows using regular expressions with *
4setopt nocaseglob                                               # Case insensitive globbing
5setopt rcexpandparam                                            # Array expension with parameters
6setopt nocheckjobs                                              # Don't warn about running processes when exiting
7setopt numericglobsort                                          # Sort filenames numerically when it makes sense
8setopt nobeep                                                   # No beep
9setopt appendhistory                                            # Immediately append history instead of overwriting
10setopt histignorealldups                                        # If a new command is a duplicate, remove the older one
11setopt autocd                                                   # if only directory path is entered, cd there.
12
13zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'       # Case insensitive tab completion
14zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"         # Colored completion (different colors for dirs/files/etc)
15zstyle ':completion:*' rehash true                              # automatically find new executables in path
16# Speed up completions
17zstyle ':completion:*' accept-exact '*(N)'
18zstyle ':completion:*' use-cache on
19zstyle ':completion:*' cache-path ~/.zsh/cache
20HISTFILE=~/.zhistory
21HISTSIZE=1000
22SAVEHIST=500
23#export EDITOR=/usr/bin/nano
24#export VISUAL=/usr/bin/nano
25WORDCHARS=${WORDCHARS//\/[&.;]}                                 # Don't consider certain characters part of the word
26
27
28## Keybindings section
29bindkey -e
30bindkey '^[[7~' beginning-of-line                               # Home key
31bindkey '^[[H' beginning-of-line                                # Home key
32if [[ "${terminfo[khome]}" != "" ]]; then
33  bindkey "${terminfo[khome]}" beginning-of-line                # [Home] - Go to beginning of line
34fi
35bindkey '^[[8~' end-of-line                                     # End key
36bindkey '^[[F' end-of-line                                     # End key
37if [[ "${terminfo[kend]}" != "" ]]; then
38  bindkey "${terminfo[kend]}" end-of-line                       # [End] - Go to end of line
39fi
40bindkey '^[[2~' overwrite-mode                                  # Insert key
41bindkey '^[[3~' delete-char                                     # Delete key
42bindkey '^[[C'  forward-char                                    # Right key
43bindkey '^[[D'  backward-char                                   # Left key
44bindkey '^[[5~' history-beginning-search-backward               # Page up key
45bindkey '^[[6~' history-beginning-search-forward                # Page down key
46
47# Navigate words with ctrl+arrow keys
48bindkey '^[Oc' forward-word                                     #
49bindkey '^[Od' backward-word                                    #
50bindkey '^[[1;5D' backward-word                                 #
51bindkey '^[[1;5C' forward-word                                  #
52bindkey '^H' backward-kill-word                                 # delete previous word with ctrl+backspace
53bindkey '^[[Z' undo                                             # Shift+tab undo last action
54
55## Alias section
56alias cp="cp -i"                                                # Confirm before overwriting something
57alias df='df -h'                                                # Human-readable sizes
58alias free='free -m'                                            # Show sizes in MB
59alias gitu='git add . && git commit && git push'
60
61# Theming section 
62autoload -U compinit colors zcalc
63compinit -d
64colors
65
66# enable substitution for prompt
67setopt prompt_subst
68
69# Prompt (on left side) similar to default bash prompt, or redhat zsh prompt with colors
70 #PROMPT="%(!.%{$fg[red]%}[%n@%m %1~]%{$reset_color%}# .%{$fg[green]%}[%n@%m %1~]%{$reset_color%}$ "
71# Maia prompt
72PROMPT="%B%{$fg[cyan]%}%(4~|%-1~/.../%2~|%~)%u%b >%{$fg[cyan]%}>%B%(?.%{$fg[cyan]%}.%{$fg[red]%})>%{$reset_color%}%b " # Print some system information when the shell is first started
73# Print a greeting message when shell is started
74echo $USER@$HOST  $(uname -srm) $(lsb_release -rcs)
75## Prompt on right side:
76#  - shows status of git when in git repository (code adapted from https://techanic.net/2012/12/30/my_git_prompt_for_zsh.html)
77#  - shows exit status of previous command (if previous command finished with an error)
78#  - is invisible, if neither is the case
79
80# Modify the colors and symbols in these variables as desired.
81GIT_PROMPT_SYMBOL="%{$fg[blue]%}±"                              # plus/minus     - clean repo
82GIT_PROMPT_PREFIX="%{$fg[green]%}[%{$reset_color%}"
83GIT_PROMPT_SUFFIX="%{$fg[green]%}]%{$reset_color%}"
84GIT_PROMPT_AHEAD="%{$fg[red]%}ANUM%{$reset_color%}"             # A"NUM"         - ahead by "NUM" commits
85GIT_PROMPT_BEHIND="%{$fg[cyan]%}BNUM%{$reset_color%}"           # B"NUM"         - behind by "NUM" commits
86GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}⚡︎%{$reset_color%}"     # lightning bolt - merge conflict
87GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}"       # red circle     - untracked files
88GIT_PROMPT_MODIFIED="%{$fg_bold[yellow]%}●%{$reset_color%}"     # yellow circle  - tracked files modified
89GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}"        # green circle   - staged changes present = ready for "git push"
90
91parse_git_branch() {
92  # Show Git branch/tag, or name-rev if on detached head
93  ( git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD ) 2> /dev/null
94}
95
96parse_git_state() {
97  # Show different symbols as appropriate for various Git repository states
98  # Compose this value via multiple conditional appends.
99  local GIT_STATE=""
100  local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
101  if [ "$NUM_AHEAD" -gt 0 ]; then
102    GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD}
103  fi
104  local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
105  if [ "$NUM_BEHIND" -gt 0 ]; then
106    GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND}
107  fi
108  local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)"
109  if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then
110    GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING
111  fi
112  if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
113    GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED
114  fi
115  if ! git diff --quiet 2> /dev/null; then
116    GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED
117  fi
118  if ! git diff --cached --quiet 2> /dev/null; then
119    GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED
120  fi
121  if [[ -n $GIT_STATE ]]; then
122    echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX"
123  fi
124}
125
126git_prompt_string() {
127  local git_where="$(parse_git_branch)"
128 
129  # If inside a Git repository, print its branch and state
130  [ -n "$git_where" ] && echo "$GIT_PROMPT_SYMBOL$(parse_git_state)$GIT_PROMPT_PREFIX%{$fg[yellow]%}${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX"
131 
132  # If not inside the Git repo, print exit codes of last command (only if it failed)
133  [ ! -n "$git_where" ] && echo "%{$fg[red]%} %(?..[%?])"
134}
135
136# Right prompt with exit status of previous command if not successful
137 #RPROMPT="%{$fg[red]%} %(?..[%?])"
138# Right prompt with exit status of previous command marked with ✓ or ✗
139 #RPROMPT="%(?.%{$fg[green]%}✓ %{$reset_color%}.%{$fg[red]%}✗ %{$reset_color%})"
140
141
142# Color man pages
143export LESS_TERMCAP_mb=$'\E[01;32m'
144export LESS_TERMCAP_md=$'\E[01;32m'
145export LESS_TERMCAP_me=$'\E[0m'
146export LESS_TERMCAP_se=$'\E[0m'
147export LESS_TERMCAP_so=$'\E[01;47;34m'
148export LESS_TERMCAP_ue=$'\E[0m'
149export LESS_TERMCAP_us=$'\E[01;36m'
150export LESS=-r
151
152
153## Plugins section: Enable fish style features
154# Use syntax highlighting
155source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
156# Use history substring search
157source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
158# bind UP and DOWN arrow keys to history substring search
159zmodload zsh/terminfo
160bindkey "$terminfo[kcuu1]" history-substring-search-up
161bindkey "$terminfo[kcud1]" history-substring-search-down
162bindkey '^[[A' history-substring-search-up                     
163bindkey '^[[B' history-substring-search-down
164
165# Apply different settigns for different terminals
166case $(basename "$(cat "/proc/$PPID/comm")") in
167  login)
168        RPROMPT="%{$fg[red]%} %(?..[%?])"
169        alias x='startx ~/.xinitrc'      # Type name of desired desktop after x, xinitrc is configured for it
170    ;;
171#  'tmux: server')
172#        RPROMPT='$(git_prompt_string)'
173#               ## Base16 Shell color themes.
174#               #possible themes: 3024, apathy, ashes, atelierdune, atelierforest, atelierhearth,
175#               #atelierseaside, bespin, brewer, chalk, codeschool, colors, default, eighties,
176#               #embers, flat, google, grayscale, greenscreen, harmonic16, isotope, londontube,
177#               #marrakesh, mocha, monokai, ocean, paraiso, pop (dark only), railscasts, shapesifter,
178#               #solarized, summerfruit, tomorrow, twilight
179#               #theme="eighties"
180#               #Possible variants: dark and light
181#               #shade="dark"
182#               #BASE16_SHELL="/usr/share/zsh/scripts/base16-shell/base16-$theme.$shade.sh"
183#               #[[ -s $BASE16_SHELL ]] && source $BASE16_SHELL
184#               # Use autosuggestion
185#               source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
186#               ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
187#               ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
188#     ;;
189  *)
190        RPROMPT='$(git_prompt_string)'
191                # Use autosuggestion
192                source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
193                ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
194                ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
195    ;;
196esac