Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Last active December 2, 2025 21:24
Show Gist options
  • Select an option

  • Save ormaaj/d485b63e4c4c50c5975ab7c325a62d36 to your computer and use it in GitHub Desktop.

Select an option

Save ormaaj/d485b63e4c4c50c5975ab7c325a62d36 to your computer and use it in GitHub Desktop.
fstab generator
#!/usr/bin/env bash
shopt -s extglob lastpipe expand_aliases
typeset -Gx BASH_COMPAT=51
function fstabfmt {
local -; set +m
typeset x y IFS LC_CTYPE=C
typeset -a fields=(source target fstype options freq passno)
typeset -ia w=("${fields[@]/*/0}")
{
IFS=,
LIBMOUNT_FORCE_MOUNT2=always findmnt --all -Csrvuno "${fields[*]}"
} | tr \\n ' ' | {
IFS=' '
while read -rd ' ' 'a[x = ${#a[@]}]'; do
(( (y = ${#a[x]}) > w[x = x % 6] && (w[x] = y) ))
done
}
printf -v x '%%-%ds ' "${w[@]}"
printf -- "${x/%?/\\n}" "${a[@]}"
}
fstabfmt "$@"
# vim: set ft=bash fenc=utf-8 ff=unix ts=4 sts=4 sw=4 noet :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment