aboutsummaryrefslogtreecommitdiff
path: root/files/.zsh/rc/S50_aliases
blob: 0717361e33813f12b24d04d8bdab7e0eb8d30a1f (plain) (blame)
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
function is_command() {
    command -v $1 > /dev/null
}

# {{{ Global aliases

alias -g G='|grep -i'
alias -g H='|head'
alias -g T='|tail'
alias -g L='|less'
alias -g LA='2>&1|less'
alias -g X='|xclip'
alias -g XC='|xclip -selection clipboard'
alias -g UP='|&\up'
alias -g S='|sort'
alias -g SN='|sort -n'
alias -g NO='>/dev/null'
alias -g NE='2>/dev/null'
alias -g NUL='&>/dev/null'
alias -g X='| xargs'
alias -g X1='| xargs -n 1'
alias -g XL='| tr "\n" "\0" | xargs -0'

alias -g A1="| awk '{print \$1}'"
alias -g A2="| awk '{print \$2}'"
alias -g A3="| awk '{print \$3}'"
alias -g A4="| awk '{print \$4}'"
alias -g A5="| awk '{print \$5}'"
alias -g A6="| awk '{print \$6}'"
alias -g A7="| awk '{print \$7}'"
alias -g A8="| awk '{print \$8}'"
alias -g A9="| awk '{print \$9}'"

# }}}
# Suffix aliases {{{

alias -s html=open
alias -s pdf=open
is_command wine && alias -s exe=wine
alias -s jar="java -jar"
alias -s git="gclone"
is_command gdebi && alias -s deb="sudo gdebi" || alias -s deb="sudo dpkg -i"
is_command aria2c && alias -s torrent="aria2c"

# }}}
# Common tools {{{

# Fix aliases
alias sudo='sudo '
alias sudo-path='sudo env "PATH=$PATH" '
alias watch='watch '

# Remove grml alias for ag
unalias ag

alias -- -="cd -"

alias df='df -h'
alias free='free -tm'
alias whois='whois -H'
alias grep='grep --color=auto'
alias zgrep='zgrep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias fn='find . -name'
alias ip='ip -color -brief'
alias dmesg='dmesg --human'
alias nf="numfmt --from=auto --to=iec"
alias tree="tree --dirsfirst"
alias dig='dig +nocmd +multiline +noall +answer'
alias lsof='lsof -w'
is_command bat && alias cat='bat'

alias crontab='crontab -i'
alias rm='rm --interactive=once'
alias rmcdir='cd ..; rm -rfi "$OLDPWD" || cd "$OLDPWD"'
is_command trash-put && alias rm='trash-put'
alias mv='mv --interactive'
alias cp='cp --interactive --recursive --reflink=auto'
alias ln='ln --interactive --verbose'
alias mkdir='mkdir -pv'
if is_command colordiff; then
    alias diff='colordiff -u'
else
    alias diff='diff -u'
fi

alias fd='fdfind'
alias dd='dd status=progress'
alias ls='ls --color=auto -h -F --group-directories-first'
alias l='ls -l'
alias d='dirs -v | head -10'

alias da='\du -sch'
if is_command gdu; then
    alias du='gdu --no-delete --no-cross'
    alias ncdu='gdu'
elif is_command ncdu; then
    alias du='ncdu -rr -x --exclude .git'
    alias ncdu='ncdu -q'
else
    alias du='du -h'
fi

alias bc='bc -lq'

alias c=' clear'
check_com g || alias g='git'
check_com lg && is_command lazygit || alias lg='lazygit'
check_com s || alias s='ssh'
alias v='vim'
alias vp='vim -c "setlocal buftype=nofile bufhidden=hide noswapfile buflisted" -'
alias sv='sudo -e'
alias t='tmux new-session -A -s main'
if is_command tmuxp; then
  alias mux='tmuxp load -y'
elif is_command tmuxinator; then
  alias mux='tmuxinator'
fi
alias scratch='vim -c Scratch +startinsert'
alias scratchmd='scratch -c "set ft=markdown"'
alias rscp='rsync -rlptDvzhP'
is_command pigz && alias gzip='pigz'
is_command pigz && alias zcat='pigz -cd'
is_command unpigz && alias gunzip='unpigz'

if is_command viman ; then
  alias man='LANG=C viman'
  compdef _man viman
else
  alias man='LANG=C man'
fi

alias sc=systemctl
alias scu="systemctl --user"
alias jc="journalctl --lines=30 --follow --unit"
alias jcu="journalctl --user --lines=30 --follow --unit"
alias pwgen="pwgen --capitalize --numerals --secure"
alias pw="pwgen 40 1"

alias lsblk="lsblk -o NAME,SIZE,UUID,FSTYPE,MOUNTPOINT,LABEL,MODEL"

alias gpgencrypt='gpg --encrypt-files'
alias gpgdecrypt='gpg --decrypt-files'

# }}}
# Network and web {{{

if is_command prettyping; then
    alias ping='prettyping --nolegend'
fi
alias localip="hostname -I | gawk '{print \$1}'"
alias tcp-listen="netstat --tcp --listen --numeric --program 2>/dev/null || netstat -an | grep LISTEN"
alias portcheck='nc -z -v -w 5'
is_command netstat && alias ports='netstat -tulanp'
is_command ss && alias ports='ss -tulanp'
is_command lynx && alias urls="lynx -nonumbers -listonly -dump"
alias ipv6_disable='sudo sysctl net.ipv6.conf.all.disable_ipv6=1'
alias ipv6_enable='sudo sysctl net.ipv6.conf.all.disable_ipv6=0'
alias aria2c-rpc="aria2c --enable-rpc"
if [ -f "$HOME/.config/chromium/Default/Cookies" ] ; then
    alias aria2c-cookies="aria2c --load-cookies='$HOME/.config/chromium/Default/Cookies'"
fi
if is_command python3; then
    alias httpserver='python3 -m http.server'
else
    alias httpserver='python -m SimpleHTTPServer'
fi

alias yd='yt-dlp'
alias yd-date='yd --download-archive=download-archive.log --playlist-reverse --ignore-errors --output="[%(playlist_autonumber)04d] %(upload_date)s - %(title)s-%(id)s.%(ext)s"'
alias yd-audio='yd --format bestaudio --embed-thumbnail --extract-audio --audio-format mp3'
alias yd-cb='xsel -bo | xargs yt-dlp'
alias yd-url='yd --flat-playlist --get-url'
is_command buku && alias b='buku --suggest'

# }}}
# Building tools and development {{{

alias k='kubectl'
alias make='make -j$(nproc)'
alias nicer='nice -n 15 ionice -c 2 -n 7 '
alias gco="git branch --sort=-committerdate | fzf --tiebreak=index | xargs git checkout"
alias gst="git status"
alias ghome='cd "$(git rev-parse --show-toplevel)"'
test -f ~/bin/pandoc-filter-includes.py && alias pdoc='pandoc --standalone --filter ~/bin/pandoc-filter-includes.py'
is_command pgcli && alias pgcli="pgcli --pgclirc ~/.config/pgcli/config --pgclirc ~/.config/pgcli/local.config"
alias pipr="pip3 install -r"
alias pipup="pip3 list --outdated | awk 'NR>2{print \$1}' | xargs --interactive pip3 install --no-cache-dir --upgrade"

function mvn-or-mvnw() {
    if [ -x ./mvnw ]; then
        echo "executing mvnw instead of mvn"
        ./mvnw "$@"
    else
        command mvn "$@"
    fi
}
alias mvn="mvn-or-mvnw"
compdef _mvn mvn-or-mvnw
compdef _mvn mvnd

# Docker and docker-compose
alias dbash='docker exec -it `docker ps -ql` bash'
alias dps='docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Names}}\t{{.Ports}}"'
alias drun='docker run -it --rm'
alias dlog='docker logs --tail 100 --follow'
alias dc='docker-compose'
alias dc-down='dc down --volumes --rmi local --remove-orphans'
alias dc-logs='dc logs --tail 100 --follow'
function dc-stats() {
    dc $@ ps -q | xargs --no-run-if-empty docker stats
}
function docker-save() {
    docker save "$1" | gzip > $(slugify "$1").tar.gz
}
alias docker-top='docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock moncho/dry'
alias docker-dive='docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock wagoodman/dive'

# }}}
# Package manager {{{

if is_command aptitude; then
    alias upa='sudo aptitude -u'
    alias apurge='sudo aptitude purge --purge-unused'
else
    alias up='sudo apt update; sudo apt upgrade'
    alias apurge='sudo apt purge'
fi

# }}}
# Calendar & tasks {{{

alias cal='ncal -Mb'
alias ta='task add'
alias task-no-spell='TW_IGNORE_SPELL=1 task'
if is_command remind; then
    alias remind="noglob remind -@ -m -b1"
    alias rem="noglob rem -@ -m -b1"
    alias rem1="rem -cu+1"
    alias rem2="rem -cu+2"
    alias tt="rem; task"
    alias tkremind="tkremind -m -b1"
    for day in {1..9} ; do
        alias $day="rem '*$day'"
    done

    remind-schedule() {
      remind -@ "${@:-*7}" | grep -vEe '^(No reminders\.|)$'
    }
    rem-schedule() {
      rem -@ "${@:-*7}" | grep -vEe '^(No reminders\.|)$'
    }
fi

# }}}
# Other and unsorted {{{

if is_command unoconv; then
    alias 2pdf='unoconv --format pdf'
elif is_command libreoffice; then
    alias 2pdf='libreoffice --headless --convert-to pdf'
fi
alias pdoc-pdf='pandoc -V fontenc=T2A -V geometry:margin=1in -V mainfont="Linux Libertine O"'
alias ocrmypdf='ocrmypdf --clean --deskew --rotate-pages'
alias ocrmypdf-rus='ocrmypdf --language rus'
alias ocrmypdf-eng='ocrmypdf --language eng'
alias ocrmypdf-rus-eng='ocrmypdf --language rus+eng'
alias ocrmypdf-swe-eng='ocrmypdf --language swe+eng'

alias display_off='xset dpms force off'
alias cclip='xclip -selection clipboard'
alias remove-colors='sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g"'
alias boot-log="sed 's/\^\[/\o33/g;s/\[1G\[/\[27G\[/' /var/log/boot | less -r"

# TLP

alias tlp-stat='sudo tlp-stat'
alias tlp-fullcharge='sudo tlp fullcharge BAT0; sudo tlp fullcharge BAT1'
alias tlp-setcharge='sudo tlp setcharge BAT0; sudo tlp setcharge BAT1'

# ZFS

alias zfs='sudo zfs'
alias zpool='sudo zpool'

# Exim
#alias exim-queue-list='sudo exim -bp'
#alias exim-queue-header='sudo exim -Mvh'
#alias exim-queue-body='sudo exim -Mvb'
#alias exim-queue-rm='sudo exim -Mrm'

# }}}
# Cleanup {{{

unfunction is_command

# }}}

# vim: et ft=zsh fdm=marker :