-
Notifications
You must be signed in to change notification settings - Fork 7
/
.zsh_aliases
135 lines (126 loc) Β· 4.62 KB
/
.zsh_aliases
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
# vim: ft=zsh
function mkcd() { mkdir -p $1; cd $1;}
alias cp='cp -riv'
alias mv='mv -iv'
alias mkdir='mkdir -pv'
alias v='nvim --listen ~/.cache/nvim/server.pipe'
alias l='eza --sort=changed --icons -la --git --git-ignore --ignore-glob=".DS_Store|__MACOSX|__pycache__"'
alias la='eza --group-directories-first --icons -la'
alias ll='eza --group-directories-first --icons -la --color-scale --time-style=long-iso --git --git-ignore --ignore-glob=".git|.DS_Store|__MACOSX|__pycache__" -T -L2'
alias ll3='eza --group-directories-first --icons -la --git --git-ignore --ignore-glob=".git|.DS_Store|__MACOSX" -T -L3'
alias ll4='eza --group-directories-first --icons -la --git --git-ignore --ignore-glob=".git|.DS_Store|__MACOSX" -T -L4'
alias tree='eza --group-directories-first -T --icons'
alias c='clear'
alias gs='git status -sb'
alias gc='git commit'
function gp() {
git push $@ || return 1
if test -s "$(git root)/.github/workflows" && ([[ $(git remote get-url origin) =~ 'github.com' ]] || gh repo view >/dev/null 2>&1); then
max_retries=50
retry_count=0
# Loop until the job exists for commit or maximum retries reached
while [ $retry_count -lt $max_retries ]; do
local job=$(gh run list --commit $(git rev-parse HEAD) --json databaseId --jq '.[0].databaseId')
if [[ -n $job ]]; then
echo "Job found: $job"
break
else
echo "Job not found, retrying..."
((retry_count++))
sleep 1
fi
done
if [ $retry_count -ge $max_retries ]; then
echo "Max retries reached, aborting"
return 1
fi
gh run watch --exit-status $job || gh run view --log-failed $job
elif test -s "$(git root)/.gitlab-ci.yml" && ([[ $(git remote get-url origin) =~ 'gitlab.com' ]] || glab repo view >/dev/null 2>&1); then
glab ci view
fi
}
function gh-ci-retry() {
local max_retries=${1:-20} # read from argument or default to 20
retry_count=0
# Loop until the job succeeds or maximum retries reached
local job=$(gh run list --commit $(git rev-parse HEAD) --json databaseId --jq '.[0].databaseId')
while [ $retry_count -lt $max_retries ]; do
gh run rerun $job --failed
if gh run watch --exit-status $job; then
break
else
echo "retrying..."
((retry_count++))
fi
done
if [ $retry_count -ge $max_retries ]; then
echo "Max retries reached, aborting"
return 1
fi
}
alias gm='git switch $(git_main_branch)'
alias t='tmux attach -t $(tmux list-sessions -F "#{session_name}" | fzf) || tmux new-session'
alias wget='wget --content-disposition'
alias dl='xh --download'
alias venv='source ~/work/python/environments/venv/bin/activate'
alias update='sudo apt-get update && sudo apt-get upgrade -y'
alias d='sudo docker'
alias dc='sudo docker-compose'
# alias dcu='sudo docker-compose pull && sudo docker-compose up -d && sudo docker image prune -f'
alias dcu='sudo docker-compose pull && sudo docker-compose up -d'
alias dexec='sudo docker exec -e COLUMNS="`tput cols`" -e LINES="`tput lines`" -ti'
alias arm='arch -arm64'
alias x86='arch -x86_64'
alias extract='ouch decompress'
alias yadmui='gitui -d ~/.local/share/yadm/repo.git'
alias tower='gittower $(git rev-parse --show-toplevel)'
alias ping='prettyping --nolegend'
alias ps='procs'
alias cpu='procs --sortd cpu'
alias mem='procs --sortd mem'
function _calcram() {
local sum
sum=0
for i in `\ps aux | grep -i "$1" | grep -v "grep" | awk '{print $6}'`; do
sum=$(($i + $sum))
done
sum=$(echo "scale=0; $sum / 1024.0" | bc)
echo $sum
}
# Show how much RAM application uses.
# original from https://github.com/paulmillr/dotfiles/blob/master/home/.zshrc.sh
# $ ram safari
# => safari uses 154 MB of RAM
function ram() {
local sum
local app="$1"
if [ -z "$app" ]; then
echo "First argument - pattern to grep from processes"
return 0
fi
sum=$(_calcram $app)
if [[ $sum != "0" ]]; then
echo "${fg[blue]}${app}${reset_color} uses ${fg[green]}${sum}${reset_color} MB of RAM"
else
echo "No active processes matching pattern '${fg[blue]}${app}${reset_color}'"
fi
}
# Same, but tracks RAM usage in realtime. Will refresh every second until stopped.
# $ rams safari
function rams() {
local sum
local app="$1"
if [ -z "$app" ]; then
echo "First argument - pattern to grep from processes"
return 0
fi
while true; do
sum=$(_calcram $app)
if [[ $sum != "0" ]]; then
echo -en "${fg[blue]}${app}${reset_color} uses ${fg[green]}${sum}${reset_color} MB of RAM\r"
else
echo -en "No active processes matching pattern '${fg[blue]}${app}${reset_color}'\r"
fi
sleep 1
done
}