To flesh out my comment on John Moon's answer, here's a function that wraps ls
and adds a -a
flag if the path matches a certain list:
function ls() {
# if no arguments are provided, the current directory is assumed
[ "$#" -eq 0 ] && set .
case "$(realpath "$1")" in
(/path/to/jason/filestoprocess*|\
/path/to/jason/otherfilestoprocess*)
set -- -a "$1" ;;
esac
command ls "$@"
}
The first section of the function checks to see if a bare ls
is being done; in this case, we set .
(the current directory) as parameter #1; otherwise, we assume that the (given) first parameter is the path to list.
If the set-or-given path matches the patterns listed (either ...filestoprocess or ...otherfilestoprocess here), then we use set
again to add the -a
flag into the parameters. At the end, we use command
to call the actual ls
command with the arguments we've arranged. Thanks to muru for pointing out the set
simplification!
To add more paths, simply continue the patterns, separating them with pipe (|)
characters. I've broken the two existing patterns onto separate lines with the backslash escape character \
to make them easier to read.
If you have ls
aliased to something already, that will take precedence and would need to be removed to make this function work (otherwise, any flags that the alias adds would be passed to this function and end up in $1
). If there are flags that you like to have in ls
by default, simply add them to the two corresponding command ls
calls.