There are already two questions on this topic here, but both address errors in their scripts rather than the actual title.
I want to develop a program that obtains some basic information about a file, depending on its type. I want to distinguish between directories, text and binary data.
So far I am using file
:
case "$(file --dereference $arg)" in
*directory) ls -l --color=auto --almost-all --human-readable --group-directories-first --file-type --dereference-command-line "$@";;
*text*|*JSON*) bat --style header "$@";;
esac
Which mostly works, but as you can see, I already had to add an exception for JSON as file
identifies that as JSON data with no mention of text.
The problem is that there are more exceptions, and I'd prefer to not add them all individually.
Is there a way to obtain more general information on the content type from file
or perhaps another standard program?