about summary refs log tree commit diff
path: root/sh/snippets
blob: 25e2f0474aaf2e4cf86a522fc6e6db0608d01ae1 (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
#!/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"

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

# need to pass password through pipe to not show in ps
# another way is use `grep -f-` to read pattern from stdin, but it is hard to specify filenames with spaces that way, `grep ... $(find ... | printf %q ...)` somehow thinks 'a b' as two files 'a and b', e.g., This DOES NOT WORK: `pass albiononline.com | { IFS= read -r p; printf '%s' "$p";} | grep --color=auto -IR -f- $(find . -type d \( -iname '*sandbox*interactive*' -o -iname '*albion*' \) -print0 | xargs -0 printf '%q ')`, not sure why
{
	pass albiononline.com | { IFS= read -r p; printf '%s\0' "$p";}
	find "$HOME" -type d \( -iname '*sandbox*interactive*' -o -iname '*albion*' \) -print0
} | xargs -0 grep --color=auto -IRF