Home Link

Hello, my name is Brett Terpstra, and it’s nice to meet you. Elegant solutions to complex problems. Curious?

fk: redux

Mar 06, 2010 (147 days ago)

Just a quick change to my post on the bash function fk that I've been using. A small modification has greatly improved its usability: make the cancel option always be first in the menu. Just move "Cancel" before the $(fp $1) bit. It's a little odd that I didn't do that to begin with...


fp () { #find and list processes matching a case-insensitive partial-match string
        ps Ao pid,comm|awk '{match($0,/[^\/]+$/); print substr($0,RSTART,RLENGTH)": "$1}'|grep -i $1|grep -v grep
}

fk () { 
    IFS=$'\n'
    PS3='Kill which process? (1 to cancel): '
    select OPT in "Cancel" $(fp $1); do
        if [ $OPT != "Cancel" ]; then
            kill $(echo $OPT|awk '{print $NF}')
        fi
        break
    done
    unset IFS
}

Leave a Reply

Comments may use standard Markdown formatting

Entries (RSS) and Comments (RSS).