Skip to content

Instantly share code, notes, and snippets.

@wknapik
Last active December 3, 2021 16:17
Show Gist options
  • Select an option

  • Save wknapik/bd6e3c4c75c85ad4c3a8e6fea640792e to your computer and use it in GitHub Desktop.

Select an option

Save wknapik/bd6e3c4c75c85ad4c3a8e6fea640792e to your computer and use it in GitHub Desktop.

Revisions

  1. wknapik revised this gist Dec 3, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion repolink.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Requires: bash, coreutils, git.
    # Requires: bash (I use it in zsh), coreutils, git.

    # Print link(s) to file(s) in repo(s), with optional line numbers.
    # $@ := file_path[:file_line] [ file_path2[:file_line2] [ ... ] ]
  2. wknapik revised this gist Oct 20, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion repolink.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Requires: bash, coreutils, git.

    # Print link(s) to file(s) in a repository, with optional line numbers.
    # Print link(s) to file(s) in repo(s), with optional line numbers.
    # $@ := file_path[:file_line] [ file_path2[:file_line2] [ ... ] ]
    repolink() {
    local branch f file host origin url_path
  3. wknapik revised this gist Oct 20, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion repolink.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # Print link(s) to file(s) in a repository, with optional line numbers.
    # $@ := file_path[:file_line] [ file_path2[:file_line2] [ ... ] ]
    repolink() {
    local branch f file host origin
    local branch f file host origin url_path
    for f in "$@"; do
    file="$(realpath "$f")"
    checkout_path="$(git -C "$(dirname "$file")" rev-parse --show-toplevel)"
  4. wknapik revised this gist Oct 20, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions repolink.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Requires: bash, coreutils, git.

    # Print link(s) to file(s) in a repository, with optional line numbers.
    # $@ := file_path[:file_line] [ file_path2[:file_line2] [ ... ] ]
    repolink() {
  5. wknapik renamed this gist Oct 20, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. wknapik created this gist Oct 20, 2021.
    20 changes: 20 additions & 0 deletions repolink
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # Print link(s) to file(s) in a repository, with optional line numbers.
    # $@ := file_path[:file_line] [ file_path2[:file_line2] [ ... ] ]
    repolink() {
    local branch f file host origin
    for f in "$@"; do
    file="$(realpath "$f")"
    checkout_path="$(git -C "$(dirname "$file")" rev-parse --show-toplevel)"
    origin="$(git -C "$checkout_path" config --get remote.origin.url)"
    branch="$(git -C "$checkout_path" rev-parse --abbrev-ref HEAD)"
    host="${origin#*://}" # strip off scheme
    host="${host#*@}" # strip off user
    host="${host/:[0-9]*\//\/}" # strip off port
    host="${host//://}" # replace : with /
    host="${host%.git}" # strip off .git suffix
    host="${host%/}" # strip off trailing /

    url_path="${file#"$checkout_path"/}"
    echo "https://$host/blob/$branch/${url_path/:/#L}"
    done
    }