-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
194 lines (155 loc) · 5.69 KB
/
.zshrc
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
export TERM="xterm-256color"
source /usr/share/zsh/scripts/zplug/init.zsh
# Theme
POWERLEVEL9K_MODE='nerdfont-complete'
POWERLEVEL9K_STATUS_CROSS=true
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_middle"
POWERLEVEL9K_SHORTEN_DIR_LENGTH=4
POWERLEVEL9K_TIME_BACKGROUND="yellow"
POWERLEVEL9K_TIME_FOREGROUND="black"
POWERLEVEL9K_TIME_FORMAT="%B%D{%H:%M:%S}"
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon dir dir_writable vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_OS_ICON_FOREGROUND="108"
POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow'
POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='yellow'
# Plugins
if [ "$TERM" != 'linux' ]; then
source /usr/share/zsh-theme-powerlevel9k/powerlevel9k.zsh-theme
else
export PS1="%{%F{yellow}%}%n%{%f%} %~ › "
fi
zplug "zsh-users/zsh-completions"
zplug "zsh-users/zsh-autosuggestions"
zplug "zsh-users/zsh-syntax-highlighting"
zplug "zsh-users/zsh-history-substring-search"
zplug "yukiycino-dotfiles/fancy-ctrl-z"
# History configuration
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt correct # Command correction
setopt globdots # Hidden files tab completion
setopt auto_pushd
stty -ixon # Disables XON/XOFF flow control
zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)(?)*==34=34}:${(s.:.)LS_COLORS}")'; # Tab colors
# Completion options
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f'
zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f'
zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f'
zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f'
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
zstyle ':completion:*' format ' %F{yellow}-- %d --%f'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' verbose yes
fpath=(~/.zsh/completion $fpath)
autoload -Uz compinit && compinit -i
export PATH=${PATH}:${HOME}/.bin
export PATH=${PATH}:${HOME}/.local/bin
export PATH=${PATH}:${HOME}/.yarn/bin
export PATH=${PATH}:${HOME}/lib/flutter/bin
export PATH="$HOME/.symfony/bin:$PATH"
export FZF_DEFAULT_COMMAND='fd --hidden --type f --follow --color=always --exclude .git'
export FZF_DEFAULT_OPTS="--ansi"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export VISUAL=vim
export EDITOR="$VISUAL"
export CHROME_EXECUTABLE=/usr/bin/google-chrome-stable
# Fixes keys
bindkey -e
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line
bindkey "\e[5~" beginning-of-history
bindkey "\e[6~" end-of-history
bindkey "\e[7~" beginning-of-line
bindkey "\e[3~" delete-char
bindkey "\e[2~" quoted-insert
bindkey "\e[5C" forward-word
bindkey "\e[5D" backward-word
bindkey "\e\e[C" forward-word
bindkey "\e\e[D" backward-word
bindkey "\e[1;5C" forward-word
bindkey "\e[1;5D" backward-word
bindkey "\e[8~" end-of-line
bindkey "\eOH" beginning-of-line
bindkey "\eOF" end-of-line
bindkey "\e[H" beginning-of-line
# Enables shift tab
bindkey '^[[Z' reverse-menu-complete
# Enables emacs mode
set -o emacs
# Arrows search
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
# Shortcuts
alias v='nvim'
alias vi='nvim'
alias vim='nvim'
alias ls='exa'
alias la='exa -a'
alias ll='exa -l'
alias lla='exa -la'
alias grep="rg"
alias t='tmux -2'
alias dc='docker-compose'
alias dcs="docker stop $(docker ps -aq)"
alias dcrm="docker rm $(docker ps -aq)"
alias docker-top='docker run -ti -v /var/run/docker.sock:/var/run/docker.sock quay.io/vektorlab/ctop:latest'
alias dotfiles='cd ~/dotfiles'
zplug load
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_CTRL_T_OPTS="--bind ?:toggle-preview --preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'"
_fzf_compgen_path() {
fd --hidden --follow --exclude ".git" . "$1"
}
_fzf_compgen_dir() {
fd --type d --hidden --follow --exclude ".git" . "$1"
}
# pierpo/fzf-docker
# doesn't work with zplug...
_fzf_complete_docker() {
# Get all Docker commands
#
# Cut below "Management Commands:", then exclude "Management Commands:",
# "Commands:" and the last line of the help. Then keep the first column and
# delete empty lines
DOCKER_COMMANDS=$(docker --help 2>&1 >/dev/null |
sed -n -e '/Management Commands:/,$p' |
grep -v "Management Commands:" |
grep -v "Commands:" |
grep -v 'COMMAND --help' |
grep .
)
ARGS="$@"
if [[ $ARGS == 'docker ' ]]; then
_fzf_complete "--reverse -n 1 --height=80%" "$@" < <(
echo $DOCKER_COMMANDS
)
elif [[ $ARGS == 'docker rmi'* || $ARGS == 'docker -f'* ]]; then
_fzf_complete "--multi --reverse" "$@" < <(
docker images --format '{{.Repository}}:{{.Tag}}'
)
elif [[ $ARGS == 'docker start'* || $ARGS == 'docker restart'* || $ARGS == 'docker stop'* || $ARGS == 'docker rm'* || $ARGS == 'docker exec'* || $ARGS == 'docker kill'* ]]; then
_fzf_complete "--multi --reverse" "$@" < <(
docker ps --format '{{.Names}}'
)
fi
}
_fzf_complete_docker_post() {
# Post-process the fzf output to keep only the command name and not the explanation with it
awk '{print $1}'
}
[ -n "$BASH" ] && complete -F _fzf_complete_docker -o default -o bashdefault docker
# Find in files and return filenames
fif() {
if [ ! "$#" -gt 0 ]; then echo "Need a string to search for!"; return 1; fi
rg --files-with-matches --no-messages "$1" | fzf --height 40% --multi --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --pretty --context 10 '$1' || rg --pretty --context 10 '$1' {}"
}
rp() {
sd $1 $2 $(fif $1)
}