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