This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
S06_utils
58 lines (52 loc) · 1.62 KB
/
S06_utils
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
alias wzmv="noglob zmv -Wv"
function logify() {
gawk '{ print strftime("%Y-%m-%dT%H:%M:%S"), $0; fflush(); }'
}
alias -g ...='../..'
alias -g ....='../../..'
alias -g .....='../../../..'
alias rmpyc='find . -type f -name "*.pyc" -print0 | xargs -0 rm'
function indent() {
sed "s/^/ /"
}
srcgrep() {
find . ! -path '*/.git/*' \
! -path '*myTrash*' \
! -path '*deps*' \
\( -name '*.py' -or -name '*.c' -or -name '*.html' -or -name '*.json' \) \
-type f -exec egrep -I --color=auto -H "$@" {} \;
}
srcgreped() {
vim -p $(srcgrep "$@" | cut -f1 -d: | sort -u)
}
gentoken() {
if [ -z "$1" ]; then
local hexchars=12
else
local hexchars=$1
fi
dd if=/dev/urandom bs=32 count=1 2>/dev/null | md5sum | cut -c1-$hexchars | # generate random hex chars
tr -d '\n' | # remove newline or cpcopy will copy the newline
(( cpcopy ) 2>/dev/null || cut -c1- ) # if cpcopy exists, copy to clipboard, else use cut to revive the newline
( cppaste | cut -c1- ) 2> /dev/null || true # if cppaste exists, paste what you just copied, else do nothing
}
if [ -n "$_GOT_CLIPBOARD" ]; then
alias -g cptee='cpcopy ; cppaste'
fi
function and_notify() {
local message
if [ "$1" = "-m" ]; then
shift
message="$1"
shift
fi
if "$@"; then
[ -z "$message" ] && message="$1 succeeded"
local sound="~/.zsh.d/static/sounds/information.ogg"
else
[ -z "$message" ] && message="$1 failed"
local sound="~/.zsh.d/static/sounds/error.ogg"
fi
ui-notify "$message"
audio-play "$sound"
}