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