Skip to content

Instantly share code, notes, and snippets.

@PeterHancock
Created February 28, 2014 13:29
Show Gist options
  • Save PeterHancock/9271122 to your computer and use it in GitHub Desktop.
Save PeterHancock/9271122 to your computer and use it in GitHub Desktop.
shotgun password
//app.js
var readline = require('readline'), rl = null, ....
function startRl() {
rl = readline.createInterface(process.stdin, process.stdout);
rl.setPrompt('> ');
rl.on('line', function (userInput) {
shell.execute(userInput);
rl.prompt();
});
};
// I found something similiar in a thread but I forget the source
function getPassword(callback) {
var stdin = process.stdin;
stdin.setRawMode(true);
stdin.setEncoding('utf8');
var password = '';
var onData = function onData(ch) {
ch = ch + "";
switch (ch) {
case "\n":
case "\r":
case "\u0004":
//They've finished typing their password
process.stdout.write('\n');
stdin.setRawMode(false);
stdin.removeListener('data', onData);
callback(false, password);
break;
case "\u0003":
// Ctrl-C
callback(true);
break;
default:
// More passsword characters
process.stdout.write('*');
password += ch;
break;
}
};
stdin.on('data', onData);
}
shell.on('password', function () {
//disable readline
rl.close();
getPassword(function(cancel, password){
startRl();
shell.execute(password);
});
});
startRl();
rl.prompt();
@catdadcode
Copy link

I think what you did here is perfectly fine. Because shotgun remains agnostic toward UI it doesn't make sense to include console password retrieval support within shotgun itself. However, as with shotgun-client (considering renaming to "shotgun-web-client") you could create a companion library that wraps shotgun and does provide all these helpful features :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment