Created
November 30, 2018 11:31
-
-
Save vdakalov/65d1214a2e544c8676f43b5db30e82c5 to your computer and use it in GitHub Desktop.
REPL Terminal for Node.js
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
#!/bin/bash | |
getUid() { | |
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1 | |
} | |
. "$HOME/.bashrc" | |
if [ -z "$NVM_DIR" ]; then | |
if [ -d "$HOME/.nvm" ] && [ -f "$HOME/.nvm/nvm.sh" ]; then | |
NVM_DIR="$HOME/.nvm" | |
else | |
echo "Environment variable NVM_DIR is not defined. Exit." | |
read | |
exit 1 | |
fi | |
fi | |
. "$NVM_DIR/nvm.sh" | |
if [ -z "$1" ]; then | |
while true; do | |
base=/tmp/$(getUid) | |
if [ ! -d "$base" ]; then | |
mkdir "$base" | |
break | |
fi | |
done | |
else | |
if [ ! -d "$1" ]; then | |
mkdir -vp $1 | |
fi | |
base=$1 | |
fi | |
node_bin=$(nvm which node) | |
npm_bin=$(dirname $node_bin)/npm | |
mkdir -p $base | |
cd $base | |
echo "node: $($node_bin -v)" | |
echo "npm: $($npm_bin -v)" | |
echo "cwd/NODE_PATH: $base" | |
echo | |
NODE_PATH=$base node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Linux Mint
System Settings -> Keyboard -> Shortcuts -> Custom Shortcuts -> Add custom shortcut
Name:
Node.js REPL
Command:
gnome-terminal --title "Node.js REPL" -- /bin/bash /home/user/bin/node-repl