bash-completion

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

三世轮回 提交于 2019-11-26 19:43:23
问题 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

How to reset COMP_WORDBREAKS without affecting other completion script?

随声附和 提交于 2019-11-26 13:57:52
问题 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

How do I change bash history completion to complete what&#39;s already on the line?

自古美人都是妖i 提交于 2019-11-26 12:33:54
问题 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? 回答1: Probably