I have a list of unison profiles which exists in ~/.unison/*.prf
.
I'd like to have bash completion so that when I type unison
or unison-gtk
and hit tab it would list the .prf
files from that folder without the .prf
part.
Perhaps an example would be clearer:
$ ls ~/.unison/*.prf
default.prf dot-mozilla.prf to-desktop.prf
$ cd ~ # just to show you don't have to be in the ~/.unison folder
$ unison to<tab>
$ unison to-desktop
I foresee needing this for another tool as well, so it would be convenient if there were parts that could be reused.
Bash completion is a bash function that allows you to auto complete commands or arguments by typing partially commands or arguments, then pressing the [Tab] key. This will help you when writing the bash command in terminal.
Put them in the completions subdir of $BASH_COMPLETION_USER_DIR (defaults to $XDG_DATA_HOME/bash-completion or ~/. local/share/bash-completion if $XDG_DATA_HOME is not set) to have them loaded automatically on demand when the respective command is being completed.
Bash completion is a functionality through which Bash helps users type their commands more quickly and easily. It does this by presenting possible options when users press the Tab key while typing a command.
If you are running debian/ubuntu or possibly other GNU/Linux distros, there should be examples of this type of completion in your /etc/bash_completion.d/ directory. Here is an example of how you might set up a completion script for unison:
have unison &&
_unison_show()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($( compgen -W "$(for x in ~/.unison/*.prf; do echo $(basename ${x%.prf}); done)" -- $cur ) )
}
complete -F _unison_show unison
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With