Questions tagged [compgen]

Use when this bash builtin command is being called independently of standard autocompletion, which is the more usual tag.

15 questions
63
votes
2 answers

Understand `compgen` builtin command

From help compgen: $ help compgen compgen: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word] Display possible completions depending on the…
Pandya
  • 23,898
  • 29
  • 92
  • 144
15
votes
1 answer

How to output string completions to stdout?

Some of the git commands have many options, and it would often be useful to search through them for the one I need - I was just looking for the option which controls the TAB width in git-gui, but there are about 200 completions for git config. An…
l0b0
  • 50,672
  • 41
  • 197
  • 360
10
votes
3 answers

Can a bash script include its own auto-completions?

There are many resources available (1, 2, 3) that explain how to make use of bash's ability to auto-complete commands and arguments, but all of these resources require the addition of code to a user's ~/.bash_profile or /etc/bash_completion.d/* but…
beporter
  • 203
  • 2
  • 7
9
votes
2 answers

autocomplete filenames using compgen

As part of a larger autocomplete function I'm writing, I want to use compgen to generate a list of files. I read the bash manual entries for compgen and complete, and from there I assumed that the option -G "*" would be the solution. I could not get…
daniel kullmann
  • 9,427
  • 11
  • 38
  • 45
8
votes
1 answer

Is there a command to get builtin commands on zsh?

Is there a command to get builtin commands on zsh? For example, it is possible to get all builtin commands with the compgen -b command in the bash shell.
testter
  • 1,290
  • 2
  • 11
  • 24
5
votes
0 answers

Bash completion own compgen prefix

I have a simple bash completion script that essentially invokes my (non-bash) program and set its output to COMREPLY, i.e. COMPREPLY=( $(my-program -- "${COMP_WORDS[@]}") ) Some of the options accept comma separated value, is there a way to handle…
Limon
  • 161
  • 3
4
votes
1 answer

compgen warning: -C option not working as I expected

What is the correct way to use the compgen -C option? I'm trying to learn about Bash programmable completion, and in particular the compgen builtin function. I'm experimenting with the different compgen command-line options, and I don't understand…
2
votes
1 answer

Why do I need to use the -I parameter in `compgen -G ... | xargs basename`?

I ran into a situation where I was piping the output of compgen -G to xargs basename and could not get it to work until I added the xargs -I parameter as seen below. Here is a script demonstrating what I was trying to do, with explanatory comments.…
chris
  • 123
  • 5
1
vote
1 answer

bash array acting weird

I have two folders under /tmp. From terminal: ls -d /tmp/firefox-* /tmp/firefox-sy2vakcj.default-esr-charlie-cache /tmp/firefox-sy2vakcj.default-esr-charlie-profile or compgen -G…
Just Khaithang
  • 412
  • 1
  • 5
  • 16
1
vote
1 answer

compgen and SELinux

I have an app, browser shell and I'm executing this command to get list of execuables (List all binaries from $PATH) compgen -A function -abck | sort | uniq and when I call this command It return executables but I've got lot of errors from SELinux…
jcubic
  • 9,612
  • 16
  • 54
  • 75
1
vote
0 answers

How does readline use compgen to get all applicable completions?

I'm building an alternative to readline and would like to have tab completion in a similar way to how readline has tab completion. In readline, if you type git you get all the git subcommands as autocomplete options. But if you type ls
Drew
  • 165
  • 7
1
vote
1 answer

How to use bash command completion so that only files within a particular directory are completed?

Suppose I have a bash function specialcat that cats a file in the ~/Special directory specialcat () { cat ~/Special/$1 } Suppose the ~/Special directory was set up like so: mkdir ~/Special echo This is the first special file >…
panofsteel
  • 113
  • 3
0
votes
1 answer

compgen -o nospace option without effect

I'm trying to create a command completion function, and I was following this guide. This is approximately how it looks: function __my_completion () { local cur prev opts opts_log opts_import COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" …
RL-S
  • 131
  • 1
  • 4
0
votes
1 answer

`compgen -A file -G './tmp/*.sh` unexpectedly shows ALL the files in directory ./ as well as the desired ones

I expected that compgen -A file -G './tmp/*.sh' would show only files under tmp/, but it also showed all files in the current directory. I have tried compgen -A file -X '!(tmp/*.sh)' and compgen -A file -X "!(tmp/*.sh)" but both result in null…
Craig Hicks
  • 644
  • 8
  • 13
0
votes
0 answers

'compgen' appears to have undocumented parameter '--', can I rely on it being present across systems?

I happen to be on Ubuntu 18.04, with GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu) The output of % compgen -A file -- test-data foobar -- outputs all files/dirs in the current directory as though no token to complete was passed. …
Craig Hicks
  • 644
  • 8
  • 13