1

Suppose I wanted to kill firefox , I just write pidof fi(press tab)refox (appears on its own) , then I write ' kill 'id given by pidof' ' on terminal.

I know that I can write 'kill `pidof firefox` ' but the autocomplete does not work . So I wanted a command like mykill firefox (on which tab completion also work) which on the background runs 'kill `pidof firefox` '

mykill process name (with tab completion) -> kill `pidof process name`

aabhas
  • 193

1 Answers1

3

Your best bet would to just use the pkill command instead. It can be found in the procps package. You use it like so:

pkill fir<tab>
pkill firefox

To get completion for nested commands, your shell (bash) needs to be smart and enable autocompletion in those scenarios. Unforunately, it looks like it does not. I believe the alternative shell, fish, does.

CameronNemo
  • 1,675
  • I agree on this but there is 1 difference that could matter: you kill all firefoxes and TS method kills 1. There could be 2+ running ;) – Rinzwind Jun 06 '14 at 19:29
  • Thanx for your answer @Cameron , will surely use it but I want to learn how to implement auto complete in shell using bash so hoping that another answer answering that also appears :) I would have also upvoted your answer if i had more than 15 reputation :P – aabhas Jun 06 '14 at 19:46
  • Your shell allows you to create functions in your .bashrc which are available for use just like regular commands. I do not think bash supports autocomplete for functions, though. fish does not either. – CameronNemo Jun 08 '14 at 03:02
  • There are pkill and killall. They can act in a similar way. To spot the differences between them you may give a look to this answer or to the other of the post. – Hastur Jun 11 '14 at 20:22