Happy New Year everyone! My first post of 2017 is going to be a very short, but it may just help you speed up your terminal workflow.
Two tools I use on a day to day basis are iTerm2 and JIRA from Atlassian. iTerm2 is a terminal replacement app for OSX, and if you haven’t used it before you really should give it a try (I’ve mentioned it before in a previous blog post). JIRA is the go to web application for bug tracking; it also works well with the rest of the Atlassian suite.
For a while I’ve wanted to be able to open tickets right from the terminal window. This would come in extremely helpful when looking at a
git log output like the one below for example:
Luckily iTerm2 comes with a whole host of features, one of which is called ‘Smart Selection’. You may not have noticed this before, but if you click multiple times on certain types strings they will be selected as a whole (email addresses, filesystem paths, URI’s). This is Smart Selection in action. iTerm2 looks at the string directly under the cursor, runs a set of matching Regex’s against it, and then allows you to run the relevant action against it.
We can use this feature to open the JIRA ticket page relating to the issue listed in our git logs like so:.
Adding this functionality is very simple. Under iTerm2 preferences go to ‘Profiles’, then the ‘Advanced’ tab. Here you will see the ‘Smart Selection’ edit button. See the images below for the sample settings I’ve used:
^[project-ticket-prefix]-(\d+) to the Regex rules, then edit the corresponding action and add Open URL.. with your JIRA URL. Note: This assumes the string starts with the ticket prefix, which is the case in my git logs. You may need to adjust this for your own setup.
After that you should be able to right click on one of your tickets whenever they appear in the terminal and see the ‘Open JIRA Ticket’ option. Simple!
If you’re a ZSH user, you may also be interested in the JIRA plugin that allows you to interact with your JIRA instance via the CLI. I’ve yet to use it myself, but it does look like it could be quite useful.