-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
functionrc
143 lines (126 loc) · 4.38 KB
/
functionrc
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
#!/bin/bash
p() { sudo pacman "$@"; notify-pacman-block; }
see() {
choice="$(find ~/.local/bin -mindepth 1 -printf '%P\n' | fzf)"
[ -f "$HOME/.local/bin/$choice" ] && $EDITOR "$HOME/.local/bin/$choice"
}
vf() { find . -type f | fzf | xargs -r -I % "$EDITOR" % ;}
calc() { awk "BEGIN{ print $* }" ;}
kitsudown() { curl "$@" | grep -Eo 'subtitles[^"]+\.(srt|ass)' | xargs -n 1 -P 26 -I{} wget --no-clobber 'http://kitsunekko.net/{}' ;}
cheat() { curl "cheat.sh/$*" ;}
zman() { man -Tpdf "$*" | setsid -f zathura -; }
choose_from_cwds() {
for PROCID in $(pgrep -u "$USER" "^${SHELL##*/}$|^lf$|^ranger$"); do
readlink -e "/proc/$PROCID/cwd"
done | sort -u | fzf
}
humantime() { date -d "@$1" ;}
wait-notify() {
sleep "$@"
setsid -f notify-send -t 0 --icon alarm-timer "Timer ended" "$* passed"
setsid -f paplay /usr/share/sounds/freedesktop/stereo/complete.oga
}
massrename() {
# Renames all files in the current folder according to this pattern: 1669303368162.ext
local new=""
local -r localtime=$(date '+%s')
for file in ./*.*; do
if [[ -f $file ]] && ! [[ $(basename -- "${file%.*}") =~ ^[0-9]{13,16}$ ]]; then
while [[ -z $new ]] || [[ -f $new ]]; do
new=${localtime}$( printf -- '%03d\n' "$(shuf -i 0-999 -n 1)" ).${file##*.}
done
mv -n -- "$file" "$new"
fi
done
}
# Rsync shortcuts
rsync_a() { rsync -rltv --delete "$@" ;}
rsync_fat() { rsync_a --modify-window=1 "$@" ;}
# Check the weather. Run 'curl wttr.in/:help' for more options.
weath() { curlwttr "${1-$LOCATION}?M$([ "$COLUMNS" -lt 125 ] && echo n)" ;}
cweath() { curlwttr "${1-$LOCATION}?0M" ;}
# Install an AUR package manually (for Parabola to get AUR access)
aurinstall() { curl -O "https://aur.archlinux.org/cgit/aur.git/snapshot/$1.tar.gz" && tar -xvf "$1.tar.gz" && cd "$1" && makepkg --noconfirm -si && cd .. && rm -rf "$1" "$1.tar.gz"; }
# Uninstall all packages no longer required as dependencies (orphans)
remorphans() {
local packages=()
for package in $(pacman -Qdtq); do
packages+=("$package")
done
echo "Found ${#packages[*]} orphans."
if ! [[ ${#packages[*]} -eq 0 ]]; then
sudo pacman -Rns "${packages[@]}"
fi
}
# Readme
readme() {
for readme in {readme,README}.{md,MD,markdown,txt,TXT,mkd}; do
if [[ -f "$readme" ]]; then
less "$readme"
fi
done
}
# Full system backup
# https://wiki.archlinux.org/index.php/Rsync#Full_system_backup
backup_everything() {
if mount -l | grep -F "/mnt/system_backup"; then
sudo rsync -aAXvHS --delete --info=progress2 --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/home/*/.thumbnails/*","/home/*/.cache/*","/home/*/.local/share/Trash/*","/home/*/.gvfs","/var/cache/pacman/pkg/*"} / /mnt/system_backup
fi
}
# Test different versions of Anki
anki_test_install() {
local -r version=${1:?No version provided.}
local -r dir=~/.local/share/anki_builds/"anki_$version"
(
mkdir -p -- "$dir" && cd -- "$dir" || exit
python -m venv --system-site-packages pyenv
./pyenv/bin/pip3 install --upgrade pip
./pyenv/bin/pip3 install --upgrade --pre "aqt==$version"
)
}
anki_test_run() {
local -r dir=~/.local/share/anki_builds
if [[ $* ]]; then
local -r choice=$*
else
local -r choice=$(find "$dir" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | dmenu)
fi
if [[ -n $choice ]]; then
(cd -- "$dir/$choice" && ./pyenv/bin/anki)
fi
}
sitedl() {
local -r url=$1 domain=$2
wget -e robots=off \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
--domains "$domain" \
--no-parent "$url"
}
all_but_base() {
local -r basepac=$(pacman -Qi base-devel base | grep -Fi 'depends on' | cut -d: -f2 | tr ' ' '\n')
comm -23 <(pacman -Qetq | sort -u) <(echo "$basepac" | sort -u) | less
}
silenceremove() {
ffmpeg \
-i "${1:?Input is not set}" \
-af silenceremove=stop_periods=-1:stop_duration=0.3:stop_threshold=-50dB \
-c:a libopus \
"${2:?Output is not set}"
}
my_mecab() {
local -r support_dir=$(dirname -- "$(find /usr/lib/mecab/dic/mecab-ipadic-neologd /usr/lib/mecab/dic ~/.local/share/Anki2/addons21 -type f -name dicrc -print -quit)")
local -r user_dic=$(find "$support_dir" -type f -name "user_dic.dic")
local -a command=(mecab -d "$support_dir" "$@")
[[ -f $user_dic ]] && command+=(-u "$user_dic")
"${command[@]}"
}
bfg_strip_blobs() {
bfg --strip-blobs-bigger-than "${1:-200K}"
git reflog expire --expire=now --all
git gc --prune=now --aggressive
}