Skip to content

Instantly share code, notes, and snippets.

@Seltyk
Created August 13, 2023 15:19
Show Gist options
  • Save Seltyk/f8deaba6e367496f26222f784ede9c4c to your computer and use it in GitHub Desktop.
Save Seltyk/f8deaba6e367496f26222f784ede9c4c to your computer and use it in GitHub Desktop.
Destroy any process matching a PCRE
#!/bin/zsh
# Nuclear option: kill any program whose process/command matches a PCRE.
# Options for `kill` are passed directly to it, e.g. `nuke -9 foo` runs `kill -9 pidof_foo`.
# Note: a more portable alternative to $@[-1] may be to `eval last=\$$#` then use `$last`.
# Note: making $@[1,-2] more portable might be a bit harder. I have no clue how it'd be done.
[[ $# -eq 0 ]] && echo "Usage: nuke [KILLOPTS] PROG" && return 1 || ps ax | grep -iP "^(?!.*grep).*$@[-1]" | awk '{print $1}' | xargs -I {} kill $@[1,-2] {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment