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...] [df args...]
  27 #
  28 # Smaller-sized remake of the `dysk` tool, and its default output. Data come
  29 # from running `df -T -H`, and any other options/args given to this tool.
  30 #
  31 # The options are, available both in single and double-dash versions
  32 #
  33 #   -h, -help    show this help message
  34 
  35 
  36 case "$1" in
  37     -help|--help)
  38         awk '/^# +dyskette /, /^$/ { gsub(/^# ?/, ""); print }' "$0"
  39         exit 0
  40     ;;
  41 esac
  42 
  43 df -T -H "$@" | awk '
  44     BEGIN {
  45         style = "\x1b[38;2;204;124;0m\x1b[48;2;0;135;95m"
  46         t[0] = style "     " "\x1b[0m"
  47         t[1] = style "▌    " "\x1b[0m"
  48         t[2] = style "█    " "\x1b[0m"
  49         t[3] = style "█▌   " "\x1b[0m"
  50         t[4] = style "██   " "\x1b[0m"
  51         t[5] = style "██▌  " "\x1b[0m"
  52         t[6] = style "███  " "\x1b[0m"
  53         t[7] = style "███▌ " "\x1b[0m"
  54         t[8] = style "████ " "\x1b[0m"
  55         t[9] = style "████▌" "\x1b[0m"
  56 
  57         fsw = length("filesystem")
  58         typew = length("type")
  59         usedw = length("use")
  60         usepercw = length("used")
  61         freew = length("free")
  62         sizew = length("size")
  63     }
  64 
  65     NR == 1 || $2 == "tmpfs" || $2 == "devtmpfs" { next }
  66 
  67     {
  68         n++
  69 
  70         v = $6
  71         gsub(/%$/, "", v)
  72         for (i = 0; v >= 20; i += 2) v -= 20
  73         if (v >= 10) i++
  74         bar[n] = t[i]
  75 
  76         fs[n] = $1
  77         if (fsw < length($1)) fsw = length($1)
  78         type[n] = $2
  79         if (typew < length($2)) typew = length($2)
  80         used[n] = $4
  81         if (usedw < length($4)) usedw = length($4)
  82         useperc[n] = $6
  83         if (usepercw < length($6)) usepercw = length($6)
  84         free[n] = $5
  85         if (freew < length($5)) freew = length($5)
  86         size[n] = $3
  87         if (sizew < length($3)) sizew = length($3)
  88 
  89         s = ""
  90         for (i = 7; i <= NF; i++) {
  91             if (i > 7) s = s " "
  92             s = s $i
  93         }
  94         mnt[n] = s
  95     }
  96 
  97     END {
  98         if (n < 1) exit
  99 
 100         fmt = "%%%ds  %%%ds  %%%ds  %%%ds  %%-5s  %%%ds  %%%ds  %%s\n"
 101         fmt = sprintf(fmt, -fsw, -typew, -usedw, usepercw, freew, sizew)
 102 
 103         printf fmt,
 104             "filesystem", "type", "used", "use", "-",
 105             "free", "size", "mountpoint"
 106 
 107         for (i = 1; i <= n; i++) {
 108             printf fmt,
 109                 fs[i], type[i], used[i], useperc[i], bar[i],
 110                 free[i], size[i], mnt[i]
 111         }
 112     }
 113 '