Mar 06
2010
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
}
Nov 17
2009
I do a lot in Terminal. Sometimes, it’s easier. Sometimes it’s faster. Sometimes I’d just rather type it out. Whatever the reason, I’ve never been able to stand looking at a boring shell prompt. Bash is my primary shell, mostly because I’ve never taken the time to learn much else. I’ll get there someday. For now, here’s my current Bash shell prompt…
I’m using the PROMPT_COMMAND variable to run a few quick functions to generate the prompt. It doesn’t do anything processor-intensive, so I haven’t seen any lag caused by this one (unlike some of my previous experiments). PROMPT_COMMAND is set to call a function called, appropriately, prompt_command(). This, in turn, calls a few external functions defined in my .bash_profile. To use it, just stick all of the code below into your .bash_profile, and modify it as you see fit. Be sure to replace any definitions of PROMPT_COMMAND or PS1.
Continue reading “My new favorite Bash prompt…”
Nov 14
2009
This is a function from my OS X .bash_profile. ‘fk’ is short for Find and Kill, and it lets you do a quick search of your running processes for a case-insensitive partial match of the first parameter passed to it. It’s useful for quickly finding a process without worrying about its capitalization or full spelling, and without having to sift through (or manually grep) a long ps ax list.
Continue reading “fk: a useful bash function…”