A very useful habit I picked up over the years is this:
If I catch myself doing the same thing on my computer at least three times, I try to write a script to automate it.
Even when I was using Windows, I mostly lived in the WSL Linux command line so this was pretty easy. Windows-specific things could be automated using PowerShell. (Seriously, if you’re a programmer using Windows, you must learn PowerShell. It is actually a pretty nice language – much nicer than Bash – and there is a cmdlet for everything).
Now that I’m on Linux, this became even easier. I have a
~/bin directory on my
PATH and I put these tiny scripts there.
- It’s important that you shouldn’t overcomplicate the scripts.
- They don’t need to be general, 90% of them don’t need any parameters or complex logic.
- They should have descriptive names, like the one I use to deploy this blog:
You can also automate tasks on remote servers. My
deploy-blog.sh script, for
example, looks like this:
#!/usr/bin/env bash pushd /home/botond/Sync/blog bundle exec jekyll build ssh firstname.lastname@example.org "rm -rf /var/www/tatooinesunset.botond.online/*" scp -r ./_site/* email@example.com:/var/www/tatooine-sunset.botond.online echo Deployment finished - please check the website for any errors. popd
This is very simple, primitive even, but it serves me well. It doesn’t even make a backup of the previous version. That is something I definitely should do later :)