- Introduce bash completion
- look at basic options
- build a custom completion
complete -p
complete -F _minimal complete -F _fcoemon_options fcoemon complete -o filenames -F _yu_yumdownloader yumdownloader complete -o filenames -F _yu_builddep yum-builddep.py ...
299 on my home laptop
Register a completion strategy for a command.
Strategies all return lists of completions.
complete -F _foo foo
complete -C foo_comp foo
complete -A setopt set
complete -o filenames -o nospace -F _pass pass
complete [-abcdefgjksuv] [-o comp-option] [-DEI] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] name [name …] complete -pr [-DEI] [name …]
complete -o default -o nospace -W \
"$(awk '/^Host / {print $2}' < $HOME/.ssh/config)" scp sftp ssh;
Let’s build up a version for bk
We’ll use a dummy version called baker
def pr cmd, options
puts "'#{cmd} #{options.join(' ')}' was called"
end
cmd, *options = ARGV
case cmd
when 'up'
pr cmd, options
when 'down'
pr cmd, options
when 'runcmd'
#....
else
raise "Unknown cmd: #{cmd}"
end
#!/usr/bin/env ruby
# complete -r baker; complete -C ./c1.rb baker
COMMANDS = %w(up down runcmd ps pull version)
puts COMMANDS
exit 0
class BakerCompleter
COMMANDS = %w(up down runcmd ps pull version)
def self.completions(word)
if word.empty?
COMMANDS
else
COMMANDS.select do |c|
c.match? word
end
end
end
end
# baker <?>
full_cmd = ENV["COMP_LINE"].split
current_word = full_cmd.last.to_s.strip
puts BakerCompleter.completions(current_word)
exit 0
https://github.com/scop/bash-completion https://devmanual.gentoo.org/tasks-reference/completion/index.html https://debian-administration.org/article/317/An_introduction_to_bash_completion_part_2 https://blog.cykerway.com/posts/2016/12/23/how-to-write-bash-completion.html https://www.linuxjournal.com/content/more-using-bash-complete-command https://spin.atomicobject.com/2016/02/14/bash-programmable-completion/