-
Notifications
You must be signed in to change notification settings - Fork 400
is there a better way to complete only executables in a given dir #748
-
Hey.
I want to complete any executables (regular files or symlinks pointing to such) in a given directory (but not in it's subdirectories).
Ideally with no dependencies (e.g. find) which are not guaranteed to be there
My current approach is:
{ PATH="${someDir}" compgen -c; compgen -abk -A function; } | sort | uniq -u
which first takes the output of -c and then filters out any aliases, built-ins, keywords and functions.
But that's of course also a bit ugly... and requires two additional processes.
Anything better?
Thanks,
Chris.
Beta Was this translation helpful? Give feedback.
All reactions
This question is unrelated to bash-completion. This kind of question should be asked on the help-bash list.
I don't think there is a single command to obtain only the executable files. The suggested line can be rewritten in a more natural way as follows, but further improvements depend on the use case.
PATH=$PWD compgen -c | grep -vxF "$(compgen -abk -A function)"
Or rather than relying on hacks, files can be simply tested as
# Just for illustration of the idea, *not tested* result=() for file in "$someDir"/*; do if [[ -x $file ]]; then result+=("${file##*/}") fi done
This is plain, clean, and flexible.
Replies: 2 comments
-
This question is unrelated to bash-completion. This kind of question should be asked on the help-bash list.
I don't think there is a single command to obtain only the executable files. The suggested line can be rewritten in a more natural way as follows, but further improvements depend on the use case.
PATH=$PWD compgen -c | grep -vxF "$(compgen -abk -A function)"
Or rather than relying on hacks, files can be simply tested as
# Just for illustration of the idea, *not tested* result=() for file in "$someDir"/*; do if [[ -x $file ]]; then result+=("${file##*/}") fi done
This is plain, clean, and flexible.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
This question is unrelated to bash-completion. This kind of question should be asked on the help-bash list.
Well bash itself obviously has no direct way... and like for so many other things, bash-completion might have just provided some helper function or similar that I couldn't find.
PATH=$PWD compgen -c | grep -vxF "$(compgen -abk -A function)"
Guess I'll need to check which of the two is faster. But probably that one.
Or rather than relying on hacks, files can be simply tested as
Sure, but that was noticeable slower in my tests.
Beta Was this translation helpful? Give feedback.