git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/git-other-branches12
-rwxr-xr-xbin/git-update-all17
-rwxr-xr-xbin/ssh-with-gpg20
3 files changed, 49 insertions, 0 deletions
diff --git a/bin/git-other-branches b/bin/git-other-branches
new file mode 100755
index 0000000..034670e
--- /dev/null
+++ b/bin/git-other-branches
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+
+GITBIN='/usr/bin/git'
+AWKBIN='/usr/bin/awk'
+GREPBIN='/usr/bin/grep'
+
+# 1. Pull the current branch and also tags, and prune references vanished from remote
+# shellcheck disable=SC2016
+"$GITBIN" branch --remotes |\
+ "$AWKBIN" '{print $1}' | "$AWKBIN" -F/ '{print $2}' |\
+ "$GREPBIN" -v "^$(git rev-parse --abbrev-ref HEAD)\$" |\
+ "$GREPBIN" -v '^HEAD$'
diff --git a/bin/git-update-all b/bin/git-update-all
new file mode 100755
index 0000000..d3f6033
--- /dev/null
+++ b/bin/git-update-all
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+GITBIN='/usr/bin/git'
+
+# 1. Pull the current branch and also tags, and prune references vanished from remote
+"$GITBIN" pull -tpf || exit 110
+# 2. Pull all branches existing locally
+mybr="$("$GITBIN" branch --show-current)"
+while read -r branch
+do
+ (
+ printf '\033[1m\033[3mSwitching to %b.\033[0m\n' "$branch"
+ "$GITBIN" switch "$branch" &&\
+ "$GITBIN" pull &&\
+ "$GITBIN" switch "$mybr"
+ )
+done < <("$GITBIN" branch --list|awk '{print $NF}'|grep -vP "^${mybr}\$")
diff --git a/bin/ssh-with-gpg b/bin/ssh-with-gpg
new file mode 100755
index 0000000..7ca0d67
--- /dev/null
+++ b/bin/ssh-with-gpg
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+
+# For this to work, you also need to import the public key of any private key you want to use
+# in the target server's pubring first.
+
+if [ -z "$1" ];then
+ printf "USAGE: %b TARGET [OPTIONS...]\\n" "$(basename "$0")" >&2
+ exit 1
+fi
+
+TGT="$1"
+
+REMUID="$(ssh "$TGT" "id -u")"
+ssh "$TGT" 'killall gpg-agent 2>/dev/null;rm -f /run/user/$(id -u)/gnupg/S.*'
+if [ -z "$REMUID" ];then
+ printf "Cannot fetch user id from %b.\\n" "$TGT" >&2
+ exit 2
+fi
+
+ssh -R "/run/user/${REMUID}/gnupg/S.gpg-agent":"/run/user/$(id -u)/gnupg/S.gpg-agent-extra" -o "StreamLocalBindUnlink=yes" "$TGT" "${@:2}"