Last active
September 1, 2021 11:25
-
-
Save Foxhound401/72b6dbf7b6e474b885cbad7233a15300 to your computer and use it in GitHub Desktop.
Clone repo in bitbucket with multiple different email account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#### | |
# Helper to working with multiple Bitbucket accounts | |
# | |
# How to use | |
# change the YOUR_SSH_KEY to your your ssh-key name | |
# | |
# chmod +x gitdf.sh | |
# ./gitdf.sh [email protected]:eastplayer/your-repo.git | |
# | |
# credit: TUNG MANH VU - https://github.com/vmtung for all the stuggle he encouter | |
# youtube channel: https://www.youtube.com/channel/UCjzozBrNDFTWfXFef7Mik2g | |
# | |
#### | |
set -e | |
# keep track of the last executed command | |
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG | |
# echo an error message before exiting | |
trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT | |
# TODO dynamic ssh-key files allow option to choose the file | |
CLONE_URL="$1" | |
SSH_SRC=$(find ~/.ssh -type f | grep -v ".pub" | dmenu -l 4 -p "Choose your ssh-key: ") | |
echo -e "\e[44mExtract directory name\e[0m" | |
echo " " | |
DIR_NAME=$(echo $CLONE_URL | awk -F/ '{print $2}' | awk -F. '{print $1}') | |
echo -e "\e[32m*** $DIR_NAME ***\e[0m" | |
echo " " | |
ssh-agent bash -c "ssh-add $SSH_SRC; git clone ${CLONE_URL}" | |
echo -e "\e[34mFinished clone project.\e[0m" | |
echo " " | |
sleep 1 | |
echo -e "\e[31mAdding ssh-key file...\e[0m" | |
echo " " | |
sed -i "/logallrefupdates/ a sshCommand = ssh -i $SSH_SRC -o 'IdentitiesOnly yes' -F /dev/null" ./${DIR_NAME}/.git/config && echo -e "\e[34mKey Successfully Added!!!\e[0m" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment