-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc_portable
243 lines (208 loc) · 6.07 KB
/
.zshrc_portable
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
# Paths
export PATH="$HOME/.local/bin:$PATH" # pip?
export PATH="$HOME/.cargo/bin/:$PATH" # rust
# Tokens and API Keys
load_gemini_key() {
export GEMINI_API_KEY="$(op read "op://Personal/Gemini API Key/credential")"
}
gemini() {
if [ -z "${GEMINI_API_KEY}" ]; then
echo "GEMINI_API_KEY not set. Run load_gemini_key first."
return 1
fi
xh POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${GEMINI_API_KEY}" \
contents:="$1"
}
# powerlevel10k
[[ ! -f ~/powerlevel10k/powerlevel10k.zsh-theme ]] || source ~/powerlevel10k/powerlevel10k.zsh-theme
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# ls colors
export LS_COLORS="ln=1;32:ex=1;32:di=1;94:ow=1;7;94"
# Helpers
declare -A HELP_MESSAGES=(
["backmerge"]="Usage: backmerge <branch>"
["clone"]="Usage: clone <repository-url>"
["checkout"]="Usage: checkout <branch; commit_id; integer_commits_ago>"
["branch"]="Usage: branch <new-branch-name>"
["commit"]="Usage: commit \"<commit-message>\""
["add"]="Usage: add <dir-or-file>"
["stash"]="Usage: stash \"<stash-message>\""
["show"]="Usage: show <integer_commits_ago>"
["ammend"]="Usage: ammend \"<commit-message>\""
)
check_param() {
if [[ -n $BASH_VERSION ]]; then # bash
caller="${FUNCNAME[1]}"
else # zsh / ksh, use offset:length so it always works
# zsh arrays start at 1, with ksh arrays option it starts at 0 https://stackoverflow.com/questions/31426565/get-name-of-calling-function-in-zsh
caller="${funcstack[@]:1:1}"
fi
if [ -z "$1" ]; then
echo "${HELP_MESSAGES[$caller]}" >&2
return 1
fi
return 0
}
# General alias
alias sudo="sudo " # enable aliases for sudo
alias vim="nvim"
alias v="vim"
alias pack="tar -zcvf"
alias unpack="tar -zxvf"
alias ls="lsd"
alias l="ls"
alias la="ls -a"
alias ll="ls -lt"
alias lt="ls --tree"
alias cat="bat"
alias vd="vd --theme=ascii8"
# Config alias
alias zshc="vim ~/.zshrc"
alias zshpc="vim ~/.zshrc_portable"
alias zshlc="vim ~/.zshrc_local"
# cd alias
alias cconfig="c ~/.config"
alias ch="c ~"
alias cnvim="c ~/.config/nvim/lua"
# Python alias
alias pipnuke="pip freeze | cut -d "@" -f1 | xargs pip uninstall -y"
alias pipfreeze="pip list --format=freeze > requirements.txt"
# SSH alias
alias sshpi="ssh [email protected]"
alias sshda="ssh [email protected]"
alias sshhetzner="ssh [email protected]"
# gh alias
alias repocreate="git remote remove origin || gh repo create --public --source . --remote origin && upstreamorigin"
alias repodelete="gh repo delete $(basename $PWD)"
alias repofork="gh repo fork --clone=true"
alias prcreate="gh pr create"
# git alias
## aliases without params
alias lg="lazygit"
alias init="git init"
alias upstreamorigin="currBranch=\$(git rev-parse --abbrev-ref HEAD) && git push --set-upstream origin \$currBranch"
alias upstreamdavay="currBranch=\$(git rev-parse --abbrev-ref HEAD) && git push --set-upstream davay \$currBranch"
alias uncommit="git reset --soft HEAD~1"
alias unstage="git reset"
alias reignore="git rm -r --cached . && git add ." # if you updated gitignore after committing
alias status="git status"
alias pull="git pull"
alias push="git push"
alias clean="git clean -dfx"
alias stashlist="git stash list"
alias stashshow="git stash show -p"
alias stashpop="git stash pop"
alias branches="git --no-pager branch --all"
alias commits="git --no-pager log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
alias lfsconfig='echo -e "[lfs]\nurl = [email protected]:$(basename $(git rev-parse --show-toplevel)).git\nlocksverify = true" > .lfsconfig'
nuke() {
git fetch origin && \
git clean -dfx && \
git reset --hard origin $(git symbolic-ref --short HEAD)
}
## aliases requiring params
backmerge() {
check_param "$1" || return 1
currBranch=$(git rev-parse --abbrev-ref HEAD)
git checkout "$1" && \
git pull && \
git checkout $currBranch && \
git merge "$1"
}
clone() {
check_param "$1" || return 1
git clone "$1"
}
checkout() {
check_param "$1" || return 1
# 1: Check if it's a branch
if git rev-parse --verify --quiet "$1" >/dev/null 2>&1; then
git checkout "$1"
return $?
fi
# 2: Check if it's a remote branch
if git rev-parse --verify --quiet "origin/$1" >/dev/null 2>&1; then
git checkout -b "$1" "origin/$1"
return $?
fi
# 3: Check if it's a valid commit ID
if git rev-parse --verify --quiet "$1^{commit}" >/dev/null 2>&1; then
git checkout "$1"
return $?
fi
# 4: Check if it's a number to go back in history
if [[ "$1" =~ ^[0-9]+$ ]]; then
git checkout "HEAD~$1"
return $?
fi
echo "Error: '$1' is not a valid branch, commit ID, or number of commits to go back"
return 1
}
branch() {
check_param "$1" || return 1
git checkout -b "$1"
}
commit() {
check_param "$1" || return 1
git commit -am "$1"
}
add() {
check_param "$1" || return 1
git add "$1"
}
stash() {
check_param "$1" || return 1
git stash push --include-untracked -m "$1"
}
show() {
check_param "$1" || return 1
git show HEAD~"$1"
}
ammend() {
check_param "$1" || return 1
git commit --amend -m "$1"
}
reset() {
if [ $# -eq 0 ]; then
git reset --hard HEAD
else
git restore --source=HEAD "$@"
fi
}
# gen z alias
alias yikes="git reset --hard HEAD"
alias bigyikes="git clean -dfx && git reset --hard HEAD"
# unused gen z alias
# alias smash="git merge"
# alias ong="rm -rf"
# alias yoink="git pull"
# alias yeet="git push"
# alias cap="-n"
# alias nocap="-f"
# alias yap="-v"
# alias noyap="-q"
# alias please="sudo"
# alias based="c ~/"
# alias bet="git add"
# alias fr="git commit"
# Custom functions
timezsh() {
shell=${1-$SHELL}
for i in $(seq 1 10); do
/usr/bin/time $shell -i -c exit;
done
}
c() {
cd "$@" && ls
}
# Pretty xsv, also replace empty values with -, handle edge cases:
# - when 2 missing values are adjacent
# - when missing value is at the beginning
# - when missing value is at the end
x() {
xsv "$@" | \
sed -e ':a' -e 's/,,/,…,/g' -e 'ta' \
-e 's/^,/…,/' \
-e 's/,$/,…/' | \
bat -l csv
}