Add gh_clone_repo function
[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 gh_clone_repo() {
95 gh_username=$(echo "$1" | awk -F / '"$1 == "https" && $3 == github.com" {print $4}')
96 gh_dir="${HOME}/Archives/Software/src/repos/remote/github.com/${gh_username}"
97 mkdir -p "$gh_dir"
98 cd "$gh_dir" || exit 1
99 git clone "$1"
100 cd - || exit 1
101 }
102
103 work_log_template() {
104 cat << EOF
105 $(date +%F)
106 ==========
107
108 Morning report
109 --------------
110
111 ### Previous
112
113 ### Current
114
115 ### Blockers
116
117 Day's notes
118 -----------
119 EOF
120 }
121
122 work_log() {
123 mkdir -p "$DIR_WORK_LOG"
124 file_work_log_today="${DIR_WORK_LOG}/$(date +%F).md"
125 if [ ! -f "$file_work_log_today" ]
126 then
127 work_log_template > "$file_work_log_today"
128 fi
129 vim "$file_work_log_today"
130
131 }
132
133 weather() {
134 curl "http://wttr.in/$WEATHER_LOCATION"
135 }
136
137 bt_devs_paired() {
138 bluetoothctl -- paired-devices \
139 | awk '{print $2}' \
140 | xargs bluetoothctl -- info
141 }
142
143 bt_devs() {
144 bluetoothctl -- devices \
145 | awk '{print $2}' \
146 | xargs bluetoothctl -- info
147 }
This page took 0.10413 seconds and 5 git commands to generate.