Score:3

How to make alias to systemctl with autocomplete

us flag

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

Score:6
cn flag

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

Artur Meinild avatar
vn flag
I had been wondering about this for some time - thanks for a good solution. ;-)
Score:0
us flag

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
bac0n avatar
cn flag
where did you put it?
tehkonst avatar
us flag
@bac0n In the terminal. Or in ~/.bashrc file in my case.
bac0n avatar
cn flag
no need for an alias.
tehkonst avatar
us flag
I thought so, but somehow it didn't work.
bac0n avatar
cn flag
yep wrong of me.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.