aboutsummarylogtreecommitdiffstats
path: root/easy-zsh-config
blob: 0b9af37db04ac1e887420d7e210f28cd8614bf38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
## Config the theme file from arg. or use fallback theme file
if [ $# -gt 0 ]; then
  if [[ -r "${1}" ]]; then
    _POSH_THEME="${1}"
  else
    _POSH_THEME="/usr/share/oh-my-posh/themes/atomic.omp.json"
  fi
else
  _POSH_THEME="/usr/share/oh-my-posh/themes/atomic.omp.json"
fi

## Apply the theme file
if [[ -r "${_POSH_THEME}" ]] && type oh-my-posh &> /dev/null; then
  export POSH_THEME=${_POSH_THEME}
  eval "$(oh-my-posh init zsh)"
else
  autoload -U promptinit
  promptinit
  prompt elite2 green yellow
fi


## Set history
HISTFILE=~/.zsh_history
HISTSIZE=100000
SAVEHIST=100000
setopt correct                   # Auto correct mistakes
setopt extendedglob              # Extended globbing. Allows using regular expressions with *
setopt nocaseglob                # Case insensitive globbing
setopt rcexpandparam             # Array expension with parameters
setopt BANG_HIST                 # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY          # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY        # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY             # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST    # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS          # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS      # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS         # Do not display a line previously found.
setopt HIST_IGNORE_SPACE         # Don't record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS         # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS        # Remove superfluous blanks before recording entry.
setopt HIST_VERIFY               # Don't execute immediately upon history expansion.
setopt HIST_BEEP                 # Beep when accessing nonexistent history.

zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'       # Case insensitive tab completion
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"         # Colored completion (different colors for dirs/files/etc)
zstyle ':completion:*' rehash true                              # automatically find new executables in path 
# Speed up completions
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.cache/zsh
WORDCHARS=${WORDCHARS//\/[&.;]}                                 # Don't consider certain characters part of the word


## Set plugins
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
if [[ -r /usr/share/doc/pkgfile/command-not-found.zsh ]]; then
    source /usr/share/doc/pkgfile/command-not-found.zsh
    #export PKGFILE_PROMPT_INSTALL_MISSING=1
fi
### Load function for auto completion
autoload -U compinit
compinit


## Set key bindings
bindkey -e
bindkey '^[[7~' beginning-of-line                               # Home key
bindkey '^[[H' beginning-of-line                                # Home key
if [[ "${terminfo[khome]}" != "" ]]; then
  bindkey "${terminfo[khome]}" beginning-of-line                # [Home] - Go to beginning of line
fi
bindkey '^[[8~' end-of-line                                     # End key
bindkey '^[[F' end-of-line                                      # End key
if [[ "${terminfo[kend]}" != "" ]]; then
  bindkey "${terminfo[kend]}" end-of-line                       # [End] - Go to end of line
fi
bindkey '^[[2~' overwrite-mode                                  # Insert key
bindkey '^[[3~' delete-char                                     # Delete key
bindkey '^[[C'  forward-char                                    # Right key
bindkey '^[[D'  backward-char                                   # Left key
bindkey "^[[A" history-substring-search-up                      # Up key
bindkey "^[[B" history-substring-search-down                    # Down key
bindkey ";5A" history-beginning-search-backward                 # Ctrl-Up key
bindkey ";5B" history-beginning-search-forward                  # Ctrl-Down key
bindkey "^[[1;5A" history-beginning-search-backward             # Ctrl-Up key
bindkey "^[[1;5B" history-beginning-search-forward              # Ctrl-Down key

bindkey '^[Oc' forward-word                                     #
bindkey '^[Od' backward-word                                    #
bindkey '^[[1;5D' backward-word                                 #
bindkey '^[[1;5C' forward-word                                  #
bindkey '^H' backward-kill-word                                 # delete previous word with ctrl+backspace
bindkey '^[[Z' undo                                             # Shift+tab undo last action


## Set alias 
alias cp="cp -i"                                                # Confirm before overwriting something
alias df='df -h'                                                # Human-readable sizes
alias free='free -h'                                            # Human-readable sizes
alias gitu='git add . && git commit && git push'
alias ls='ls --color=auto'                                      # Set colored output of ls


## Color man pages
man() {
  LESS_TERMCAP_mb=$'\E[01;31m'  # bold red
  LESS_TERMCAP_md=$'\E[01;31m'  # bold red
  LESS_TERMCAP_me=$'\E[0m'      # reset
  LESS_TERMCAP_se=$'\E[0m'      # reset
  LESS_TERMCAP_so=$'\E[01;44m' # bold blue
  LESS_TERMCAP_ue=$'\E[0m'      # reset
  LESS_TERMCAP_us=$'\E[01;32m' # bold green
  LESS=-R
  command man "$@"
}