walls.corpus

By Nathan L. Walls

Tool Sharpening: Jan 1, 2015

For some background on what’s going on here, see the first tool sharpening post

Environment + Process tweaks

I added several zsh aliases for some Git actions that are becoming more common for me, when working on feature branches

1
2
3
4
5
alias gsl='git stash list'
alias gssv='git stash save'
alias gss='git stash show'
alias gssp='git stash show -p'
alias gsp='git stash pop'

These are particularly useful when I’m in the middle of work on a repository and I want to do anything else, like run a git bisect or examine another branch.

Another use case I have is searching, with find or with ag, then opening resulting files in BBEdit.

A typical case looks like this:

1
ag -l foo -print0 | xargs bbedit

In this example, any file in the current directory or below containing the term ‘foo’ will be opened in BBEdit. The find version is very similar for cases when I want to open all files with a name containing ‘foo’.

1
find . -name '2014*' -print | xargs bbedit

Rather than type these commands out every time, I want to type a much shorter command and the search string, like so:

1
bbf foobar

or

1
bbg foobar

It would be easiest for me, by experience, to implement each of these in Ruby or Perl. Instead, I chose to implement these as zsh shell functions. I used Erich Smith’s Composure shell library to build the functions. The resulting code looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# author, about, param, example and group are Composure functions
# ag is the Silver Searcher (brew install ag)
bbf () {
    author 'Nathan L. Walls'
    about 'Function to find files matching a term and open them in BBEdit'
    param '1: Term to search for via `find . -name`'
    example 'bbf 2014*'
    group 'utility'

    find . -name '$*' -print | to_bbedit
}

bbg () {
    author 'Nathan L. Walls'
    about 'Func. to open files containing a term in BBEdit'
    param '1: Term to search for via `ag -l`'
    example 'bbg foo'
    group 'utility'

    ag -l $* -print0 | to_bbedit
}

to_bbedit () {
    author 'Nathan L. Walls'
    about 'Func. to open files in BBEdit through xargs, via a pipe'
    param 'None, implied to come through xargs'
    example 'ls | to_bbedit'
    group 'utility'

    xargs bbedit
}

One other use case I have for this sort of thing doesn’t even require opening files, necessarily, and that’s seeing what files I have that have the word “focus” within them, except spec_helper.rb, in my Ruby projects. This way, I can keep from committing code with focus: true in place and save myself the step of rerunning tests and amending a commit. That looks like this:

1
alias foc='ag -l focus --ignore spec_helper.rb

Or, at least it did until I thought about it a little more and wanted to make it a function as well. Now, it looks like this, instead:

1
2
3
4
5
6
7
8
9
foc () {
    author 'Nathan L. Walls'
    about "Find errant 'focus: true' statements before committing"
    param 'None'
    example 'foc'
    group 'testing'

    ag -l 'focus: true' --ignore spec_helper.rb
}

Why not use an alias here? Partly because I’m enjoying using Composure and partly because I believe I might make further use of this foc () function elsewhere.

There’s still a bit more I could do with these functions, namely adding some error checking, but these will get the job done for me well enough.

I also:

  • Tweaked BBEdit 11 settings to limit the scope of clippings used for given languages, which keeps me from getting cross-language clipping pollution. In my case, there was a large set of PHP clippings coming up when I was looking for Ruby clippings. And now, I’m not
  • Found a way to Save All open documents in BBEdit, Cmd-Opt-S
  • Added TextExpander shortcuts related to writing Git commit messages
  • Updated my work machine to the dotfiles set-up I highlighted in the previous tool-sharpening entry
  • Created a Cider profile to get my Homebrew set-up into source control
  • Updated Git to address a Mac OS X vulnerability

Project work

  • No project work since the last entry

Skill improvements

See above regarding working with Composure to write shell functions. Overall, I’m finding Composure a really nice little framework for iterating over commands quickly and making them understandable later. It was starting to write these commands and then trying to remember Smith’s presentation at Triangle Ruby Brigade back in August 2014 about Composure that led to my coworker Steve finding Smith’s lightning talk.