fk: redux

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…

<div markdown=0>


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
}

</div>

0 Responses. Add Yours!

Discussion

blog comments powered by Disqus