Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have many scripts that are used to start and stop services. It is frustrating when using tab completion that you need to type:

 ./serviceScript.sh [sta|sto]

before there is enough information for tab-completion to complete the word start or stop.

Does anyone have a different pair of words that could be sensibly used in the place of start stop, or alternatively, a better solution to my problem?

share|improve this question
add comment

5 Answers

If you are only looking to avoid typing that much every time, you can use Ctrl + R to see history of commands after typing them once.

After pressing Ctrl + R you can start writing once you start writing as soon as you start writing bash history will complete commands from history. So, if after pressing Ctrl + R you just wrote st and the last command you executed was the command with stop argument that will appear.

If you want an older one e.g., the command with start argument, just pressing Ctrl + R will get you the complete start command.

share|improve this answer
add comment

If the words start and stop are too much to type, why not create aliases which perform one or the other?

# (for bash)
alias myservicebegin='serviceScript.sh start'
alias myserviceend='serviceScript.sh stop'

Of course, if typing is too much effort, you could always make desktop icons/shortcuts for the desired actions, then you only need to click... Only options after this would maybe be a service monkey or something. (ha! service Monkey for services...)

share|improve this answer
add comment

For Bash you can use Bash Completion feature. Install the bash_completion package from your distro. There are good chances that you will have completion for /etc/init.d scripts already. If not, you can read how to make a completion yourself around the net. Here is one link.

Another way is to use a predefined functions like these:

if [[ ${EUID} == 0 ]] ; then # available only for root user
       # rc scripts managing
       rc() { /etc/init.d/$*; }
       complete -o filenames -W "$(cd /etc/init.d/ && echo *)" rc

       rc-start() { for arg in $*; do rc $arg start; done } 
       rc-restart() { for arg in $*; do rc $arg restart; done } 
       rc-stop() { for arg in $*; do rc $arg stop; done } 
       rc-status() { for arg in $*; do rc $arg status; done } 
fi

Here you can use the rc command to call the init.d scripts like: rc apache2 start. This will translate to /etc/init.d/apache2 start. The command also have autocompletion for the files in your init.d directory, i.e. when you type: rc apa[TAB] it will autocomplete to rc apache2.

The other short commands are for convenience: rc-start apache2 will call rc apache2 start and therefore /etc/init.d/apache2 start

Edit: you can change the /etc/init.d path to /etc/rc.d if your distro is using rc.d for services.

share|improve this answer
    
-1: Doesn't address the question. OP is looking for synonyms for "start" and "stop" which don't require you to type three characters before tab completion will distinguish them. He is not looking for how to set up tab completion in the first place. –  Dave Sherohman Jul 4 '12 at 8:28
    
@DaveSherohman, To be clear: as I said in the answer "Another way is to use a predefined functions like these", means the OP can name the functions with different names, not including [start|stop] words... eg. rc-s() , rc-t() ... –  0xAF Jul 4 '12 at 18:22
add comment

The first thing to mind was begin/end, but ./my_service begin doesn't feel quite right semantically.

Run/halt aren't used as often, so they may be harder to remember, but ./my_service run and ./my_service halt seem to work well with the normal English meanings of the words.

Just remember that, if you want init to be able to manage your services, the start and stop commands will still need to be supported even if you put in other commands that are more tab-completion-friendly.

share|improve this answer
add comment

You could try something hacky like this:

a=(/etc/init.d/*(x:t))
function start stop restart reload {  /etc/init.d/$1 $0 }
for i (start stop restart reload) compctl -k a $i

It will allow you to type something like restTabsmaTab which will expand to restart smartmontools and call /etc/init.d/smartmontools restart.

But there might be already some kind of completion function in your zsh distribution for that job. Just have a look around functions/Completion/Unix/.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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