Skip to content

Instantly share code, notes, and snippets.

@crutch12
Last active August 9, 2022 22:20
Show Gist options
  • Save crutch12/7940accc898d055d3813e08dba78fdf0 to your computer and use it in GitHub Desktop.
Save crutch12/7940accc898d055d3813e08dba78fdf0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const os = require('os')
const child_process = require('child_process')
const fs = require('fs')
// ["bitbucket.web-bee.ru", "web-bee", "Firstname Lastname", "example@web-bee.ru"]
const [remote, workName, displayName, email] = process.argv.slice(2)
console.info({ remote, workName, displayName, email })
if (!remote || !workName || !displayName || !email) {
console.error('You should provide 4 values (remote, workName, displayName, email)')
process.exit(1);
}
// .gitconfig-web-bee
const workConfigFileName = `.gitconfig-${workName}`
const workConfigFileText = `# ~/.gitconfig-${workName}
[user]
name = ${displayName}
email = ${email}
`;
// ~/.gitconfig-web-bee
const workConfigFilePath = os.homedir() + '/' + workConfigFileName
// write file ~/.gitconfig-web-bee
fs.writeFileSync(workConfigFilePath, workConfigFileText);
// add includeIf (https://git-scm.com/docs/git-config#_example)
const gitConfigCommand = `git config --global includeif.hasconfig:remote.*.url:*://**${remote}**/**.path ${workConfigFileName}`
// update ~/.gitconfig
// git config --global includeif.hasconfig:remote.*.url:*://**bitbucket.web-bee.ru**/**.path .gitconfig-web-bee
child_process.execSync(gitConfigCommand)
console.info('Success!')
console.info(child_process.execSync('git config --global --list').toString())
process.exit(0);
{
"name": "@web-bee-ru/git-config-setup",
"version": "1.0.0",
"bin": "index.js"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment