-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "g-whereis", | ||
"version": "0.0.2", | ||
"description": "", | ||
"main": "whereis.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"bin": "whereis.js", | ||
"author": "Jochem Stoel", | ||
"license": "ISC" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# whereis | ||
This is a huge sofisticated super complex framework to find in which PATH directory a file is located. It can also be built as an executable. If you want just the function whereis() then open file _whereis.js_ and copy paste it. | ||
|
||
## run using regular node | ||
```bash | ||
node whereis.js git.exe | ||
git.exe found in C:\Program Files (x86)\Git\cmd\git.exe | ||
|
||
node whereis.js blooperdeefloop | ||
blooperdeefloop found nowhere | ||
``` | ||
|
||
## build for cli | ||
If you have _pkg_ installed you can build whereis by simply running | ||
```bash | ||
pkg . | ||
``` | ||
This will compile a single executable for windows, linux and osx. If you add the location of whereis.exe to PATH then you can simply run this in your command line in any folder: | ||
|
||
```bash | ||
whereis node.exe | ||
``` | ||
|
||
## binaries | ||
I have included a build for windows/linux/osx using Node v8.5.0 but it is generally advised to build things yourself. |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* whereis | find something in PATH */ | ||
var fs = require('fs') | ||
var path = require('path') | ||
|
||
function find() { | ||
var pathSep = process.platform === 'win32' ? ';' : ':' | ||
var directories = process.env.PATH.split(pathSep) | ||
for (var i = 0; i < directories.length; i++) { | ||
for (var j = 0; j < arguments.length; j++) { | ||
var filename = arguments[j] | ||
var filePath = path.join(directories[i], filename) | ||
|
||
if (fs.existsSync(filePath)) { | ||
return [filePath, directories[i]] | ||
} | ||
} | ||
} | ||
return null | ||
} | ||
|
||
let that, where, there | ||
|
||
if(process.argv.length==3) | ||
that = process.argv[2] | ||
else { | ||
console.log('whereis what?') | ||
process.exit() | ||
} | ||
|
||
where = find(that) | ||
|
||
if(where==null) | ||
there = 'nowhere' | ||
else | ||
there = `in ${where[0]}` | ||
|
||
console.log( | ||
`${that} found ${there}` | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.