To obtain complementary candidates for bash

Asked 1 years ago, Updated 1 years ago, 109 views

If you press Tab while using bash in an interactive environment, the list of complementary candidates will be displayed, but is it possible to get this from the shell script? In other words, the current $PATH and $PWD (or there may be other environment variables) are given strings that are being entered and then the candidates are returned in an array of strings.

Would it be easy to understand if it is close to file-name-all-complets in Emacs LISP?

Please let me know if anyone knows.

bash

2022-09-30 17:30

1 Answers

I referred to the same question in SO.
shell-bash completion script to complete file path after certain commandline options-Stack Overflow

Is it compgen-f?

bash-3.2$bash --version
GNU bash, version 3.2.53(1)-release(x86_64-apple-darwin14)
Copyright (C) 2007 Free Software Foundation, Inc.
bash-3.2$ls
bash-3.2 $touch foo bar baz
bash-3.2$ls
barbaz foo
bash-3.2 $compgen-f
bar
baz
foo
bash-3.2$compgen-fba
bar
baz


2022-09-30 17:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.