To create a permanent alias shortcut, put it in .bash_profile file and point .bashrc file to .bash_profile file. Follow these steps (I am creating an alias command called bnode to run babel transpiler on ES6 code):
- Go to terminal command prompt and type “cd” (this will take
you to the home directory. Note: even though your programming files may
be located on your “D: drive”, your “.bash” files may be located on
your “C: drive” )
- To see the location of the home directory, type “pwd” (this will show you the home directory path and where the .bash files are probably located)
- To see all dot "." files in the home directory, type “ls -la” (this will show ALL files including hidden dot "." files)
- You will see 2 files: “.bash_profile” and “.bashrc”
- Open .bashrc file in VS Code Editor or your IDE and enter “source ~/.bash_profile” in first line (to point .bashrc file to .bash_profile)
- Open .bash_profile file in VS Code Editor and enter “alias bnode='./node_modules/.bin/babel-node'” (to create permanent bnode shortcut to execute as bash command)
- Save and close both files
- Now open the file you want to execute (index.js) and open in terminal command prompt and run file by using command “bnode index.js”
- Now your index.js file will execute but before creating bnode alias in .bash_profile file you would get the error "bash: bnode command not found" and it would not recognize and give errors on some ES6 code.
- Helpful link to learn about dotfiles: https://dotfiles.github.io/
I hope this helps! Good luck!