bash-completion

Conditional trailing space with bash programmable completion

我的梦境 提交于 2019-11-29 18:32:19
问题 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=(

Dynamic case statement in bash

走远了吗. 提交于 2019-11-29 12:27:29
I'm trying to figure out how to create a dynamic case statement in a bash script. For example, let's say I have the output of an awk statement with the following contents red green blue In this scenario, the output can change at any time. I'm trying to then execute different logic if a value is included in this awk output. So if the data above is in $list, then I'd conceptually like to do something like: case "${my_var}" in $list) ..... something_else) ..... esac I'm trying to use this to build a dynamic custom tab completion function (see http://www.debian-administration.org/article/An

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

若如初见. 提交于 2019-11-29 04:50:25
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? I was having the same problem and I fixed it by adjusting how I bound the completion function to the command. I know this works when you are

Git bash-completion with filename support?

半城伤御伤魂 提交于 2019-11-28 08:36:13
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 since ~1.8.2 So, let's see how the Mercurial bash completion script does this. This is the important

Bash completions with equals sign and enumerable flag values

£可爱£侵袭症+ 提交于 2019-11-28 06:40:53
问题 I'm trying to construct a bash completion routine that will suggest command lines flags and suitable flag values. For example in the below fstcompose command I would like the competition routine to first suggest the compose_filter= flag, and then suggest possible values from [alt_sequence, auto, match, sequence]. fstcompose --compose_filter= For any flags that do not have a set of associated of values I want the competition to fall back to the default mode of suggesting paths or files. The

Dynamic case statement in bash

我们两清 提交于 2019-11-28 06:30:21
问题 I'm trying to figure out how to create a dynamic case statement in a bash script. For example, let's say I have the output of an awk statement with the following contents red green blue In this scenario, the output can change at any time. I'm trying to then execute different logic if a value is included in this awk output. So if the data above is in $list, then I'd conceptually like to do something like: case "${my_var}" in $list) ..... something_else) ..... esac I'm trying to use this to

Bash variable expansion on tab complete

巧了我就是萌 提交于 2019-11-28 06:20:01
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? sehe Found the bug report, please register (if not already registered) and add yourself to the 'people affected' list, I just did: https://bugs

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

隐身守侯 提交于 2019-11-28 04:27:45
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 looks exactly as it would without the ampersand at the end? I.e: $ echo "Hello I'm a background task"

Python argparse and bash completion

筅森魡賤 提交于 2019-11-28 03:06:06
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 every TAB about what to complete, but I have the impression that this can't really work, is that correct?

bash and readline: tab completion in a user input loop?

99封情书 提交于 2019-11-27 19:01:38
I'm making a bash script which presents a command line to the user. The cli code is as this: #!/bin/bash cmd1() { echo $FUNCNAME: "$@" } cmd2() { echo $FUNCNAME: "$@" } cmdN() { echo $FUNCNAME: "$@" } __complete() { echo $allowed_commands } shopt -qs extglob fn_hide_prefix='__' allowed_commands="$(declare -f | sed -ne '/^'$fn_hide_prefix'.* ()/!s/ ().*//p' | tr '\n' ' ')" complete -D -W "this should output these words when you hit TAB" echo "waiting for commands" while read -ep"-> "; do history -s $REPLY case "$REPLY" in @(${allowed_commands// /|})?(+([[:space:]])*)) $REPLY ;; \?) __complete ;