Using Bash and the terminal for greater computer productivity
An alias is a bash command shortcut. You run the shortcut name, and it executes the longer function you store. It’s great to save and quickly use common commands.
Assuming you’re using ZSH like me, here’s two useful commands to add to your aliases file right now:
viewalito see your alias list.
editalito edit your alias list.
Another useful alias trick is one that can open a repo while also getting it running locally all at once. For example, here’s my current alias that opens my personal site in a code editor while getting the local version up.
- First it navigates to the folder with my site’s code
- Then it uses a VSC code shortcut to open up the repo
yarn develop, which is the repo’s script to spin up the site
Viola! One command to get you into working mode.
Script files end in
*.sh, and are used to store bash commands. Run the file, and run the command(s) in that file.
To get a script file working, you need to:
- Make sure your script is in the PATH directly, which is where most scripts should go. Run
echo $PATHto see where it is.
#!/bin/bashas a comment on the first line
chmod +x <filename.sh>
Then you can just run
<filename.sh> and run the script!
Saving Commands with Parameters
Write a function like this in a script file, and it’ll take parameters. You could write it directly in an alias file if it’s short. If it’s long, put it in a separate file and reference it via the alias file or the script method above.
Each parameter is referenced by it’s order in the same format. First one is
$1, second is
$2, and so on.