bash-completion

bash tab completion with spaces

半腔热情 提交于 2019-12-03 08:18:43
I'm having a problem with bash-completion when the possible options may contain spaces. Let's say I want a function which echoes the first argument: function test1() { echo $1 } I generate a list of possible completion options (some have spaces, some not), but I don't manage to handle spaces correctly. function pink() { # my real-world example generates a similar string using awk and other commands echo "nick\ mason syd-barrett david_gilmour roger\ waters richard\ wright" } function _test() { cur=${COMP_WORDS[COMP_CWORD]} use=`pink` COMPREPLY=( $( compgen -W "$use" -- $cur ) ) } complete -o

bash autocompletion: add description for possible completions

左心房为你撑大大i 提交于 2019-12-02 22:57:10
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 10.10.10.11 are possible completions and routerA & routerB just descriptions (not to be executed). I know that bash can complete commands with "complete -W", but is it able to print descriptions for them? I have a solution to this that does not require pressing TAB more than twice or echoing any extra information. The key is to check whether there is only one

How to bash complete a GNU long option with given set of arguments?

心已入冬 提交于 2019-12-01 06:52:06
问题 GNU advises to use --name=value syntax for passing argument for long option. It enables a long option to accept an argument that is itself optional. Suppose you have a complete set of possible arguments. How do you write a bash completion code for such an option? I want the completion to add space when it completes an unambiguous argument, but not before. 回答1: Here is the template code I wrote for completing GNU options given in the code for imaginary command gnu-options . Options that do not

Bash completion for path in argument (with equals sign present)

一笑奈何 提交于 2019-11-30 20:05:00
I used to be able to type the following: $> ./foo --arg=<TAB> Where foo is any program I wrote, and it would give me a list of files in the current directory, just like tab-completion normally does. I didn't have to make any changes to /etc/bash_completion. Recently, however, this has gone away for some unknown reason. Does anyone know how to re-enable this feature? FWIW, this still does the correct thing (notice the lack of an equals sign): $> ./foo --arg <TAB> I removed all bash completion scripts and started adding them one by one to if any of them cause the problem. In my case it turned

Getting compgen to include slashes on directories when looking for files

主宰稳场 提交于 2019-11-30 17:25:24
I'd like to get the following behavior from my custom completion Given $ mkdir foo $ touch foo faz/bar faz/baz I'd like to get this $ foo -u <tab><tab> => foo faz/ $ foo -u fa<tab><tab> => foo -u faz/ $ foo -u faz/<tab><tab> => bar baz I assumed that compgen -f f would output foo faz/ , but it outputs foo faz which doesn't help me much. Do I need to post-process the output or is there some magic combination of options to compgen that work? I ran into the same problem. Here's the workaround I'm using: Register the completion function with -o default , e.g., complete -o default -F _my_completion

Specifying two file extensions in bash complete

ε祈祈猫儿з 提交于 2019-11-30 13:56:47
I am trying to modify bash complete properties. I can exclude a file extension for a command thusly: complete -f -X '*hi' vim I want to specify two file names for exclusion. How do I do this? Note: the following command did not work. complete -f -X '(*hi|*o)' vim devnull One way to do this is to turn on Extended Globs . Run this at the command line, or add it to your .bashrc to make it permanent: shopt -s extglob Now, your complete command can look like this: complete -f -X '*.@(hi|o)' vim Quoting from Extended Globs in patterns : @(list): Matches one of the given patterns. 来源: https:/

Conditional trailing space with bash programmable completion

僤鯓⒐⒋嵵緔 提交于 2019-11-30 13:14:49
I'm creating a function to provide programmable completion for a command that I use (with much help from http://www.debian-administration.org/articles/317 ). The shell script usage is as follows: script.sh command [command options] where command can be either 'foo' or 'bar' and command options for 'foo' are 'a_foo=value' and 'b_foo=value' and command options for 'bar' are 'a_bar=value' and 'b_bar=value'. Here's the configuration I'm using: _script() { local cur command all_commands COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" command="${COMP_WORDS[1]}" all_commands="foo bar" case "${command}"

Multi Level Bash Completion

六眼飞鱼酱① 提交于 2019-11-30 12:42:10
问题 I currently have a Bash completion file which completes a single parameter from a list of allowed commands for a script (called "pbt"). This is the working Bash Completion file: _pbt_complete() { local cur goals COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} goals='asadmin clean deploy' cur=`echo $cur` COMPREPLY=($(compgen -W "${goals}" ${cur})) } complete -F _pbt_complete pbt So if i call pbt <tab> Bash completes to all allowed commands (asadmin, clean, deploy), which is okay. Now i want to add

Slow load time of bash in cygwin

我的梦境 提交于 2019-11-30 01:53:20
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 fine, without the reload problem. Could the following cause the problem? if [ `uname -o` = "Cygwin" ]; then .... fi As you've noted in your answer, the problem is Cygwin's bash-completion package. The quick and easy fix is to disable bash-completion, and the correct way to do that is to run Cygwin's setup.exe ( download it again if you need to) and

Specifying two file extensions in bash complete

女生的网名这么多〃 提交于 2019-11-29 19:20:59
问题 I am trying to modify bash complete properties. I can exclude a file extension for a command thusly: complete -f -X '*hi' vim I want to specify two file names for exclusion. How do I do this? Note: the following command did not work. complete -f -X '(*hi|*o)' vim 回答1: One way to do this is to turn on Extended Globs . Run this at the command line, or add it to your .bashrc to make it permanent: shopt -s extglob Now, your complete command can look like this: complete -f -X '*.@(hi|o)' vim