3

I tried

alias sct='systemctl'
complete -F _systemctl sct

But the function _systemctl is not found until I run the original command systemctl in the session. This function loads dynamically or somehow and contains many other same functions inside.

OS - Ubuntu 20.04

6

Create a file named /etc/bash_completion.d/systemctl:

if [[ -r /usr/share/bash-completion/completions/systemctl ]]; then
    . /usr/share/bash-completion/completions/systemctl && complete -F _systemctl systemctl sct
fi

You can restart bash-completion by sourcing . /etc/bash_completion

1
  • 1
    I had been wondering about this for some time - thanks for a good solution. ;-) Oct 22 at 7:47
0

I found a file with autocomplete functions for systemctl in my system and added a line to load it:

source /usr/share/bash-completion/completions/systemctl
alias sct='systemctl'
complete -F _systemctl sct
5
  • where did you put it?
    – bac0n
    Oct 22 at 6:44
  • @bac0n In the terminal. Or in ~/.bashrc file in my case.
    – tehkonst
    Oct 22 at 6:55
  • no need for an alias.
    – bac0n
    Oct 22 at 7:02
  • I thought so, but somehow it didn't work.
    – tehkonst
    Oct 22 at 7:03
  • 1
    yep wrong of me.
    – bac0n
    Oct 22 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.