Skip to content

Instantly share code, notes, and snippets.

@loopmode
Last active November 8, 2022 08:23
Show Gist options
  • Save loopmode/eb038abf2e58f464073ad3cc26c05765 to your computer and use it in GitHub Desktop.
Save loopmode/eb038abf2e58f464073ad3cc26c05765 to your computer and use it in GitHub Desktop.
"kill" function for git bash on windows
kill() {
local name="${1}"
if [ -z "$name" ];
then
echo ">> Enter a process name and press [ENTER] (partial matching)"
read name
fi
wmic process where "name like '%$name%'" delete
}
alias kill-java="kill java"
alias kill-node="kill node"
alias kill-bash="kill bash"
alias kill-chrome="kill chrome"

kill for windows

A shortcut to eliminate processes on windows.

In a typical web development workflow on windows, we are working with git bash rather than cmd or PowerShell. Windows has a nifty but verbose way of killing processes based on a (partial) match of the process name: wmic process where "name like '%some string%'" delete. This function is just a convenience wrapper around it.

Usage

There are two ways of using the function: With argument or without.

with argument

When called with an argument, any process that has a name matching the argument will be killed.

This example kills any java process, but also any other process with jav in the name (like an imaginary javelin process):

$ kill jav

without argument

If you just type kill and hit enter, you will be prompted for a process name/matcher to kill. You then type it in a second step and hit enter again:

$ kill
>> Enter a process name and press [ENTER] (partial matching)
jav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment