Organize into home and system directories
[khome.git] / home / lib / login_functions.sh
1 # Top Disk-Using directories
2 # TODO: Consider using numfmt instead of awk
3 tdu() {
4 du "$1" \
5 | sort -n -k 1 -r --parallel="$(nproc)" \
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
18 # Most-recently modified file system objects
19 recent() {
20 # NOTES:
21 # - intentionally not quoting the parameters, so that some can be ignored
22 # if not passed, rather than be passed to find as an empty string;
23 # - %T+ is a GNU extension;
24 # - gawk is able to split records on \0, while awk cannot.
25 find $@ -printf '%T@ %T+ %p\0' \
26 | tee >(gawk -v RS='\0' 'END { printf("[INFO] Total found: %d\n", NR); }') \
27 | sort -z -k 1 -n -r \
28 | head -n "$(stty size | awk 'NR == 1 {print $1 - 5}')" -z \
29 | gawk -v RS='\0' '
30 {
31 sub("^" $1 " +", "") # Remove epoch time
32 sub("+", " ") # Blank-out the default separator
33 sub("\\.[0-9]+", "") # Remove fractional seconds
34 print
35 }'
36 }
37
38 recent_dirs() {
39 recent "$1" -type d
40 }
41
42 recent_files() {
43 recent "$1" -type f
44 }
45
46 pa_def_sink() {
47 pactl info | awk '/^Default Sink:/ {print $3}'
48 }
49
50 void_pkgs() {
51 curl "https://xq-api.voidlinux.org/v1/query/x86_64?q=$1" | jq '.data'
52 }
53
54 # Colorful man
55 man() {
56 LESS_TERMCAP_md=$'\e[01;31m' \
57 LESS_TERMCAP_me=$'\e[0m' \
58 LESS_TERMCAP_se=$'\e[0m' \
59 LESS_TERMCAP_so=$'\e[01;44;33m' \
60 LESS_TERMCAP_ue=$'\e[0m' \
61 LESS_TERMCAP_us=$'\e[01;32m' \
62 command man "$@"
63 }
64
65 experiment() {
66 cd "$(~/bin/experiment $@)" || exit 1
67 }
68
69 hump() {
70 ledit -l $(stty size | awk '{print $2}') ocaml $@
71 }
72
73 howto() {
74 cat "$(find ~/Archives/Documents/HOWTOs -mindepth 1 -maxdepth 1 | sort | fzf)"
75 }
76
77 gh_fetch_repos() {
78 curl "https://api.github.com/$1/$2/repos?page=1&per_page=10000"
79 }
80
81 gh_clone() {
82 gh_fetch_repos "$1" "$2" \
83 | jq --raw-output '.[] | select(.fork | not) | .git_url' \
84 | parallel -j 25 \
85 git clone {}
86 }
87
88 gh_clone_user() {
89 gh_clone 'users' "$1"
90 }
91
92 gh_clone_org() {
93 gh_clone 'orgs' "$1"
94 }
95
96 gh_clone_repo() {
97 gh_username=$(echo "$1" | awk -F / '"$1 == "https" && $3 == github.com" {print $4}')
98 gh_dir="${HOME}/Archives/Software/src/repos/remote/github.com/${gh_username}"
99 mkdir -p "$gh_dir"
100 cd "$gh_dir" || exit 1
101 git clone "$1"
102 cd - || exit 1
103 }
104
105 work_log_template() {
106 cat << EOF
107 $(date +%F)
108 ==========
109
110 Morning report
111 --------------
112
113 ### Previous
114
115 ### Current
116
117 ### Blockers
118
119 Day's notes
120 -----------
121 EOF
122 }
123
124 work_log() {
125 mkdir -p "$DIR_WORK_LOG"
126 file_work_log_today="${DIR_WORK_LOG}/$(date +%F).md"
127 if [ ! -f "$file_work_log_today" ]
128 then
129 work_log_template > "$file_work_log_today"
130 fi
131 vim "$file_work_log_today"
132
133 }
134
135 weather() {
136 curl "http://wttr.in/$WEATHER_LOCATION"
137 }
138
139 bt_devs_paired() {
140 bluetoothctl -- paired-devices \
141 | awk '{print $2}' \
142 | xargs bluetoothctl -- info
143 }
144
145 bt_devs() {
146 bluetoothctl -- devices \
147 | awk '{print $2}' \
148 | xargs bluetoothctl -- info
149 }
This page took 0.097419 seconds and 5 git commands to generate.