| 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 | # Top Disk-Using Files |
| 19 | tduf() { |
| 20 | find "$1" -type f -printf '%s\t%p\0' \ |
| 21 | | sort -z -n -k 1 -r \ |
| 22 | | head -z -n 50 \ |
| 23 | | gawk -v RS='\0' ' |
| 24 | { |
| 25 | size = $1 |
| 26 | path = $0 |
| 27 | sub("^" $1 "\t+", "", path) |
| 28 | gb = size / 1024 / 1024 / 1024 |
| 29 | printf("%f\t%s\n", gb, path) |
| 30 | }' |
| 31 | } |
| 32 | |
| 33 | # Most-recently modified file system objects |
| 34 | recent() { |
| 35 | # NOTES: |
| 36 | # - intentionally not quoting the parameters, so that some can be ignored |
| 37 | # if not passed, rather than be passed to find as an empty string; |
| 38 | # - %T+ is a GNU extension; |
| 39 | # - gawk is able to split records on \0, while awk cannot. |
| 40 | find $@ -printf '%T@ %T+ %p\0' \ |
| 41 | | tee >(gawk -v RS='\0' 'END { printf("[INFO] Total found: %d\n", NR); }') \ |
| 42 | | sort -z -k 1 -n -r \ |
| 43 | | head -n "$(stty size | awk 'NR == 1 {print $1 - 5}')" -z \ |
| 44 | | gawk -v RS='\0' ' |
| 45 | { |
| 46 | sub("^" $1 " +", "") # Remove epoch time |
| 47 | sub("+", " ") # Blank-out the default separator |
| 48 | sub("\\.[0-9]+", "") # Remove fractional seconds |
| 49 | print |
| 50 | }' |
| 51 | } |
| 52 | |
| 53 | recent_dirs() { |
| 54 | recent "$1" -type d |
| 55 | } |
| 56 | |
| 57 | recent_files() { |
| 58 | recent "$1" -type f |
| 59 | } |
| 60 | |
| 61 | pa_def_sink() { |
| 62 | pactl info | awk '/^Default Sink:/ {print $3}' |
| 63 | } |
| 64 | |
| 65 | void_pkgs() { |
| 66 | curl "https://xq-api.voidlinux.org/v1/query/x86_64?q=$1" | jq '.data' |
| 67 | } |
| 68 | |
| 69 | # Colorful man |
| 70 | man() { |
| 71 | LESS_TERMCAP_md=$'\e[01;31m' \ |
| 72 | LESS_TERMCAP_me=$'\e[0m' \ |
| 73 | LESS_TERMCAP_se=$'\e[0m' \ |
| 74 | LESS_TERMCAP_so=$'\e[01;44;33m' \ |
| 75 | LESS_TERMCAP_ue=$'\e[0m' \ |
| 76 | LESS_TERMCAP_us=$'\e[01;32m' \ |
| 77 | command man "$@" |
| 78 | } |
| 79 | |
| 80 | experiment() { |
| 81 | cd "$(~/bin/experiment $@)" || exit 1 |
| 82 | } |
| 83 | |
| 84 | hump() { |
| 85 | ledit -l "$(stty size | awk '{print $2}')" ocaml $@ |
| 86 | } |
| 87 | |
| 88 | howto() { |
| 89 | cat "$(find ~/Archives/Documents/HOWTOs -mindepth 1 -maxdepth 1 | sort | fzf)" |
| 90 | } |
| 91 | |
| 92 | gh_fetch_repos() { |
| 93 | curl "https://api.github.com/$1/$2/repos?page=1&per_page=10000" |
| 94 | } |
| 95 | |
| 96 | gh_clone() { |
| 97 | gh_user_type="$1" |
| 98 | gh_user_name="$2" |
| 99 | gh_dir="${DIR_GITHUB}/${gh_user_name}" |
| 100 | mkdir -p "$gh_dir" |
| 101 | cd "$gh_dir" || exit 1 |
| 102 | gh_fetch_repos "$gh_user_type" "$gh_user_name" \ |
| 103 | | jq --raw-output '.[] | select(.fork | not) | .git_url' \ |
| 104 | | parallel -j 25 \ |
| 105 | git clone {} |
| 106 | } |
| 107 | |
| 108 | gh_clone_user() { |
| 109 | gh_clone 'users' "$1" |
| 110 | } |
| 111 | |
| 112 | gh_clone_org() { |
| 113 | gh_clone 'orgs' "$1" |
| 114 | } |
| 115 | |
| 116 | gh_clone_repo() { |
| 117 | gh_username=$(echo "$1" | awk -F / '"$1 == "https" && $3 == github.com" {print $4}') |
| 118 | gh_dir="${DIR_GITHUB}/${gh_username}" |
| 119 | mkdir -p "$gh_dir" |
| 120 | cd "$gh_dir" || exit 1 |
| 121 | git clone "$1" |
| 122 | } |
| 123 | |
| 124 | work_log_template() { |
| 125 | cat << EOF |
| 126 | $(date +%F) |
| 127 | ========== |
| 128 | |
| 129 | Morning report |
| 130 | -------------- |
| 131 | |
| 132 | ### Previous |
| 133 | |
| 134 | ### Current |
| 135 | |
| 136 | ### Blockers |
| 137 | |
| 138 | Day's notes |
| 139 | ----------- |
| 140 | EOF |
| 141 | } |
| 142 | |
| 143 | work_log() { |
| 144 | mkdir -p "$DIR_WORK_LOG" |
| 145 | file_work_log_today="${DIR_WORK_LOG}/$(date +%F).md" |
| 146 | if [ ! -f "$file_work_log_today" ] |
| 147 | then |
| 148 | work_log_template > "$file_work_log_today" |
| 149 | fi |
| 150 | vim "$file_work_log_today" |
| 151 | |
| 152 | } |
| 153 | |
| 154 | note() { |
| 155 | mkdir -p "$DIR_NOTES" |
| 156 | vim "$DIR_NOTES/$(date +'%Y_%m_%d--%H_%M_%S%z')--$1.md" |
| 157 | } |
| 158 | |
| 159 | weather() { |
| 160 | curl "http://wttr.in/$WEATHER_LOCATION" |
| 161 | } |
| 162 | |
| 163 | bt_devs_paired() { |
| 164 | bluetoothctl -- paired-devices \ |
| 165 | | awk '{print $2}' \ |
| 166 | | xargs bluetoothctl -- info |
| 167 | } |
| 168 | |
| 169 | bt_devs() { |
| 170 | bluetoothctl -- devices \ |
| 171 | | awk '{print $2}' \ |
| 172 | | xargs bluetoothctl -- info |
| 173 | } |
| 174 | |
| 175 | run() { |
| 176 | stderr="$(mktemp)" |
| 177 | $@ 2> >(tee "$stderr") |
| 178 | code="$?" |
| 179 | urgency='' |
| 180 | case "$code" in |
| 181 | 0) urgency='normal';; |
| 182 | *) urgency='critical' |
| 183 | esac |
| 184 | notify-send -u "$urgency" "Job done: $code" "$(cat $stderr)" |
| 185 | rm "$stderr" |
| 186 | } |