Summary | Find the path from PATH env vars which includes string you specified. |
Env | win babel-node |
Last active
October 9, 2015 03:34
-
-
Save fliedonion/623af6f3a8a4e159ed91 to your computer and use it in GitHub Desktop.
Find in Path environment variables with babel-node
c:\> npm install --global babel
c:\> babel-node find-from-path-sample.js windows
[ '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' ]
This file contains hidden or 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
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 )) | |
) |
This file contains hidden or 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
// 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