Created
January 19, 2015 22:51
-
-
Save CumpsD/ac1f3bc979fbdd4775c4 to your computer and use it in GitHub Desktop.
Putty interactive session launcher from conemu/cmder
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
'use strict'; | |
var fs = require('fs'), | |
path = require('path'), | |
inquirer = require('inquirer'), | |
exec = require('child_process').exec, | |
spawn = require('child_process').spawn; | |
// puttySessionsPath is where my sessions are stored as files | |
var puttySessionsPath = process.env.google + 'Tools/Putty/sessions/', | |
puttySessions = fs.readdirSync(puttySessionsPath), | |
sessionFilter = process.argv.length > 2 ? process.argv[2] : ''; | |
var availableSessions = | |
puttySessions.map(function (file) { | |
return path.join(puttySessionsPath, file); | |
}).filter(function (file) { | |
return fs.statSync(file).isFile(); | |
}).map(function (file) { | |
return unescape(path.basename(file)); | |
}).filter(function (file) { | |
return file.toLowerCase().indexOf(sessionFilter.toLowerCase()) > -1; | |
}).map(function (file) { | |
return { | |
name: file, | |
value: file | |
}; | |
});//.forEach(function (file) { console.log('%s', file.name); }); | |
availableSessions.push({ | |
name: 'Other', | |
value: 'SomeOtherPuttySessionWhichWasntInTheList' | |
}); | |
var sessionPrompt = [{ | |
type: 'list', | |
name: 'sessionName', | |
message: 'Which session do you want to launch?', | |
choices: availableSessions, | |
validate: function (input) { return input ? true : 'Session is required!'; }, | |
filter: function (input) { return input.toLowerCase(); } | |
}]; | |
inquirer.prompt(sessionPrompt, function (answers) { | |
var baseCommand = 'conemu /reuse /basic /cmd '; | |
if (answers.sessionName.toLowerCase() === 'SomeOtherPuttySessionWhichWasntInTheList'.toLowerCase()) { | |
// Launch regular putty | |
exec(baseCommand + 'putty -cur_console:t:"Putty"'); | |
} else { | |
var sessionTitle = answers.sessionName.indexOf('] ') > -1 | |
? answers.sessionName.substring(answers.sessionName.indexOf('] ') + 2) | |
: answers.sessionName; | |
// Launch putty with -load "answers.sessionName" | |
exec(baseCommand + 'putty -cur_console:t:"' + sessionTitle + '" -load "' + answers.sessionName + '"'); | |
} | |
}.bind(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment