Created
March 23, 2023 14:27
-
-
Save avegancafe/0bab39c875338b713c75db37633d9734 to your computer and use it in GitHub Desktop.
Fuzzy-find and kill processes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fkill --description 'Fuzzy-find process and kill it' | |
set -l fzf_args --reverse --height 40% --no-hscroll -n 8 --ansi --multi | |
set -l pid | |
if test (id -u) -eq 0 | |
set pid (ps -f -u $UID | sed 1d | fzf $fzf_args | awk '{print $2}') | |
else | |
set pid (ps -ef | sed 1d | fzf $fzf_args | awk '{print $2}') | |
end | |
echo $pid | |
if test "$pid" = '' | |
return | |
end | |
set -l process_name (ps -o command= -p $pid) | |
log "Killing '$process_name'..." | |
echo $pid | xargs kill -9 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment