DEV Community

OnFileNotWanted
OnFileNotWanted

Posted on

kill processes with fzf

fkill

we can use a shell function, in this case im using zsh

fkill - kill process

fkill() { pid=$(ps -ef | sed 1d | fzf -m --ansi --color fg:-1,bg:-1,hl:46,fg+:40,bg+:233,hl+:46 --color prompt:166,border:46 --height 40% --border=sharp --prompt="➤ " --pointer="➤ " --marker="➤ " | awk '{print $2}') if [ "x$pid" != "x" ] then kill -${1:-9} $pid fi } select_file() { given_file="$1" #fd --type file --follow --hidden --exclude .git | fzf --query="$given_file" fzf --query="$given_file" } 
Enter fullscreen mode Exit fullscreen mode

or call a script directly

#!/usr/bin/bash ## uncomment lines 4-11 then add to zsh keybinds (default is ctrl+k) #use fzf to kill proccesses ## fkill_widget() { ## sh $HOME/scripts/fkill # call fkill script locus ## zle reset-prompt ## } ## zle -N fzf-redraw-prompt # give me my $PS1 back ## zle -N fkill_widget ## bindkey '^k' fkill_widget #ctrl+k ################ fkill script start ########### if [ "$UID" != "0" ] then pid=$(ps -f -u $UID | sed 1d | fzf -m --ansi --color fg:-1,bg:-1,hl:46,fg+:40,bg+:233,hl+:46 --color prompt:166,border:46 --height 30% --border=sharp --prompt="➤ " --pointer="➤ " --marker="➤ " | awk '{print $2}') else pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}') fi if [ "x$pid" != "x" ] then echo $pid | xargs kill -${1:-9} fi ############## fkill script end ############# 
Enter fullscreen mode Exit fullscreen mode

Download script inline link.

Top comments (0)