Opening a Linear ticket in your browser based on the current branch
For a project I a working no we are using Linear to manage our to-do’s. In Linear there’s a bunch of tickets and when we start working on one we will create a branch for it.
A typical branch name looks something like: feature/sp-14-user-login
.
To make it a bit easier to open the Linear ticket I’m working on from my CLI I made a little function and added it to my .zshrc
file. This way I can just run the command lin
and the ticket opens up in my browser.
If you want to use it you can simply copy the script below inside your .zshrc
(or .bashrc
) file, and modify the projects to the ones you are working on.
After updating, make sure to run source ~/.zshrc
or source ~/.bashrc
to reload your settings.
function lin() { # Get the current branch name branch_name=$(git rev-parse --abbrev-ref HEAD) # Extract the ticket identifier (e.g., sp-123) ticket_identifier=$(echo "$branch_name" | grep -oE '[a-z]+-[0-9]+') if [ -n "$ticket_identifier" ]; then # Extract the project key (e.g., sp) project_key=$(echo "$ticket_identifier" | cut -d'-' -f1) # Build the URL based on the project key case "$project_key" in sp) url="https://linear.app/spatie/issue/$ticket_identifier" ;; xy) url="https://linear.app/xyz-project/issue/$ticket_identifier" ;; *) echo "Unknown project key: $project_key" return 1 ;; esac # Open the URL open "$url" else echo "No ticket identifier found in branch name." fi }
I imagine this script should be easy to modify to support most other popular issue trackers.
Enjoy!