Repository navigation
Expand file tree
/
Copy pathexecutable_dot_zshrc
More file actions
211 lines (171 loc) · 5.23 KB
/
Copy pathexecutable_dot_zshrc
File metadata and controls
211 lines (171 loc) · 5.23 KB
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# History in cache directory:
RED="\e[31m"
GREEN="\e[32m"
RESET="\e[0m"
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.cache/zshhistory
HISTORY_IGNORE='(pwd|exit|fg|bg|top|clear|history|ls|uptime|df)'
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
setopt SHARE_HISTORY
setopt APPEND_HISTORY
# Prevent ranger from loading it's default config.
export RANGER_LOAD_DEFAULT_RC=FALSE
# configure PATH
setopt extended_glob null_glob
path=(
$path
/var/lib/flatpak/exports/bin
$HOME/.local/share/flatpak/exports/bin
$HOME/.local/bin
$HOME/.local/scripts
$HOME/.local/bin
)
# remove duplicate entries from PATH.
typeset -U path
# exclude any directories that don't exist.
path=($^path(N-/))
# finally, set the PATH. Remember that there is a special relationship in zsh
# between $PATH and $path, which allows you to do to this.
export PATH
SSH_ENV="$HOME/.ssh/agent-environment"
function start_agent {
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV"
echo "SSH agent started..."
chmod 600 "$SSH_ENV"
. "$SSH_ENV" > /dev/null
}
function source_zsh_plugin() {
local plugin="$1"
local paths=(
"$HOMEBREW_PREFIX/share/$plugin" # Mac Homebrew
"/usr/share/zsh/plugins/$plugin" # Arch
"/usr/share/$plugin" # Ubuntu/Debian
"$HOME/.zsh/plugins/$plugin" # Home directory (git install)
)
for plugin_path in "$paths[@]"; do
if [[ -f "$plugin_path/$plugin.zsh" ]]; then
source "$plugin_path/$plugin.zsh" 2>/dev/null
return 0
fi
done
return 1
}
# Source SSH settings, if applicable
if [ -f "$SSH_ENV" ]; then
. "$SSH_ENV" > /dev/null
ps -ef | grep $SSH_AGENT_PID | grep ssh-agent$ > /dev/null || {
start_agent
}
else
start_agent
fi
function bitwarden-unlock {
if ! command -v bw >/dev/null; then
echo "Bitwarden CLI doesn't appear to be installed."
return 1
fi
local bw_key
bw_key=$(bw unlock --raw)
if [[ $? -ne 0 || -z "$bw_key" ]]; then
echo "${RED}Failed to unlock Bitwarden vault. Check your master password.${RESET}"
return 1
fi
export BW_SESSION="$bw_key"
echo "${GREEN}Unlocked Bitwarden vault.${RESET}"
}
function bitwarden-search {
if [[ "$#" -lt 1 ]]; then
echo "${RED}Search term is required!${RESET}"
return 1
fi
{
printf '%s\t%s\n' "$(tput setaf 4)Name$(tput sgr0)" "$(tput setaf 4)ID$(tput sgr0)"
bw list items --search "$1" | jq -r '.[] | "\(.name)\t\(.id)"'
} | column -t -s $'\t'
}
function bitwarden-get-password {
if [[ "$#" -lt 1 ]]; then
echo "${RED}Search term is required!${RESET}"
return 1
fi
local result
result=$(bw list items --search "$1" | jq -r '.[0].login.password')
if [[ -z "$result" || "$result" == "null" ]]; then
echo "${RED}No password found for \"$1\".${RESET}"
return 1
fi
echo "$result"
}
# Set env variable for GPG
GPG_TTY=$(tty)
export GPG_TTY
# enable vi mode
bindkey -v
export KEYTIMEOUT=20
# Source browser settings if file exists
[ -f ~/.browser ] && source ~/.browser
export TERM=tmux-256color
# Basic auto/tab complete:
autoload -U compinit
zstyle ':completion:*' menu select
zmodload zsh/complist
compinit
_comp_options+=(globdots) # Include hidden files.
# Use vim keys in tab complete menu:
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'left' vi-backward-char
bindkey -M menuselect 'down' vi-down-line-or-history
bindkey -M menuselect 'up' vi-up-line-or-history
bindkey -M menuselect 'right' vi-forward-char
# Fix backspace bug when switching modes
bindkey "^?" backward-delete-char
# Load aliases and shortcuts if existent.
if [[ -d "$HOME/.config/zsh.d" ]]; then
for f in "$HOME/.config/zsh.d/"*; do
source "$f"
done
fi
#change ZSH autosuggest highlight color
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=006'
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
# Set ctrl+space to accept suggestion.
bindkey '^ ' autosuggest-accept
# Start hook for direnv
eval "$(direnv hook zsh)"
bindkey -s '^f' "herdr-sessionizer\n"
# Source zsh plugins
source_zsh_plugin zsh-autosuggestions
source_zsh_plugin zsh-syntax-highlighting
if which starship >/dev/null 2>&1; then
eval "$(starship init zsh)"
fi
if [ -d /home/linuxbrew/ ]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
# Set EDITOR.
# Do this AFTER loading brew vars, since it's installed via homebrew now on a lot of my systems.
if command -v nvim >/dev/null; then
export EDITOR=$(which nvim)
else
export EDITOR=/usr/bin/vim
fi
# Set up fzf key bindings and fuzzy completion
if [ -f /usr/bin/fzf ] || [ -f "$HOMEBREW_PREFIX/bin/fzf" ]; then
source <(fzf --zsh)
fi
# Use zoxide and eza if available.
if [ -f "$HOMEBREW_PREFIX/bin/zoxide" ] || [ -f /usr/bin/zoxide ]; then
eval "$(zoxide init zsh --cmd cd)"
fi
if [ -f "$HOMEBREW_PREFIX/bin/eza" ] || [ -f /usr/local/bin/eza ]; then
alias ls='eza -l'
fi
if [ -f /usr/local/bin/atuin ] || [ "$HOMEBREW_PREFIX/bin/atuin" ]; then
eval "$(atuin init zsh)"
fi