Skip to content

Conversation

@Cypher1
Copy link

@Cypher1 Cypher1 commented May 8, 2024

Fixes path handling for the command git-hub-browse to use relative paths.
This enables opening the current working directory or a file in a directory without manually specifying the file path relative to the root.

Proposed Changes

  • Use realpath to get the full path of the file or directory
  • Use git rev-parse --show-toplevel to get the root directory
  • Use sed to remove the root from the full path, making it root relative.
  • Use the pwd (current working directory) as the default path, rather than ""


file="$3"
file="${3:-$(pwd)}"
file="$(command realpath "$file" | sed "s|^$root||")"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love suggestions on the 'proper' way to do this in zsh as I'm not experienced with it and shellcheck doesn't zsh yet.

Copy link

@orzomaxx orzomaxx May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think file="${${file:P}#$root}" will do the work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants