32 lines
1.2 KiB
Bash
Executable File
32 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# [b]rowse - custom ls or bat depending on file type
|
|
# Show type & contents of given files or PWD
|
|
# depends: tput stat bat neovim
|
|
# args: files to inspect
|
|
|
|
set -eo pipefail
|
|
# get the last arg or current dir
|
|
for last; do true; done
|
|
last=${last:-.}
|
|
|
|
# Elevate permissions if the file is not accessible
|
|
test -x "$(dirname "$last")" &&
|
|
{ test -r "$last" || ! test -e "$last"; } ||
|
|
elevate=sudo
|
|
tput setaf 4 && $elevate file -E "$last" | { grep -v --color=never 'directory$' || true; }
|
|
|
|
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 "$@" | less -XF;;
|
|
(*binary)
|
|
case "$(file "$last")" in
|
|
(*:\ *compress*) /usr/share/nvim/runtime/macros/less.sh "$@";;
|
|
(*:\ *\ image\ data*) viu --height "$(echo $LINES/2 | bc)" "$@";;
|
|
esac
|
|
tput setaf 3 && $elevate stat --format '%A size %sB, birth: %.10w mod %.10y' "$last"
|
|
;;
|
|
(*) $elevate bat --style header "$@" --pager 'less -RXF'
|
|
tput setaf 3 && $elevate stat --format '%A size %sB, birth: %.10w mod %.10y' "$last"
|
|
# TODO don't duplicate stat
|
|
;;
|
|
esac
|