Using Smart Selection in iTerm2 to make Asana task ID (or any text) clickable
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
+to add a new Smart Selection Rule entry
- Set a Note, for example:
Asana Task ID
- Set a regular expression:
(This will match our task ID text
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…”
- Choose “Open URL…” action with parameter:
0in 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
\1is the task ID.
- Click “Ok” (yes, the lower case
kbothers 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.
open $(git config — get remote.origin.url)/commit/\0
\0represents 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.
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! :)