Using Smart Selection in iTerm2 to make Asana task ID (or any text) clickable

⌘+click Asana task ID in commit message to open task in browser

Our team uses GitHub+Asana integration to link a git commit and Asana task together. This is done by putting task ID in the commit, something like[#420747128324311] Fix broken tests.

One thing I notice in iTerm2 is if we hold and hover around texts, URLs will be highlighted and clickable. It would be nice if I can do this to other text as well. It turns out there’s a feature in iTerm2 that can help us — it’s called Smart Selection.

Making Asana task ID clickable

Basically, we need to set up some regex and the assign action when clicked. Here are the steps:

  • Open iTerm2, go to…
    Preferences… > Profile > Advanced tab > Smart Selection > Edit
  • Click + to add a new Smart Selection Rule entry
  • Set a Note, for example:Asana Task ID
  • Set a regular expression: \[#(\d+)\] 
    (This will match our task ID text[#420747128324311])
To refresh your regex knowledge, see this cheat sheet and playground.
  • Set precision to “Very Low”. It works fine for me.
  • Double-click on the rule, or click on “Edit Actions…”
Smart Selection Edit Action menu
The second 0 in the url is a replacement for the unknown project ID of that task. It will be redirected to the correct project. As I have played around, this place holder can be any number. The \1 is the task ID.
  • Click “Ok” (yes, the lower case k bothers me too) and then click “Close” to make the changes take effect.
  • Now, try to hold and hover on the task ID, it should be highlighted and clickable! 🎉

Cool! What else can we click?

Now let’s make git commit hash clickable. When you do git reflog , you will see a 9-digit hex string on the left of each commit.

  • regex:^[a-f0–9]{9}
  • action:open $(git config — get remote.origin.url)/commit/\0
The \0 represents the whole regex match, which is our commit hash.

But there’s one difference. Seems like the command doesn’t work with “Open URL…” action. I need to use “Run command in window…” instead. It will spawn a new terminal window for a moment and then close. Your GitHub commit page should be opened correctly.

Summary

That’s it. Hope this will help boost your productivity. Please share with me what you use Smart Selection for. I will be very exited to hear from you guys! :)

Reference

https://gitlab.com/gnachman/iterm2/issues/2975

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.