File: dyskette.sh 1 #!/bin/sh 2 3 # The MIT License (MIT) 4 # 5 # Copyright (c) 2026 pacman64 6 # 7 # Permission is hereby granted, free of charge, to any person obtaining a copy 8 # of this software and associated documentation files (the "Software"), to deal 9 # in the Software without restriction, including without limitation the rights 10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 # copies of the Software, and to permit persons to whom the Software is 12 # furnished to do so, subject to the following conditions: 13 # 14 # The above copyright notice and this permission notice shall be included in 15 # all copies or substantial portions of the Software. 16 # 17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 # SOFTWARE. 24 25 26 # dyskette [options...] 27 # 28 # Smaller-sized remake of the `dysk` tool, and its default output. The only 29 # options are `-help`, and `--help`, which show this message. 30 31 32 case "$1" in 33 -help|--help) 34 awk '/^# +dyskette /, /^$/ { gsub(/^# ?/, ""); print }' "$0" 35 exit 0 36 ;; 37 esac 38 39 [ "$1" = '--' ] && shift 40 41 df -T -H "$@" | awk ' 42 BEGIN { 43 style = "\x1b[38;2;204;124;0m\x1b[48;2;0;135;95m" 44 t[0] = style " " "\x1b[0m" 45 t[1] = style "▌ " "\x1b[0m" 46 t[2] = style "█ " "\x1b[0m" 47 t[3] = style "█▌ " "\x1b[0m" 48 t[4] = style "██ " "\x1b[0m" 49 t[5] = style "██▌ " "\x1b[0m" 50 t[6] = style "███ " "\x1b[0m" 51 t[7] = style "███▌ " "\x1b[0m" 52 t[8] = style "████ " "\x1b[0m" 53 t[9] = style "████▌" "\x1b[0m" 54 55 fsw = length("filesystem") 56 typew = length("type") 57 usedw = length("use") 58 usepercw = length("used") 59 freew = length("free") 60 sizew = length("size") 61 } 62 63 NR == 1 || $2 == "tmpfs" || $2 == "devtmpfs" { next } 64 65 { 66 n++ 67 68 v = $6 69 gsub(/%$/, "", v) 70 for (i = 0; v >= 20; i += 2) v -= 20 71 if (v >= 10) i++ 72 bar[n] = t[i] 73 74 fs[n] = $1 75 if (fsw < length($1)) fsw = length($1) 76 type[n] = $2 77 if (typew < length($2)) typew = length($2) 78 used[n] = $4 79 if (usedw < length($4)) usedw = length($4) 80 useperc[n] = $6 81 if (usepercw < length($6)) usepercw = length($6) 82 free[n] = $5 83 if (freew < length($5)) freew = length($5) 84 size[n] = $3 85 if (sizew < length($3)) sizew = length($3) 86 87 s = "" 88 for (i = 7; i <= NF; i++) { 89 if (i > 7) s = s " " 90 s = s $i 91 } 92 mnt[n] = s 93 } 94 95 END { 96 if (n < 1) exit 97 98 fmt = "%%%ds %%%ds %%%ds %%%ds %%-5s %%%ds %%%ds %%s\n" 99 fmt = sprintf(fmt, -fsw, -typew, -usedw, usepercw, freew, sizew) 100 101 printf fmt, 102 "filesystem", "type", "used", "use", "-", 103 "free", "size", "mountpoint" 104 105 for (i = 1; i <= n; i++) { 106 printf fmt, 107 fs[i], type[i], used[i], useperc[i], bar[i], 108 free[i], size[i], mnt[i] 109 } 110 } 111 '