-
-
Save earwig/d05e55ac8a12dafe4ca50099f7938546 to your computer and use it in GitHub Desktop.
x: eXamine files/dirs using the right tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
if [[ $# -eq 0 ]]; then | |
args=(".") | |
else | |
args=("$@") | |
fi | |
for f in "${args[@]}"; do | |
if [[ -d "$f" ]]; then | |
ls -lAF --color=auto "$f" | |
else | |
len=($(wc -cl "$f" | sed -e 's/^ *//' -e 's/ */ /' | cut -d' ' -f1-2)) || continue | |
lines=$(tput lines) | |
if [[ "$(file -b -L --mime-encoding "$f")" == "binary" ]]; then | |
if [[ $((${len[1]}/16)) -ge $lines ]]; then | |
xxd "$f" | less | |
else | |
xxd "$f" | |
fi | |
else | |
if [[ ${len[0]} -ge $(($lines - 1)) ]]; then | |
less "$f" | |
else | |
cat "$f" | |
fi | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment