BBedit’s shell worksheet can be a really handy tool for batch renaming files. I was inspired to give it a shot after seeing a script that handed off a directory listing for editing. Here’s a really trivial example. Let’s say I have a directory containing the following files (and I’ve cd‘d to it in the worksheet):
And let’s say those files are actually Markdown, so I want to change the extension to .md.
First, type ls and execute it with Control-Return to get the listing of those files in your worksheet window. The result looks like the example above.
Next, highlight the listing, and bring up the “Find” dialogue. Make sure that “Grep” and “Selected text only” are selected.
Enter the pattern (.*?)(\.txt), meaning a lazy search of any characters up to a literal .txt, broken into two tokens. The first token is the file name, the second token is the extension. You want to replace that with mv \1\2 \1.md;. The result will look like this:
Select those lines and execute them using Control-Return. If you do another ls, you’ll see your files have been renamed.
This example is really simple, just to get you thinking about the kind of file renaming you can do. Remember that a shell worksheet in BBEdit is a regular editing window. Any snippets, scripts, or text factory you have set up are available to you.
I’ve moved on from ps aux | grep -i processname; kill PID. The Mac (along with many other Unix-likes) has two handy utilities: pgrep and pkill. pgrep does a case-insensitive search for processes matching the expression you provide, and returns all matching PIDs, one per line. pkill does the same search, but just kills the matching processes instead of returning the PIDs.
A common use case for me is middleman hanging when I change the config.rb. I could kill it using the following:
kill `pgrep middleman`
One of the benefits of using pkill is that you can run the command interactively. Handy if you end up searching on the scripting language running the process, rather than something a bit more unique.