Created
May 17, 2022 10:21
-
-
Save clbarnes/80ae2b90ba3d05ff42e043a7fa65ef94 to your computer and use it in GitHub Desktop.
les: ls if it's a directory, less if it's a file
This file contains hidden or 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/sh | |
| set -e | |
| if [ $# -eq 0 ]; then | |
| >&2 echo "No argument given, using ls" | |
| exec ls | |
| elif [ -d "$1" ]; then | |
| >&2 echo "Directory detected, using ls" | |
| exec ls "$1" | |
| elif [ -f "$1" ]; then | |
| >&2 echo "File detected, using less" | |
| exec less "$1" | |
| else | |
| >&2 echo "No such file or directory" | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment