I wrote a program (logit) that sets up logging and execs what ever follows it on the command line. That all works fine.
I want to be able to do command completion, sudo works like logit, so being lazy, I do this in my .bashrc:
complete -F _sudo logit
When it works, it does what I need, but I can't use completion for logit until after I use it for sudo.
wwalker@polonium:~$ type _sudo
-bash: type: _sudo: not found
wwalker@polonium:~$ logit cal-bash: completion: function `_sudo' not found
wwalker@polonium:~$ logit cal-bash: completion: function `_sudo' not found
wwalker@polonium:~$ sudo cal
cal caller callgrind_annotate callgrind_control
wwalker@polonium:~$ type _sudo
_sudo is a function
_sudo ()
{
....
wwalker@polonium:~$ logit cal
cal caller callgrind_annotate callgrind_control
wwalker@polonium:~$ logit cal
Anyone got any idea how _sudo magically appears?
Thanks Wayne
Edit: I found out that something triggers lazy loading of /usr/share/bash-completion/completions/sudo
when I try to autocomplete a sudo command. Looking at set -x when doing the autocomplete, I see that it calls __load_completion sudo
.
So I have a workaround that I have put in my .bashrc:
__load_completion sudo
complete -F _sudo logit
Edit 2:
wwalker@polonium:~$ ls -li /usr/share/bash-completion/completions/sudo*
3017247 -rw-r--r-- 1 root root 1306 2017-09-22 00:25:24.000 /usr/share/bash-completion/completions/sudo
3017249 lrwxrwxrwx 1 root root 4 2019-01-31 08:28:33.000 /usr/share/bash-completion/completions/sudoedit -> sudo
so to cheat the way I was going to, I could do this:
ln -s /usr/share/bash-completion/completions/sudo /home/wwalker/.local/share/bash-completion/completions/logit
and edit the last line to :
complete -F _sudo sudo sudoedit logit