From 8cd7957e2cd3be7b6e7d16b3ec54715a7f035cd1 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 16 Jan 2020 00:55:50 +0000 Subject: [PATCH] Add git.sh script Allows for using git commands whilst specifying a SSH key to use. See https://alvinabad.wordpress.com/2013/03/23/how-to-specify-an-ssh-key-file-with-the-git-command. --- bin/git.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 bin/git.sh diff --git a/bin/git.sh b/bin/git.sh new file mode 100755 index 0000000..9be64da --- /dev/null +++ b/bin/git.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# The MIT License (MIT) +# Copyright (c) 2013 Alvin Abad + +if [ $# -eq 0 ]; then + echo "Git wrapper script that can specify an ssh-key file +Usage: + git.sh -i ssh-key-file git-command + " + exit 1 +fi + +# remove temporary file on exit +trap 'rm -f /tmp/.git_ssh.$$' 0 + +if [ "$1" = "-i" ]; then + SSH_KEY=$2; shift; shift + echo "ssh -i $SSH_KEY \$@" > /tmp/.git_ssh.$$ + chmod +x /tmp/.git_ssh.$$ + export GIT_SSH=/tmp/.git_ssh.$$ +fi + +# in case the git command is repeated +[ "$1" = "git" ] && shift + +# Run the git command +git "$@"