Questions about command completion in the Bash Unix shell.
Questions tagged [bash-completion]
310 questions
24
votes
2 answers
Customizing bash completion output: each suggestion on a new line
When you type something, you often use bash autocompletion: you start writing a command, for example, and you type TAB to get the rest of the word.
As you have probably noticed, when multiple choices match your command, bash displays them like this…

4wk_
- 2,458
- 3
- 34
- 46
20
votes
9 answers
Slow load time of bash in cygwin
At the moment bash takes about 2 seconds to load. I have ran bash with -x flag and I am seeing the output and it seems as though PATH is being loaded many times in cygwin. The funny thing is I use the same file in linux environment, but it works…

Forethinker
- 3,548
- 4
- 27
- 48
19
votes
1 answer
Can bash completion be invoked programmatically?
What I want is a function I can call from a program so it completes the way bash would given a commandline and a location where TAB was pressed.
. /etc/bash_completion
generate_completions "command arg1 arg2" 17
would return the same thing as…

jpkotta
- 9,237
- 3
- 29
- 34
17
votes
4 answers
bash tab completion without variable expansion?
Let's say I have these variables defined in my bashrc:
i='cgi-bin/internal';
e='cgi-bin/external';
f='cgi-bin/foo';
b='cgi-bin/bar';
ad='cgi-bin/admin';
#etc...
When I use the variable on the command line vim $i/edit_TAB it will expand…

Andrew Sohn
- 675
- 1
- 6
- 15
17
votes
3 answers
Customize tab completion in shell
This may be have a better name than "custom tab completion", but here's the scenario:
Typically when I'm at the command line and I enter a command, followed with {TAB} twice, I get a list of all files and subdirectories in the current directory. …

jedwards
- 29,432
- 3
- 65
- 92
16
votes
5 answers
bash autocompletion: add description for possible completions
Is it possible to make bash auto-completion look like in Cisco IOS shell?
I mean to add short descriptions for each completion, like this:
telnet 10.10.10. (TAB Pressed)
10.10.10.10 - routerA
10.10.10.11 - routerB
where 10.10.10.10 and…

DDJ
- 161
- 1
- 4
16
votes
3 answers
Override bash completion for git clone
builtin completion
The default completion for git clone (reproduced below) gives tab completion for --* options:
_git_clone ()
{
case "$cur" in
--*)
__gitcomp_builtin clone
return
;;
esac
}
bash-completion 1.x…

anthony sottile
- 61,815
- 15
- 148
- 207
16
votes
4 answers
Bash Autocompletion - How to pass this array to compgen without significant whitespace being collapsed?
The following bash completion passes an array of possible words (i.e. completions) to compgen.
basenames=("foo" "fu bar" "baz");
COMPREPLY=($(compgen -W "${basenames[*]}" -- "${COMP_WORDS[COMP_CWORD]}"))
The problem is that the whitespace in the…

helpermethod
- 59,493
- 71
- 188
- 276
16
votes
2 answers
How to prevent bash completion from replacing a character when tab completing
I'm building a bash completion script for a tool which shares file uploading semantics with curl.
With curl, you can do:
curl -F var=@file
to upload a file.
My application has similar semantics and I wish to be able to show possible files after the…

UsAaR33
- 3,536
- 2
- 34
- 55
15
votes
2 answers
Unit Test for Bash completion script
I would like to write a Unit Test for a (rather complex) Bash completion script, preferrably with Python - just something that gets the values of a Bash completion programmatically.
The test should look like this:
def test_completion():
#…

Wolkenarchitekt
- 20,170
- 29
- 111
- 174
15
votes
4 answers
"${1-}" vs "$1"
The code for git bash completion, specifically the function __gitcomp, uses parameter expansions like "${1-}". This appears to be similar to "$1". What is the difference?
Also: where is this documented in the bash manual?

intuited
- 23,174
- 7
- 66
- 88
15
votes
1 answer
How to Bash Complete Three-Part Pattern
I have a command line tool which takes arguments in an three-part form:
$ t first_second_third
I have a set of valid values for first, a set of valid values for second, and a set of valid values for third. I want to use Bash complete functionality…

Alexander
- 415
- 3
- 10
14
votes
1 answer
How do I defer shell completion to another command in bash and zsh?
I am attempting to write a shell script utility that wraps other shell utilities into a single CLI and am trying to get shell completion to work in zsh and bash.
For example, let's say the CLI is named util:
util aws [...args] #=> runs aws
util…

Jacob Gillespie
- 3,981
- 3
- 23
- 33
14
votes
2 answers
bash_completion for Rails 3
Is there any bash_completion script ready for Rails 3?

klew
- 14,837
- 7
- 47
- 59
11
votes
1 answer
Git completion for alias as if for Git itself
Background
I have successfully configured Bash completion for various Git aliases. For example:
$ git config alias.subject
!git --no-pager show --quiet --pretty='%s'
$ function _git_subject() { _git_show; }
$ git subject my
$ git subject…

Harrison McCullough
- 518
- 5
- 18