Add functions: recent, recent_dirs, recent_files
[khome.git] / 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" \
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
909ece30
SK
18# Most-recently modified file system objects
19recent() {
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
36recent_dirs() {
37 recent "$1" -type d
38}
39
40recent_files() {
41 recent "$1" -type f
42}
43
c7de24d9
SK
44pa_def_sink() {
45 pactl info | awk '/^Default Sink:/ {print $3}'
46}
47
48void_pkgs() {
49 curl "https://xq-api.voidlinux.org/v1/query/x86_64?q=$1" | jq '.data'
50}
51
52# Colorful man
53man() {
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}
64ec9f23
SK
62
63experiment() {
9e4c43c0 64 cd "$(~/bin/experiment $@)" || exit 1
64ec9f23 65}
801dd7bd
SK
66
67hump() {
68 ledit -l $(stty size | awk '{print $2}') ocaml $@
69}
632b7c4a
SK
70
71howto() {
0136ca23 72 cat "$(find ~/Archives/Documents/HOWTOs -mindepth 1 -maxdepth 1 | sort | fzf)"
632b7c4a 73}
f4e0bb58
SK
74
75gh_fetch_repos() {
76 curl "https://api.github.com/$1/$2/repos?page=1&per_page=10000"
77}
78
79gh_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
86gh_clone_user() {
87 gh_clone 'users' "$1"
88}
89
90gh_clone_org() {
91 gh_clone 'orgs' "$1"
92}
e09a8d5a 93
c45bdb58
SK
94work_log_template() {
95cat << EOF
96$(date +%F)
97==========
98
99Morning report
100--------------
101
c44fbbc2 102### Previous
c45bdb58 103
c44fbbc2 104### Current
c45bdb58
SK
105
106### Blockers
107
108Day's notes
109-----------
110EOF
111}
112
113work_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
e09a8d5a
SK
124weather() {
125 curl "http://wttr.in/$WEATHER_LOCATION"
126}
2c0865d1
SK
127
128bt_devs_paired() {
129 bluetoothctl -- paired-devices \
130 | awk '{print $2}' \
131 | xargs bluetoothctl -- info
132}
133
134bt_devs() {
135 bluetoothctl -- devices \
136 | awk '{print $2}' \
137 | xargs bluetoothctl -- info
138}
This page took 0.028668 seconds and 4 git commands to generate.