Last active
January 21, 2016 08:56
-
-
Save sp-jordi-forns/799aac97a144d13da603 to your computer and use it in GitHub Desktop.
Switch to a recently modified branch through a selection menu
This file contains 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
#!/usr/bin/env node | |
String.prototype.format = function() { | |
var formatted = this; | |
for (var i = 0; i < arguments.length; i++) { | |
var regexp = new RegExp('\\{'+i+'\\}', 'gi'); | |
formatted = formatted.replace(regexp, arguments[i]); | |
} | |
return formatted; | |
}; | |
var options = []; | |
var cmd = "git for-each-ref --count=12 --sort=-committerdate --format='%(refname:short)' refs/heads/"; | |
var process = require('child_process'); | |
process.exec(cmd, function (err, stdout, stderr) { | |
if (err) { | |
console.error(err); | |
return; | |
} | |
var inquirer = require("inquirer"); | |
options = stdout.trim().split("\n"); | |
options.push(new inquirer.Separator()); | |
inquirer.prompt([{ | |
type: "list", | |
name: "select", | |
message: "Choose a branch:", | |
choices: options | |
}], function(answer) { | |
process.exec("git checkout {0}".format(answer.select), function(err, stdout, stderr) { | |
if (err) { | |
console.error(err); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment