Skip to content

Instantly share code, notes, and snippets.

@rbeer
Created May 3, 2018 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbeer/c2ba68608fb1de956c8f5b834320ac34 to your computer and use it in GitHub Desktop.
Save rbeer/c2ba68608fb1de956c8f5b834320ac34 to your computer and use it in GitHub Desktop.
Less-ls; ls for directories, less for files - in one single `ls` alias
#!/bin/bash
LS_PATH=$1
function lsFallback() {
/bin/ls -alh --color=auto $LS_PATH
exit $?
}
if [ "$LS_PATH" == "" ]; then lsFallback; fi
file $LS_PATH 2> /dev/null | grep -o text &> /dev/null
if [ $? -gt 0 ]; then
lsFallback
else
more $LS_PATH
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment