-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc_portable
195 lines (168 loc) · 4.69 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
# Random stuff
export PATH=$PATH:~/.cargo/bin/
# 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>"
)
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"
# 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 && upstream"
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 upstream="currBranch=\$(git rev-parse --abbrev-ref HEAD) && git push --set-upstream origin \$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 reset="git reset --hard HEAD"
alias nuke="git clean -dfx && git reset --hard HEAD"
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"
## 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 valid commit ID
if git rev-parse --verify --quiet "$1^{commit}" >/dev/null 2>&1; then
git checkout "$1"
return $?
fi
# 3: 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"
}
# 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
}