2020-10-23 12:00:41 +00:00
|
|
|
#!/bin/sh
|
2021-07-29 14:02:20 +00:00
|
|
|
# [b]rowse - custom ls or bat depending on file type
|
2020-10-23 12:00:41 +00:00
|
|
|
# Show type & contents of given files or PWD
|
2020-12-10 16:34:56 +00:00
|
|
|
|
2021-07-13 10:15:58 +00:00
|
|
|
set -eo pipefail
|
2020-12-10 16:34:56 +00:00
|
|
|
# gets the last arg or current dir
|
2020-11-16 11:29:31 +00:00
|
|
|
for last; do true; done
|
|
|
|
last=${last:-.}
|
2020-12-10 16:34:56 +00:00
|
|
|
|
2021-07-13 10:15:58 +00:00
|
|
|
tput setaf 4 && $(test -r "$last" || echo "sudo") file -E "$last" | ( grep -v --color=never 'directory$' || true )
|
2020-12-10 16:34:56 +00:00
|
|
|
|
2021-07-13 10:15:58 +00:00
|
|
|
elevate="$(test -r "$last" || echo "sudo")"
|
|
|
|
case "$($elevate file --dereference --mime "$last")" in
|
2021-07-29 10:44:51 +00:00
|
|
|
*inode/directory*) tput sgr0 && $(test -x "$last" || echo "sudo") ls -l --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "$@" | less -XF;;
|
2020-11-16 11:29:31 +00:00
|
|
|
*binary) ;;
|
2021-07-29 10:44:51 +00:00
|
|
|
*) $elevate bat --style header --force-colorization "$@" | less -XF
|
2021-07-13 10:15:58 +00:00
|
|
|
tput setaf 3 && $elevate stat --format '%A size %sB, birth: %.10w mod %.10y' "$last"
|
2021-07-02 16:33:30 +00:00
|
|
|
;;
|
2020-11-16 11:29:31 +00:00
|
|
|
esac
|