Aliasing Commands in the Bash Shell
Here are some things that I have found useful to change on my MacBook, to make life easier at the command line.
When I list things, I basically always want the long listing, so I alias one to the other, like so
alias ls="ls -la"
You can run alias commands at the terminal, but when you restart the shell, they will be reset. To have them run every time your start a new shell, you can put them in your
.bash_profile is a hidden file in your home directory (you can always return to your home directory with just
I use Tiddlywiki to run Node servers that serve my notebooks. Some of these are public by default, like the one that I use to build this website, but some of them are for my private notes. I back those ones up by having them read and write from my iCloud directory (I also have Time-machine making local copies of them, so this way I get onsite and offsite back up for very little effort.)
The only small problem with doing that is that the iCloud folder is located at a long and difficult to remember path
Instead of remembering that every time, I can alias it to something I will remember, like say "icloud".
alias icloud="cd ~/Library/Mobile\ Documents/com~apple~CloudDocs/"
When I run Tiddlywiki itself, I specify the port that I want it to serve on which means I can start several at once by specifying different ports.
This means I could alias the tiddlywiki command like this
alias tw="tiddlywiki --server"
and invoke it like this
The wrinkle here is that I often want to make these servers available to my local network (instead of just localhost), which I can do, but I have to pass the right parameter, which means I now have to type
tiddlywiki --server 8080 $:/core/save/all text/plain text/html "" "" 0.0.0.0
As you can see, because I need to set the seventh parameter, I also need to provide the other parameters, meaning I would have to remember them all every time.
In practice, of course, I find myself hunting through my history for the command and changing the port number. I can't just alias this command, because the port number isn't at the end.
Instead I can write a short program, with a variable and run it from the command line.
#!/bin/bash tiddlywiki --server $1 $:/core/save/all text/plain text/html "" "" 0.0.0.0
Writing the script is pretty easy, as long as you know how to reference command line arguments as variables, and you know the magic words to put at the top of the file to identify it as a bash script.
If you want to be able to run it from anywhere, you should put it somewhere on your path, mine is in
/usr/local/bin. You should also remove the ".sh" extension and make sure you have permission to run it.