Skip to content

Instantly share code, notes, and snippets.

@fliedonion
Last active October 9, 2015 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fliedonion/623af6f3a8a4e159ed91 to your computer and use it in GitHub Desktop.
Save fliedonion/623af6f3a8a4e159ed91 to your computer and use it in GitHub Desktop.
Find in Path environment variables with babel-node
Summary Find the path from PATH env vars which includes string you specified.
Env win babel-node

How to use

install babel:

c:\> npm install --global babel

usage:

c:\> babel-node find-from-path-sample.js windows

sample-output:

[ 'C:\\Windows\\system32',
'C:\\Windows',
'C:\\Windows\\System32\\Wbem',
'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\',
'C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\',
'C:\\Windows\\system32\\config\\systemprofile\\.dnx\\bin' ]
if( process.argv.length < 3 ) {
console.log('please specify keyword for search as a command line argument.');
process.exit(1);
}
var re = new RegExp(process.argv[2], "i");
console.log(
Object
.keys(process.env)
.filter( x => x.toUpperCase() == 'PATH' )
.map( x => process.env[x].split(';') )
.reduce( (x,y) => a.concat(b) )
.filter( x => x.match( re ))
)
// find path in PATH environment variable that includes 'windows'
Object.keys(process.env).filter( x => x.toUpperCase() == 'PATH' ).map( x => process.env[x].split(';') ).reduce( (x,y) => a.concat(b) ).filter( x => x.match( /windows/i ))
// ex)
// c:\> babel-node
// > Object.keys(process.env).filter( x => x.toUpperCase() == 'PATH' ).map( x => process.env[x].split(';') ).reduce( (x,y) => a.concat(b) ).filter( x => x.match( /windows/i ))
// [ 'C:\\Windows\\system32',
// 'C:\\Windows',
// 'C:\\Windows\\System32\\Wbem',
// 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\',
// 'C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\',
// 'C:\\Windows\\system32\\config\\systemprofile\\.dnx\\bin' ]
// >.exit
// c:\>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment