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). My current approach is:
which first takes the output of But that's of course also a bit ugly... and requires two additional processes. Anything better? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This question is unrelated to 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.
-
Well
Guess I'll need to check which of the two is faster. But probably that one.
Sure, but that was noticeable slower in my tests. |
Beta Was this translation helpful? Give feedback.
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.
Or rather than relying on hacks, files can be simply tested as
This is plain, clean, and flexible.