Remind myself to use a specializes startx
[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" \
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() {
68992a1d
SK
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.
909ece30 25 find $@ -printf '%T@ %T+ %p\0' \
68992a1d 26 | tee >(gawk -v RS='\0' 'END { printf("[INFO] Total found: %d\n", NR); }') \
909ece30
SK
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 }'
909ece30
SK
36}
37
38recent_dirs() {
39 recent "$1" -type d
40}
41
42recent_files() {
43 recent "$1" -type f
44}
45
c7de24d9
SK
46pa_def_sink() {
47 pactl info | awk '/^Default Sink:/ {print $3}'
48}
49
50void_pkgs() {
51 curl "https://xq-api.voidlinux.org/v1/query/x86_64?q=$1" | jq '.data'
52}
53
54# Colorful man
55man() {
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}
64ec9f23
SK
64
65experiment() {
9e4c43c0 66 cd "$(~/bin/experiment $@)" || exit 1
64ec9f23 67}
801dd7bd
SK
68
69hump() {
70 ledit -l $(stty size | awk '{print $2}') ocaml $@
71}
632b7c4a
SK
72
73howto() {
0136ca23 74 cat "$(find ~/Archives/Documents/HOWTOs -mindepth 1 -maxdepth 1 | sort | fzf)"
632b7c4a 75}
f4e0bb58
SK
76
77gh_fetch_repos() {
78 curl "https://api.github.com/$1/$2/repos?page=1&per_page=10000"
79}
80
81gh_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
88gh_clone_user() {
89 gh_clone 'users' "$1"
90}
91
92gh_clone_org() {
93 gh_clone 'orgs' "$1"
94}
e09a8d5a 95
610785ef
SK
96gh_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
c45bdb58
SK
105work_log_template() {
106cat << EOF
107$(date +%F)
108==========
109
110Morning report
111--------------
112
c44fbbc2 113### Previous
c45bdb58 114
c44fbbc2 115### Current
c45bdb58
SK
116
117### Blockers
118
119Day's notes
120-----------
121EOF
122}
123
124work_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
e09a8d5a
SK
135weather() {
136 curl "http://wttr.in/$WEATHER_LOCATION"
137}
2c0865d1
SK
138
139bt_devs_paired() {
140 bluetoothctl -- paired-devices \
141 | awk '{print $2}' \
142 | xargs bluetoothctl -- info
143}
144
145bt_devs() {
146 bluetoothctl -- devices \
147 | awk '{print $2}' \
148 | xargs bluetoothctl -- info
149}
This page took 0.031792 seconds and 4 git commands to generate.