Skip to content

Instantly share code, notes, and snippets.

@andresjesse
Created October 3, 2023 01:26
Show Gist options
  • Save andresjesse/7b57f6605655258f50d995b1e7ad918c to your computer and use it in GitHub Desktop.
Save andresjesse/7b57f6605655258f50d995b1e7ad918c to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
# Changelog:
# 2023-10-02: initial version
# To install:
# chmod a+x ssh-git-cmd.py
# sudo ln -s $(pwd)/ssh-git-cmd.py /usr/local/bin/ssh-git-cmd.py
import os, sys
from pathlib import Path
dirs = os.listdir(str(Path.home())+'/.ssh')
print("Select SSH Key for repository:")
for index, ssh_key in enumerate(dirs):
if ssh_key.endswith(".pub"):
print('\t', index, ssh_key)
x = int(input())
cmd = 'git -c core.sshCommand="ssh -i '+str(Path.home())+'/.ssh/'+dirs[x][:-4]+'" '+' '.join(sys.argv[1:])
print('Executing:')
print('\t',cmd)
os.system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment