nrg is an abbreviation for NPM RUN and GIT which, at the time of writing this, is the most used command line tools for me. It is a simple wrapper for both npm and git with some nice features.
- nrg - A utility for increasing command line productivity
- Table of Contents
- Flags
- REPL
- Commands
- Passthru commands
- alias
- awk
- cat
- chgrp
- chmod
- chown
- cp
- crc32
- curl
- cut
- date
- dd
- df
- diff
- dig
- docker
- docker-compose
- du
- echo
- emacs
- file
- find
- go
- grep
- head
- history
- hostname
- htop
- jobs
- kill
- killall
- less
- ln
- locate
- man
- md5
- mkdir
- mv
- nano
- nmap
- nmon
- nodemon
- npm
- nslookup
- passwd
- paste
- pgrep
- pico
- ping
- pkill
- ps
- rm
- rmdir
- screen
- sed
- sha1
- sort
- ssh
- ssh-keygen
- su
- sudo
- tail
- tar
- tee
- top
- touch
- tr
- tree
- unalias
- uname
- uniq
- unzip
- useradd
- userdel
- vi
- vim
- wc
- wget
- which
- whoami
- whois
- xargs
- yarn
- zip
- Configuration
- Internal script engine
- Functions available in the script engine
- atoi(string): int
- bintoints(): int
- call()
- cd()
- cwd()
- defined(var): bool
- dump()
- exit(exitcode)
- get()
- GetScreenWidth(): int
- GetScreenHeight(): int
- itoa(int): string
- print()
- printf()
- println()
- printmidpad()
- printmidpadln()
- printpadded()
- printpaddedln()
- printwidth()
- printwidthln()
- pwd()
- readpackagejson(): map
- run()
- runcmd(command)
- runcmdstr(command): [output, return code, error]
- set()
- setblue()
- setbold()
- setcyan()
- setgreen()
- setmagenta()
- setnormal()
- setred()
- settitle()
- setwhite()
- setyellow()
- SignJWTToken()
- sleep()
- sprint()
- sprintf()
- sprintln()
- test()
- trim()
- trimwhitespace()
- UnpackJWTToken()
- unset()
- use()
- ValidateJWTToken()
- Running scripts
- Running scripts from command line
- Examples
- Built-in scripts
- Functions available in the script engine
Execute the commands in the specified project.
Much of the functionality of nrg is available both in the REPL and from the command line. To start the REPL, simply run nrg without any flags.
Show help for a command.
The help function is a heavy work in progress and is currently far from complete.
This is the same command as ls. But since we are listing stuff and files can be listed, then this command is available just to make it easier to remember.
Some commands are passed through to the underlying tool. This means that you can use the same flags as you would with the underlying tool. For example, if you want to see the help for the git command, you can run nrg git --help.
Please note that the passthru commands rely on the underlying tool being installed and available in the path.
If a passthru command somehow collides with a nrg command, it's still possible to perform a passthru. Call the nrg command passthru with the passthru command and its arguments as parameters.
Example with nrg REPL:
nrg:@project> git --help
// Will show the help for the git command
nrg:@project> passthru git --help
// Will also show the help for the git commandExemple with nrg command line:
nrg:@project> nrg git --help
// Will show the help for the git command
username:path> nrg passthru git --help
// Will also show the help for the git commandThe following subsystems are passed through:
{
"projects": {
"projectkey": {
"name": "Project name",
"path": "/project/path",
"packageJSON": {},
"isGit": true,
"variables": {
"Variable1": "Value1",
"Variable2": "Value2"
}
}
},
"variables": {
"Variable1": "Value3",
"Variable2": "Value4"
},
"scripts": {
"script1": "echo 'Hello world!'"
}
}The key for the project. This is used to identify the project in the REPL and in the command line.
The name of the project.
The path to the project.
The package.json file for the project.
Whether or not the project is a git repository.
Variables for the project. These variables are available in the REPL and in the command line.
Variables used as configuration values. These variables are available in the REPL and in the command line.
Scripts that can be run in the REPL and in the command line.
nrg uses a simple script engine to run scripts. The script engine is based on the goja JavaScript engine. The script engine is used to run scripts in the REPL and in the command line.
There are a few special functions available in javascript for nrg.
Please note that this list is currently a work in progress
Converts a string to int.
Converts a string consisting of 0's and 1's to a int.
Change the current directory to the given path.
Returns the current working directory.
This is equal to pwd
Not a proper defined. instead it more or less returns true if the var isn't undefined or null.
Aborts the javascript vm with the given exitcode.
Converts an integer to a string.
Returns the current working directory.
This is equal to cwd
Reads the current package.json into a map.
If there is no package.json or if the read fails it returns null.
Runs another javascript. Similar to include/require.
Runs a command through the REPL function in nrg. Outputs anything directly.
Runs a command through the REPL function in nrg and returns an array with output, return code and error. This is a great function to use if you need to process the output done from the command.
nrg:@project> run script1 [parameter1] [parameter2]If the scriptname is unique you might use a shorthand version excluding the run command.
nrg:@project> script1 [parameter1] [parameter2]username:path> nrg run script1 [parameter1] [parameter2]If the scriptname is unique you might use a shorthand version excluding the run command.
username:path> nrg script1 [parameter1] [parameter2]/* Filename: nisse.js */
var exitCode = run("git status");
if (exitCode === 0) {
exitCode = run("git add .");
if (exitCode === 0) {
exitCode = run("git commit -m 'Commit message'");
if (exitCode === 0) {
exitCode = run("git push");
}
}
}
return exitCode;/* Filename: nisseShort.js */
return run("git status") || run("git add .") || run("git commit -m 'Commit message'") || run("git push");nrg:@project> run nisse
// Output from git status
// Output from git add .
// Output from git commit -m 'Commit message'
// Output from git push
nrg:@project> run nisseShort
// Output from git status
// Output from git add .
// Output from git commit -m 'Commit message'
// Output from git pushusername:path> nrg run nisse
// Output from git status
// Output from git add .
// Output from git commit -m 'Commit message'
// Output from git push
username:path> nrg nisseShort
// Output from git status
// Output from git add .
// Output from git commit -m 'Commit message'
// Output from git pushA script that will take the commit message as argument.
First it will run lint, then it will add all files, after that it will commit and finally push.
If the first argument starts with @ then that argument will be used yo define which project to use. The second argument will then be used as the commit message.
Will perform a recursive search for .git directories in the current path. If a git project is found then it will run a short version of git diff and output that.