Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add relative path fix to git-hub-browse #2087

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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 ""

@@ -42,7 +44,8 @@ if [[ "$reference" == 'HEAD' ]]; then
reference="$(command git rev-parse HEAD 2> /dev/null)"
fi

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

@ErrrorMaxx ErrrorMaxx 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