-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutilities.zsh
44 lines (39 loc) · 1.59 KB
/
utilities.zsh
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
# utility functions
## calculator
calc() {
if [ -n "$1" ]; then
node -e "console.log( ($@).toFixed(2) )"
else
octave -q
fi
}
calcd() {
node -e "console.log($@)"
}
alias calculator='python -ic "from __future__ import division; from math import *; from random import *"' # for multiple calculations, interactive
## url en/decode
alias urlencode='node -e "console.log( encodeURIComponent( process.argv[1] ) )"'
alias urldecode='node -e "console.log( decodeURIComponent( process.argv[1] ) )"'
## generate a random number
alias randomnum="shuf -n 1 -i" # As range: 1-100
alias dice="W $(whence randomnum) 1-6"
## grep
_in() {
if command -v rg >/dev/null; then
rg -M 800 --hidden --glob='!.git/' --glob '!git/' --glob '!node_modules/' --glob '!.cache' --glob '!vendor/' --glob '!teams-for-linux/' --glob '!.local/lib' --glob '!.local/share/*/' --glob '!BraveSoftware/' --glob '!chromium' --glob '!chrome/' --glob '!firefox/' --glob '!Signal' --glob '!.ib-tws/' --glob '!.java/' --glob '!.hwid' --glob '!.zcompcache' --glob '!tmp/' --glob='!ct/manga' --glob='!ct/comics' --glob='!dotfiles/' -g='!coverage' -g='!dist/' -g='!build/' -g='!.srt' -g='!.cargo/' -g='!.html' "$@" 2>/dev/null
else
grep --line-number --with-filename --no-messages --recursive --exclude-dir=node_modules --exclude-dir=coverage --exclude-dir=dist --exclude-dir=vendor --exclude=package-lock.json "$@"
# short: grep -nHsr
fi
}
in() {
if [ -z "$2" ]; then
_in "$1" .
else
_in "$@"
fi
}
## ps
pst() {
ps xwjf | awk '{ $1="";$3="";$4="";$5="";$6="";$7="";$8="";$9=""; print $0 }' | grep -v 'firefox-' | less
}