git-remote: Parameterize hostname
This commit is contained in:
parent
927b367a89
commit
fa77be0b19
5 changed files with 14 additions and 12 deletions
|
@ -10,7 +10,7 @@ in
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
delta
|
delta
|
||||||
git-filter-repo
|
git-filter-repo
|
||||||
github-remote
|
git-remote
|
||||||
tig
|
tig
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,8 @@ in
|
||||||
f = "git commit --fixup";
|
f = "git commit --fixup";
|
||||||
gf = "git fetch --all --jobs 4 --prune";
|
gf = "git fetch --all --jobs 4 --prune";
|
||||||
gff = "git fetch --all --jobs 4 --prune && git merge --ff-only";
|
gff = "git fetch --all --jobs 4 --prune && git merge --ff-only";
|
||||||
gh = "github-remote";
|
gh = "git-remote github.com";
|
||||||
|
gl = "git-remote gitlab.com";
|
||||||
h = "tig --all";
|
h = "tig --all";
|
||||||
hs = "home-manager switch";
|
hs = "home-manager switch";
|
||||||
np = "nix-shell --packages";
|
np = "nix-shell --packages";
|
||||||
|
|
|
@ -25,7 +25,7 @@ specify {
|
||||||
firefox.overlay = w: { buildCommand = w.buildCommand + "\nwrapProgram $executablePath --unset LC_TIME"; }; # Workaround for bugzilla#1269895
|
firefox.overlay = w: { buildCommand = w.buildCommand + "\nwrapProgram $executablePath --unset LC_TIME"; }; # Workaround for bugzilla#1269895
|
||||||
git-diff-image = any;
|
git-diff-image = any;
|
||||||
git-diff-minecraft = any;
|
git-diff-minecraft = any;
|
||||||
github-remote = any;
|
git-remote = any;
|
||||||
gnome.gnome-shell.patch = ../packages/resources/gnome-shell_screenshot-location.patch; # Pending GNOME/gnome-shell#5370
|
gnome.gnome-shell.patch = ../packages/resources/gnome-shell_screenshot-location.patch; # Pending GNOME/gnome-shell#5370
|
||||||
gopass-await.deps = { inherit (stable.gnome) zenity; };
|
gopass-await.deps = { inherit (stable.gnome) zenity; };
|
||||||
gopass-env = any;
|
gopass-env = any;
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
, gnugrep
|
, gnugrep
|
||||||
}:
|
}:
|
||||||
|
|
||||||
resholve.writeScriptBin "github-remote" {
|
resholve.writeScriptBin "git-remote" {
|
||||||
interpreter = "${bash}/bin/bash";
|
interpreter = "${bash}/bin/bash";
|
||||||
inputs = [ git gnugrep ];
|
inputs = [ git gnugrep ];
|
||||||
execer = [ "cannot:${git}/bin/git" ];
|
execer = [ "cannot:${git}/bin/git" ];
|
||||||
} (builtins.readFile ./resources/github-remote)
|
} (builtins.readFile ./resources/git-remote)
|
|
@ -1,31 +1,32 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
if [[ ! ( "${1-}" =~ ^([-_[:alnum:]]+)/([-_.[:alnum:]]+)$ ) ]]; then
|
if [[ ! ( "${2-}" =~ ^([-_[:alnum:]]+)/([-_.[:alnum:]]+)$ ) ]]; then
|
||||||
echo "Usage: ${0##*/} <owner>/<repo>" >&2
|
echo "Usage: ${0##*/} <hostname> <owner>/<repo>" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
hostname="$1"
|
||||||
owner="${BASH_REMATCH[1]}"
|
owner="${BASH_REMATCH[1]}"
|
||||||
repo="${BASH_REMATCH[2]}"
|
repo="${BASH_REMATCH[2]}"
|
||||||
|
|
||||||
https="https://github.com/$owner/$repo.git"
|
https="https://$hostname/$owner/$repo.git"
|
||||||
ssh="git@github.com:$owner/$repo.git"
|
ssh="git@$hostname:$owner/$repo.git"
|
||||||
|
|
||||||
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||||
if git remote | grep --quiet "^$owner$"; then
|
if git remote | grep --quiet "^$owner$"; then
|
||||||
echo "Configuring GitHub remote $owner/$repo for HTTPS fetch and SSH push" >&2
|
echo "Configuring remote $owner/$repo for HTTPS fetch and SSH push" >&2
|
||||||
|
|
||||||
git remote set-url "$owner" "$https"
|
git remote set-url "$owner" "$https"
|
||||||
git remote set-url --push "$owner" "$ssh"
|
git remote set-url --push "$owner" "$ssh"
|
||||||
else
|
else
|
||||||
echo "Adding GitHub remote $owner/$repo with HTTPS fetch and SSH push" >&2
|
echo "Adding remote $owner/$repo with HTTPS fetch and SSH push" >&2
|
||||||
|
|
||||||
git remote add -f "$owner" "$https"
|
git remote add -f "$owner" "$https"
|
||||||
git remote set-url --push "$owner" "$ssh"
|
git remote set-url --push "$owner" "$ssh"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Cloning from GitHub remote $owner/$repo with HTTPS fetch and SSH push" >&2
|
echo "Cloning from remote $owner/$repo with HTTPS fetch and SSH push" >&2
|
||||||
|
|
||||||
git clone --origin "$owner" "$https" "$repo"
|
git clone --origin "$owner" "$https" "$repo"
|
||||||
cd "$repo"
|
cd "$repo"
|
Loading…
Reference in a new issue