2021-09-20 11:14:34 +02:00
|
|
|
#!/bin/bash
|
2021-07-29 16:02:20 +02:00
|
|
|
# [b]rowse - custom ls or bat depending on file type
|
2020-10-23 14:00:41 +02:00
|
|
|
# Show type & contents of given files or PWD
|
2020-12-10 17:34:56 +01:00
|
|
|
|
2021-07-13 12:15:58 +02:00
|
|
|
set -eo pipefail
|
2020-12-10 17:34:56 +01:00
|
|
|
# gets the last arg or current dir
|
2020-11-16 12:29:31 +01:00
|
|
|
for last; do true; done
|
|
|
|
last=${last:-.}
|
2020-12-10 17:34:56 +01:00
|
|
|
|
2021-10-12 08:42:22 +02:00
|
|
|
# Elevate permissions if the file is not accessible
|
|
|
|
test -x "$(dirname "$last")" &&
|
|
|
|
{ test -r "$last" || ! test -e "$last"; } ||
|
|
|
|
elevate=sudo
|
2021-09-16 14:18:26 +02:00
|
|
|
tput setaf 4 && $elevate file -E "$last" | ( grep -v --color=never 'directory$' || true )
|
2020-12-10 17:34:56 +01:00
|
|
|
|
2021-07-13 12:15:58 +02:00
|
|
|
case "$($elevate file --dereference --mime "$last")" in
|
2021-07-29 12:44:51 +02: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 12:29:31 +01:00
|
|
|
*binary) ;;
|
2021-09-21 20:51:19 +00:00
|
|
|
*) $elevate bat --style header --color always "$@" | less -XF
|
2021-07-13 12:15:58 +02:00
|
|
|
tput setaf 3 && $elevate stat --format '%A size %sB, birth: %.10w mod %.10y' "$last"
|
2021-07-02 18:33:30 +02:00
|
|
|
;;
|
2020-11-16 12:29:31 +01:00
|
|
|
esac
|