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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion modules/git/functions/git-hub-browse
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then
return 1
fi

root="$(command git rev-parse --show-toplevel)"

local remotes remote references reference file url

remote="${1:-origin}"
Expand Down Expand Up @@ -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


if [[ -n "$url" ]]; then
url="$url/tree/$reference/$file"
Expand Down