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