Adding init.d service (chkconfig / autocomplete in shell)

Switch picture Switch · Sep 30, 2011 · Viewed 24.2k times · Source

I've made a startup script, (i.e. myserviced) and put it in /etc/init.d/

I ran

chkconfig --add myserviced

I can start/stop/restart the service just find using:

service myserviced start

etc. However, I notice that when I type "service" and then do TAB (to get a list of possible completions), I don't see myserviced in the list of possible completions (it lists all the other services). How do I add myserviced to the auto-completion list?

This is in zsh on RHEL.

Thanks

Answer

Koby picture Koby · Nov 4, 2012

you can use the following command to add all listed scripts in /etc/init.d/ to the service command:

complete -W "$(ls /etc/init.d/)" service

-W will create word list from the ($)specified path which 'service' will use for auto-complete.