DEV Community

OnFileNotWanted
OnFileNotWanted

Posted on

2 1

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.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay