about summary refs log tree commit diff
path: root/sh/snippets
blob: 00b109ed5406cb9d4092c23c961e9d323267a5d1 (plain)
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
#!/bin/sh
# misc code snippets

for cmd in pacdiff 'tree -a'; do
	alias ${cmd%% *}="sudo -E $cmd"
done

if [ -e "$XDG_PICTURES_DIR/wallpapers/wallpaper" ]; then
	display -window root "$XDG_PICTURES_DIR/wallpapers/wallpaper" &
else
	shufwall &
fi

# ~/.config/nsxiv/exec/key-handler
case "$1" in
	"l") linkwall ;;
	"w") tr '\n' '\0' | xargs -0 shufwall ;;
esac
linkwall() {
	tr '\n' '\0' | xargs -0 realpath | sort | uniq | while read -r file; do
		walldir="$XDG_PICTURES_DIR/wallpapers/"
		name=$(basename "$file")
		if [ ! -e "$walldir$name" ]; then
			convwall "$file" "$walldir$name" || ln -s "$file" "$walldir" 
		else
			notify-send 'error' "$name exist"
		fi
	done
}

for cmd in czkawka_gui firefox freecad gimp krita mpv qmmp songrec zathura; do
	alias $cmd="o $cmd"
done

pidof -q monerod || alacritty -e monerod

f () {
	while read -r site; do
		curl -sm5 "$site" | grep -iq "creative common\|cc-by\|cc-0\|gnu free documentation license\|gfdl\|unlicense\|wtfpl" && echo "$site"
	done
}
f < ~/downloads/blogs > ~/downloads/cc_blogs
f < ~/downloads/news > ~/downloads/cc_news

# parallel seems mess up rsync second argument's dir name's spaces, cause incorrect dir name. Bug? I choose to use xargs instead
# maybe I should use parallel's --transfer or --transferfile options?
#{ ssh-add -l || ssh-add;} && parallel -v -j2 -- rsync -vP {} '/home/xyz/a b' << EOF
{ ssh-add -l || ssh-add;} && xargs -P2 -I {} rsync -vP '{}' '/home/xyz/a b' << EOF
ka:/home/xyz/a b/c d
ka:/home/xyz/a b/c d
EOF

# use cd to workaround monero-blockchain-export.log log file save in current dir? issue, haven't tested
cd "$HOME/.bitmonero" || exit
monero-blockchain-export --output-file "$XDG_DOWNLOAD_DIR/xmr/monero_blockchain.raw"

# the old way, slower and more code
#nm_device_state="$(nmcli -t --fields device,state device)"
#if echo "$nm_device_state" | grep -q '^wg_ka:connected$'; then
#       echo ka
#elif echo "$nm_device_state" | grep -q '^wg_studio:connected$'; then
#       echo studio
#else
#       echo insp
#fi
case "$(nmcli -t --fields device,state device)" in
	*wg_ia:connected*) echo ia;;
	*wg_ka:connected*) echo ka;;
	*wg_studio:connected*) echo studio;;
	*) echo insp;;
esac
printf 'default: '; curl -m1 ifconfig.co
printf '4: '; curl -4m1 ifconfig.co
printf '6: '; curl -6m1 ifconfig.co

find "$HOME/archive/music" -type f -name '*.wav' -execdir sh -c '
	for i; do
		ffmpeg -i "$i" "$i.flac" && rm "$i"
	done
' sh '{}' \+