-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
322 lines (275 loc) · 8.96 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# nix-env -iA nixpkgs.glibcLocales
export LOCALE_ARCHIVE="$(nix-env --installed --no-name --out-path --query glibc-locales)/lib/locale/locale-archive"
export PATH=$HOME/bin:/usr/local/bin:$PATH
export ZSH="$HOME/.oh-my-zsh"
export LANG=en_US.UTF-8
export LANGUAGE=en_US:en
export LC_ALL=en_US.UTF-8
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
# Nix initialization
if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
fi
ZSH_THEME="bira"
HIST_STAMPS="dd/mm/yyyy"
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh
export LANG=en_US.UTF-8
# editors for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='nvim'
else
export EDITOR='code'
fi
# Disable GPG GUI prompts inside SSH.
if [[ -n "$SSH_CONNECTION" ]]; then
export PINENTRY_USER_DATA='USE_CURSES=1'
fi
autoload -U colors && colors # Load colors
# Basic auto/tab complete
autoload -U compinit
zstyle ':completion:*' menu select
zmodload zsh/complist
compinit
_comp_options+=(globdots) # Include hidden files.
# Some shortcuts
alias \
c="clear" \
ka="killall" \
sdn="shutdown -h now" \
e="$EDITOR" \
a="apt-get" \
i="sudo apt-get install" \
g="git" \
v="nvim" \
ts="pnpm ts-node" \
t="touch" \
tt="tmux" \
obs="obsidian" \
p="python3 -m" \
reload=". ~/.zshrc" \
y="rm -rf"\
f="fzf" \
lpg="loadpg" \
tf="terraform" \
b="cd .." \
bb="cd ..." \
bbb="cd ...." \
bbbb="cd ....." \
bbbbb="cd ......" \
bat="\bat --theme=GitHub" \
sudo='sudo ' \
j="just"\
x="chmod +x" \
ez="eza --long --header --inode --git" \
ddgo="librewolf https://duckduckgo.com" \
gh="librewolf https://github.com/ashgw" \
d_stopall="docker stop $(docker ps -a -q)" \
d_restratall="docker restart $(docker ps -a -q)" \
d_startall="docker start $(docker ps -a -q)" \
d_rmall="docker rm $(docker ps -a -q)" \
pubip='dig +short myip.opendns.com @resolver1.opendns.com' \
localip='ipconfig getifaddr en1' \
ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'" \
ports='lsof +c0 -iTCP -sTCP:LISTEN -n -P' \
defaultip="ip route | grep default"
plugins=(
zsh-syntax-highlighting
git
zsh-autosuggestions
)
# Colors n all so run this: curl https://raw.githubusercontent.com/seebi/dircolors-solarized/master/dircolors.ansi-dark --output ~/.dircolors
eval `dircolors ~/.dircolors`
setopt autocd # change directory just by typing its name
setopt interactivecomments # allow comments in interactive mode
setopt magicequalsubst # enable filename expansion for arguments of the form ‘anything=expression’
setopt nonomatch # hide error message if there is no match for the pattern
setopt notify # report the status of background jobs immediately
setopt numericglobsort # sort filenames numerically when it makes sense
setopt promptsubst # enable command substitution in prompt
WORDCHARS=${WORDCHARS//\/} # Don't consider certain characters part of the word
# hide EOL sign ('%')
PROMPT_EOL_MARK=""
# enable completion features
autoload -Uz compinit
compinit -d ~/.cache/zcompdump
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
zstyle ':completion:*' rehash true
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
# History configurations
HISTFILE=~/.zsh_history
HISTSIZE=1000
SAVEHIST=2000
setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
setopt hist_ignore_dups # ignore duplicated commands history list
setopt hist_ignore_space # ignore commands that start with space
setopt hist_verify # show command with history expansion to user before running it
#setopt share_history # share command history data
# force zsh to show the complete history
alias history="history 0"
# configure `time` format
TIMEFMT=$'\nreal\t%E\nuser\t%U\nsys\t%S\ncpu\t%P'
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
color_prompt=yes
else
color_prompt=
fi
fi
# enable auto-suggestions based on the history
if [ -f /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh ]; then
. /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
# change suggestion color
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#999'
fi
# enable command-not-found if installed
if [ -f /etc/zsh_command_not_found ]; then
. /etc/zsh_command_not_found
fi
################################## Functions section ###########################################
precmd() {
# Print the previously configured title
print -Pnr -- "$TERM_TITLE"
# Print a new line before the prompt, but only if it is not the first line
if [ "$NEWLINE_BEFORE_PROMPT" = yes ]; then
if [ -z "$_NEW_LINE_BEFORE_PROMPT" ]; then
_NEW_LINE_BEFORE_PROMPT=1
else
print ""
fi
fi
}
# generate new SSH keys for github, run this u'll get the pub key copied to ur clipboard,just paste it
ghkey() {
bash ~/.ssh/_gh_gen.sh
}
# terminate all conatainers
tercon() {
for c in $(docker ps -a | tail -n+2 | awk '{print $1}'); do
docker stop "${c}" || :
docker rm "${c}"
done
}
# remove all volumes
tervol() {
docker volume rm $(docker volume ls -q)
}
# remove all images
terimg() {
for img in $(docker images -q); do
docker rmi "${img}" || :
done
}
dprune() {
tercon && terimg && tervol
docker container prune -f
docker system prune -f
docker image prune -f
docker volume prune -f
}
# shows pretty `man` page.
man () {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
}
# create a new directory & cd into it
mdd () {
mkdir -p "$@" && cd "$@"
}
# encrypt a file with a passphrase
passenc() {
local input_file=$1
local output_file="${input_file}.gpg"
if gpg --symmetric --cipher-algo AES256 --quiet --batch --yes --output "$output_file" "$input_file"; then
shred -u "$input_file"
echo -e "\e[1;32mEncrypted $input_file and saved as: $output_file\e[0m"
else
echo -e "\e[1;31mEncryption failed for $input_file\e[0m"
fi
}
passdec() {
local input_file=$1
local output_file="${input_file%.gpg}"
if gpg --use-agent --quiet --batch --yes --decrypt --cipher-algo AES256 --output "$output_file" "$input_file" 2>/dev/null; then
shred -u "$input_file"
echo -e "\e[1;32mDecrypted $input_file and saved as: $output_file\e[0m"
else
echo -e "\e[1;31mDecryption failed for $input_file\e[0m"
fi
}
# copies the content of a file to the clipboard
cpf() {
if [[ -n $1 && -f $1 ]]; then
xclip -selection clipboard < $1
echo -e "\e[1;32mContents of '$1' copied to clipboard.\e[0m"
else
echo "Usage: cpf <filename>"
fi
}
# short for copy command, copies the output of the command to the clipboard
ccmd() {
"$@" | xclip -selection clipboard
}
# When the gpg dameon fucking up, so you gotta lock in
loadpg() {
pkill -9 gpg-agent
export GPG_TTY=$(tty)
}
export MY_CURRENT_FUCKING_CITY=Tunis # TODO: Upgrade
weather() {
LOCATION="${MY_CURRENT_FUCKING_CITY}"
printf "%s" "$SEP1"
if [ "$IDENTIFIER" = "unicode" ]; then
printf "%s" "$(curl -s wttr.in/$LOCATION?format=1)"
else
printf "WEA %s" "$(curl -s wttr.in/$LOCATION?format=1 | grep -o "[0-9].*")"
fi
printf "%s\n" "$SEP2"
}
### Below was generated by the programs I'm installing from ./install/arbitrary/
eval "$(zoxide init zsh)"
eval "$(starship init zsh)"
export PATH="$HOME/miniconda3/bin:$PATH"
. /home/ashgw/miniconda3/etc/profile.d/conda.sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# pnpm
export PNPM_HOME="$HOME/.local/share/pnpm"
case ":$PATH:" in
*":$PNPM_HOME:"*) ;;
*) export PATH="$PNPM_HOME:$PATH" ;;
esac
# go
export PATH=$PATH:/$HOME/go/bin
# Tfenv
export PATH="$HOME/.tfenv/bin:$PATH"
# Rust
export PATH="$HOME/.cargo/bin:$PATH"
# Poetry
export PATH="$HOME/.local/bin:$PATH"
# When GPG pwd verifcation screen doesn't show up on TTY
export GPG_TTY=/dev/pts/0