Commit | Line | Data |
---|---|---|
e0dbdb36 SK |
1 | # |
2 | ||
3 | d() { | |
4 | local -r word=$(fzf < /usr/share/dict/words) | |
5 | dict "$word" | |
6 | } | |
7 | ||
c7de24d9 | 8 | # Top Disk-Using directories |
58bdbfbf | 9 | # TODO: Consider using numfmt instead of awk |
c7de24d9 SK |
10 | tdu() { |
11 | du "$1" \ | |
6b543680 | 12 | | sort -n -k 1 -r \ |
c7de24d9 SK |
13 | | head -50 \ |
14 | | awk ' | |
15 | { | |
16 | size = $1 | |
17 | path = $0 | |
18 | sub("^" $1 "\t+", "", path) | |
19 | gb = size / 1024 / 1024 | |
20 | printf("%f\t%s\n", gb, path) | |
21 | }' \ | |
22 | | cut -c 1-115 | |
23 | } | |
24 | ||
27456eb6 SK |
25 | # Top Disk-Using Files |
26 | tduf() { | |
27 | find "$1" -type f -printf '%s\t%p\0' \ | |
28 | | sort -z -n -k 1 -r \ | |
29 | | head -z -n 50 \ | |
30 | | gawk -v RS='\0' ' | |
31 | { | |
32 | size = $1 | |
33 | path = $0 | |
34 | sub("^" $1 "\t+", "", path) | |
35 | gb = size / 1024 / 1024 / 1024 | |
36 | printf("%f\t%s\n", gb, path) | |
37 | }' | |
38 | } | |
39 | ||
909ece30 SK |
40 | # Most-recently modified file system objects |
41 | recent() { | |
68992a1d SK |
42 | # NOTES: |
43 | # - intentionally not quoting the parameters, so that some can be ignored | |
44 | # if not passed, rather than be passed to find as an empty string; | |
45 | # - %T+ is a GNU extension; | |
46 | # - gawk is able to split records on \0, while awk cannot. | |
909ece30 | 47 | find $@ -printf '%T@ %T+ %p\0' \ |
68992a1d | 48 | | tee >(gawk -v RS='\0' 'END { printf("[INFO] Total found: %d\n", NR); }') \ |
909ece30 SK |
49 | | sort -z -k 1 -n -r \ |
50 | | head -n "$(stty size | awk 'NR == 1 {print $1 - 5}')" -z \ | |
51 | | gawk -v RS='\0' ' | |
52 | { | |
53 | sub("^" $1 " +", "") # Remove epoch time | |
54 | sub("+", " ") # Blank-out the default separator | |
55 | sub("\\.[0-9]+", "") # Remove fractional seconds | |
56 | ||
57 | }' | |
909ece30 SK |
58 | } |
59 | ||
60 | recent_dirs() { | |
61 | recent "$1" -type d | |
62 | } | |
63 | ||
64 | recent_files() { | |
65 | recent "$1" -type f | |
66 | } | |
67 | ||
c7de24d9 SK |
68 | pa_def_sink() { |
69 | pactl info | awk '/^Default Sink:/ {print $3}' | |
70 | } | |
71 | ||
72 | void_pkgs() { | |
73 | curl "https://xq-api.voidlinux.org/v1/query/x86_64?q=$1" | jq '.data' | |
74 | } | |
75 | ||
76 | # Colorful man | |
77 | man() { | |
78 | LESS_TERMCAP_md=$'\e[01;31m' \ | |
79 | LESS_TERMCAP_me=$'\e[0m' \ | |
80 | LESS_TERMCAP_se=$'\e[0m' \ | |
81 | LESS_TERMCAP_so=$'\e[01;44;33m' \ | |
82 | LESS_TERMCAP_ue=$'\e[0m' \ | |
83 | LESS_TERMCAP_us=$'\e[01;32m' \ | |
84 | command man "$@" | |
85 | } | |
64ec9f23 SK |
86 | |
87 | experiment() { | |
9e4c43c0 | 88 | cd "$(~/bin/experiment $@)" || exit 1 |
64ec9f23 | 89 | } |
801dd7bd SK |
90 | |
91 | hump() { | |
2e8cf226 | 92 | ledit -l "$(stty size | awk '{print $2}')" ocaml $@ |
801dd7bd | 93 | } |
632b7c4a SK |
94 | |
95 | howto() { | |
0136ca23 | 96 | cat "$(find ~/Archives/Documents/HOWTOs -mindepth 1 -maxdepth 1 | sort | fzf)" |
632b7c4a | 97 | } |
f4e0bb58 | 98 | |
60e43329 SK |
99 | yt() { |
100 | local _yt_uri | |
101 | local _yt_id | |
102 | local _yt_title | |
103 | local _yt_dir | |
104 | ||
105 | _yt_uri="$1" | |
106 | _yt_id=$(youtube-dl --get-id "$_yt_uri") | |
107 | _yt_title=$(youtube-dl --get-title "$_yt_uri") | |
108 | _yt_dir="${DIR_YOUTUBE}/individual-videos/${_yt_title}--${_yt_id}" | |
109 | ||
110 | mkdir -p "$_yt_dir" | |
111 | cd "$_yt_dir" || exit 1 | |
112 | echo "$_yt_uri" > 'uri' | |
113 | youtube-dl -c --write-description --write-info-json "$_yt_uri" | |
114 | } | |
115 | ||
f4e0bb58 SK |
116 | gh_fetch_repos() { |
117 | curl "https://api.github.com/$1/$2/repos?page=1&per_page=10000" | |
118 | } | |
119 | ||
120 | gh_clone() { | |
8aa18398 SK |
121 | gh_user_type="$1" |
122 | gh_user_name="$2" | |
123 | gh_dir="${DIR_GITHUB}/${gh_user_name}" | |
124 | mkdir -p "$gh_dir" | |
125 | cd "$gh_dir" || exit 1 | |
126 | gh_fetch_repos "$gh_user_type" "$gh_user_name" \ | |
f4e0bb58 SK |
127 | | jq --raw-output '.[] | select(.fork | not) | .git_url' \ |
128 | | parallel -j 25 \ | |
129 | git clone {} | |
130 | } | |
131 | ||
132 | gh_clone_user() { | |
133 | gh_clone 'users' "$1" | |
134 | } | |
135 | ||
136 | gh_clone_org() { | |
137 | gh_clone 'orgs' "$1" | |
138 | } | |
e09a8d5a | 139 | |
610785ef SK |
140 | gh_clone_repo() { |
141 | gh_username=$(echo "$1" | awk -F / '"$1 == "https" && $3 == github.com" {print $4}') | |
8aa18398 | 142 | gh_dir="${DIR_GITHUB}/${gh_username}" |
610785ef SK |
143 | mkdir -p "$gh_dir" |
144 | cd "$gh_dir" || exit 1 | |
145 | git clone "$1" | |
610785ef SK |
146 | } |
147 | ||
c45bdb58 SK |
148 | work_log_template() { |
149 | cat << EOF | |
d8da04c5 | 150 | $(date '+%F %A') |
c45bdb58 SK |
151 | ========== |
152 | ||
153 | Morning report | |
154 | -------------- | |
155 | ||
c44fbbc2 | 156 | ### Previous |
c45bdb58 | 157 | |
c44fbbc2 | 158 | ### Current |
c45bdb58 SK |
159 | |
160 | ### Blockers | |
161 | ||
162 | Day's notes | |
163 | ----------- | |
164 | EOF | |
165 | } | |
166 | ||
167 | work_log() { | |
168 | mkdir -p "$DIR_WORK_LOG" | |
169 | file_work_log_today="${DIR_WORK_LOG}/$(date +%F).md" | |
170 | if [ ! -f "$file_work_log_today" ] | |
171 | then | |
172 | work_log_template > "$file_work_log_today" | |
173 | fi | |
3008cd51 | 174 | vim -c 'set spell' "$file_work_log_today" |
c45bdb58 SK |
175 | |
176 | } | |
177 | ||
065977fd SK |
178 | note() { |
179 | mkdir -p "$DIR_NOTES" | |
3008cd51 | 180 | vim -c 'set spell' "$DIR_NOTES/$(date +'%Y_%m_%d--%H_%M_%S%z')--$1.md" |
065977fd SK |
181 | } |
182 | ||
e09a8d5a SK |
183 | weather() { |
184 | curl "http://wttr.in/$WEATHER_LOCATION" | |
185 | } | |
2c0865d1 SK |
186 | |
187 | bt_devs_paired() { | |
188 | bluetoothctl -- paired-devices \ | |
189 | | awk '{print $2}' \ | |
190 | | xargs bluetoothctl -- info | |
191 | } | |
192 | ||
193 | bt_devs() { | |
194 | bluetoothctl -- devices \ | |
195 | | awk '{print $2}' \ | |
196 | | xargs bluetoothctl -- info | |
197 | } | |
dfbaafa4 SK |
198 | |
199 | run() { | |
200 | stderr="$(mktemp)" | |
201 | $@ 2> >(tee "$stderr") | |
202 | code="$?" | |
203 | urgency='' | |
204 | case "$code" in | |
205 | 0) urgency='normal';; | |
206 | *) urgency='critical' | |
207 | esac | |
208 | notify-send -u "$urgency" "Job done: $code" "$(cat $stderr)" | |
209 | rm "$stderr" | |
210 | } |