bash-completion

Showing only the substrings of COMPREPLY bash completion options to the user

↘锁芯ラ 提交于 2019-11-27 18:44:17
问题 In a bash completion script, suppose COMPREPLY=(aa/ba/ aa/bb/) . When the script is invoked, the completion options looks like this to the user: $ foo aa/b<TAB> aa/ba/ aa/bb/ However, I want to have a bit more control over how these options are displayed. In particular, I want to show only a substring of each COMPREPLY option to the user, similar to how directory completion works in bash now: $ foo aa/b<TAB> ba/ bb/ Is there any way of doing this in bash? 回答1: I was having the same problem

How to reset COMP_WORDBREAKS without affecting other completion script?

廉价感情. 提交于 2019-11-27 08:03:12
There is something confuse me when I implement a bash auto-completion function which I'll put it in /etc/bash_completion.d/ In order to achieve some feature, I want to remove the word break characters colon ( : ) from variable $COMP_WORDBREAKS and add a slash ( / ) at begin of $COMP_WORDBREAKS . COMP_WORDBREAKS=" /'><=;|&(" _mytool() { local cur=${COMP_WORDS[COMP_CWORD]} compopt -o nospace # my implement here COMPREPLY=( $(compgen ..........my_implement......... -- $cur) ) } complete -F _mytool mytool However, I can't reset COMP_WORDBREAKS directly because the value is shared with other

bash-completion - completion function defined the first time a command is invoked

纵饮孤独 提交于 2019-11-27 03:06:12
问题 I've added a new alias scp_using_rsync , which uses rsync to copy files over SSH with certain options. I wanted to link the bash completion for scp to this alias. It works when I add this line: complete -o bashdefault -o default -o nospace -F _scp scp_using_rsync 2>/dev/null || complete -o default -o nospace -F _scp scp_using_rsync The only problem is that I notice, _scp gets defined in my bash environment, only after I try tab-completion with ssh/scp at least once in that shell. So if I

A confusion about ${array[*]} versus ${array[@]} in the context of a Bash completion

廉价感情. 提交于 2019-11-27 02:39:53
I'm taking a stab at writing a Bash completion for the first time, and I'm a bit confused about about the two ways of dereferencing Bash arrays ( ${array[@]} and ${array[*]} ). Here's the relevant chunk of code (it works, by the way, but I would like to understand it better): _switch() { local cur perls local ROOT=${PERLBREW_ROOT:-$HOME/perl5/perlbrew} COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} perls=($ROOT/perls/perl-*) # remove all but the final part of the name perls=(${perls[*]##*/}) COMPREPLY=( $( compgen -W "${perls[*]} /usr/bin/perl" -- ${cur} ) ) } Bash's documentation says : Any

How do I change bash history completion to complete what's already on the line?

你。 提交于 2019-11-27 02:29:34
I found a command a couple of months ago that made my bash history auto-complete on what's already on the line when pressing the up arrow: $ vim fi Press ↑ $ vim file.py I'd like to set this up on my new computer, because it saves a lot of time when keeping a big history. The problem is that I can't for the life of me remember where it was mentioned and reading through endless bash references and tutorials unfortunately didn't help either. Does anybody know the command? ephemient Probably something like # ~/.inputrc "\e[A": history-search-backward "\e[B": history-search-forward or equivalently

Git bash-completion with filename support?

◇◆丶佛笑我妖孽 提交于 2019-11-27 02:19:44
问题 is there a bash-completion script that supports filename completion? I use mostly mercurial and there I can type: hg diff test/test_<tab> and it will show/complete all modified test files. It works for most subcommands, i.e. hg add <tab><tab> will only list untracked files. It is really handy. The bash script from git contrib seams to not support this. Are there any alternatives, or how do you work with git on the command line? Edit 2015 git-completion.bash supports full filename completion

Bash variable expansion on tab complete

怎甘沉沦 提交于 2019-11-27 01:16:11
问题 I'm running Ubuntu 11.04, and I'm seeing some odd behaviour when I try to use tab-completion in bash on a path that starts with a variable. If I've got TOP=/scratch, and I try to tab-complete: cd $TOP/foo it changes to: cd \$TOP/foo I'd prefer it to complete to: cd $TOP/foobar or cd /scratch/foobar but I'd settle for it just not changing the line and requiring me to un-escape the $. Does anyone know where in bash/readline I should look to fix this? 回答1: Found the bug report, please register

Running bash commands in the background without printing job and process ids

别等时光非礼了梦想. 提交于 2019-11-27 00:31:30
问题 To run a process in the background in bash is fairly easy. $ echo "Hello I'm a background task" & [1] 2076 Hello I'm a background task [1]+ Done echo "Hello I'm a background task" However the output is verbose. On the first line is printed the job id and process id of the background task, then we have the output of the command, finally we have the job id, its status and the command which triggered the job. Is there a way to suppress the output of running a background task such that the output

Python argparse and bash completion

拜拜、爱过 提交于 2019-11-26 23:56:36
问题 I would like to get auto-completion on my python scripts also in the arguments. I had never really understood how the bash_completion worked (for arguments), but after I digged in I understood that: it uses "complete" to bind a completing function to a command every completing function basically is a copy of the argument parser The second point in particular is not great, because I would like to have it automatically generated. The best thing would be that the shell asks to my program at

Accessing bash completions for specific commands programmatically

倾然丶 夕夏残阳落幕 提交于 2019-11-26 22:48:34
问题 I'm trying to write a small command launcher application, and would like to use bash's tab completions in my own completion system. I've been able to get a list of completions for general commands using compgen -abck . However, I would also like to get completions for specific commands: for instance, the input git p should display completion for git's commands. Is there any way I can use compgen to do this? If not, are there any other ways I can get a list of completions programmatically?