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; [
|
||||
delta
|
||||
git-filter-repo
|
||||
github-remote
|
||||
git-remote
|
||||
tig
|
||||
];
|
||||
|
||||
|
|
|
@ -126,7 +126,8 @@ in
|
|||
f = "git commit --fixup";
|
||||
gf = "git fetch --all --jobs 4 --prune";
|
||||
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";
|
||||
hs = "home-manager switch";
|
||||
np = "nix-shell --packages";
|
||||
|
|
|
@ -25,7 +25,7 @@ specify {
|
|||
firefox.overlay = w: { buildCommand = w.buildCommand + "\nwrapProgram $executablePath --unset LC_TIME"; }; # Workaround for bugzilla#1269895
|
||||
git-diff-image = 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
|
||||
gopass-await.deps = { inherit (stable.gnome) zenity; };
|
||||
gopass-env = any;
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
, gnugrep
|
||||
}:
|
||||
|
||||
resholve.writeScriptBin "github-remote" {
|
||||
resholve.writeScriptBin "git-remote" {
|
||||
interpreter = "${bash}/bin/bash";
|
||||
inputs = [ git gnugrep ];
|
||||
execer = [ "cannot:${git}/bin/git" ];
|
||||
} (builtins.readFile ./resources/github-remote)
|
||||
} (builtins.readFile ./resources/git-remote)
|
|
@ -1,31 +1,32 @@
|
|||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
if [[ ! ( "${1-}" =~ ^([-_[:alnum:]]+)/([-_.[:alnum:]]+)$ ) ]]; then
|
||||
echo "Usage: ${0##*/} <owner>/<repo>" >&2
|
||||
if [[ ! ( "${2-}" =~ ^([-_[:alnum:]]+)/([-_.[:alnum:]]+)$ ) ]]; then
|
||||
echo "Usage: ${0##*/} <hostname> <owner>/<repo>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
hostname="$1"
|
||||
owner="${BASH_REMATCH[1]}"
|
||||
repo="${BASH_REMATCH[2]}"
|
||||
|
||||
https="https://github.com/$owner/$repo.git"
|
||||
ssh="git@github.com:$owner/$repo.git"
|
||||
https="https://$hostname/$owner/$repo.git"
|
||||
ssh="git@$hostname:$owner/$repo.git"
|
||||
|
||||
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; 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 --push "$owner" "$ssh"
|
||||
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 set-url --push "$owner" "$ssh"
|
||||
fi
|
||||
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"
|
||||
cd "$repo"
|
Loading…
Reference in a new issue