bin/b: revamp to use sudo if needed

This commit is contained in:
xeruf 2021-07-13 12:15:58 +02:00
parent b7d21127e1
commit 642e0d8ebd
1 changed files with 7 additions and 6 deletions

View File

@ -1,17 +1,18 @@
#!/bin/sh
# Show type & contents of given files or PWD
set -eo pipefail
# gets the last arg or current dir
for last; do true; done
last=${last:-.}
tput setaf 4 && file "$last" | grep -v --color=never 'directory$'
test -e "$last" || exit 1
tput setaf 4 && $(test -r "$last" || echo "sudo") file -E "$last" | ( grep -v --color=never 'directory$' || true )
case "$(file --dereference --mime "$last")" in
*inode/directory*) ls -l --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "$@";;
elevate="$(test -r "$last" || echo "sudo")"
case "$($elevate file --dereference --mime "$last")" in
*inode/directory*) tput sgr0 && $(test -x "$last" || echo "sudo") ls -l --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "$@";;
*binary) ;;
*) $(test -f "$last" -a ! -r "$last" && echo "sudo") bat --style header "$@"
tput setaf 3 && stat --format '%A size %sB, birth: %.10w mod %.10y' "$last"
*) $elevate bat --style header "$@"
tput setaf 3 && $elevate stat --format '%A size %sB, birth: %.10w mod %.10y' "$last"
;;
esac