UNPKG

use-multiple-gits

Version:

CLI tool to manage multiple git configurations (user.name, user.email, SSH keys) with easy switching between identities

58 lines (49 loc) 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateSwitchScript = void 0; const generateSwitchScript = (config, shell = 'zsh') => { if (shell === 'powershell') { return generatePowerShellScript(config); } return generateBashScript(config); }; exports.generateSwitchScript = generateSwitchScript; const generateBashScript = (config) => { return `#!/bin/bash export GPG_TTY=$(tty) # Set Git identity for ${config.displayName || config.name} git config --global user.name "${config.userName}" git config --global user.email "${config.userEmail}" # Force Git to use ${config.name} private key git config --global core.sshCommand "ssh -i ~/.ssh/${config.sshKeyName} -F /dev/null" # Disable GPG commit signing git config --global --unset user.signingkey 2>/dev/null || true git config --global commit.gpgsign false # Update SSH agent ssh-add -D 2>/dev/null || true ssh-add ~/.ssh/${config.sshKeyName} echo "Name: ${config.userName}" echo "Email: ${config.userEmail}" echo "✅ Switched to ${config.displayName || config.name} identity" `; }; const generatePowerShellScript = (config) => { return `# PowerShell function for ${config.displayName || config.name} function use-${config.name} { $env:GPG_TTY = $PSSession.TTY # Set Git identity git config --global user.name "${config.userName}" git config --global user.email "${config.userEmail}" # Set SSH key (Windows uses different path) $sshKeyPath = "$env:USERPROFILE\\.ssh\\${config.sshKeyName}" git config --global core.sshCommand "ssh -i $sshKeyPath -F NUL" # Disable GPG signing git config --global --unset user.signingkey 2>$null git config --global commit.gpgsign false Write-Host "Name: ${config.userName}" -ForegroundColor Green Write-Host "Email: ${config.userEmail}" -ForegroundColor Green Write-Host "✅ Switched to ${config.displayName || config.name} identity" -ForegroundColor Green } `; }; //# sourceMappingURL=shellScriptGenerator.js.map