Skip to content

Add feature to resolve URL local file, open in editor of choice

Michael Trainor requested to merge tmike-reverse-parse-url into main

Sometimes I have a GitLab URL that I want to investigate on my local repo with my editor of choice. Currently, I have to copy and paste the relevant file path, and then open my editor manually.

This change will allow parsing the URL and resolving to a local file in the repository, and open in the editor of choice, at the line number(s) specified in the URL. If the ref in the URL is different to what is checked out currently, you will be asked to checkout the required ref to view the file.

Your PWD must be within the repository's path for this to resolve. Otherwise, nothing will be returned.

Editor of choice is either the :edit CLI option (-e), or the $EDITOR environment variable, in that order.

To do:

  • Use parsed ref to open file at specific ref (commit sha, branch, tag, etc). Currently file is opened at current HEAD.
  • Allow selection of line ranges in editors. Currently only first line is selected.
  • Support more editors. Currently only vim and code are supported.
  • Support branch refs with forward slash in name. Hard to determine where branch name ends and file path begins in a URL.
  • Error handling for unknown refs, eg deleted branches

Screenshots

  1. Open file via URL with ref as tag (when $EDITOR is set to vim)

Screen_Shot_2022-08-21_at_5.52.36_pm Screen_Shot_2022-08-21_at_5.53.22_pm

  1. Open file via URL with ref as branch, specifying editor with -e option:

Screen_Shot_2022-08-21_at_9.05.04_pm Screen_Shot_2022-08-21_at_9.05.17_pm

Edited by Michael Trainor

Merge request reports