Bash aliases I use

Intro

I've realized I'm too lazy to remember certain commands, but I'm also just lazy enough to write bash scripts for them. The distinction isn't huge, as these are essentially one-liners. They significantly help me with blogging, backups, and Git workflows. If you're new to aliases, simply add these commands to your ~/.bashrc file, then type source ~/.bashrc in your current session to activate them.

Blogging

I use 11ty for this blog. To preview a new article, I use:

alias preview-blog='npx @11ty/eleventy --serve'

This starts a web server that instantly reflects all changes I make. To prepare the final version for GitHub, I use this command:

alias post='npx @11ty/eleventy && cd _site/ && git add . && read -p "Commit message: " msg && git commit -m "$msg" && git push && cd ..'

Just generates the blog, adds new files to git, commits them, pushes them to GitHub, and then returns to the main blog folder.

Backup

Borg is an excellent solution for backups, but it's not the most user-friendly. Borgmatic, which essentially consists of Python scripts, makes it much easier to use. I configured it once and haven't had to think about it since. Now, to perform a backup to an external drive, I use this command:

alias backup='borgmatic -c ~/.config/borgmatic.yaml'

Converting PDF to PNG

It was surprising to discover that, despite the abundance of tools for working with PDFs, there isn't a simple, short command to convert PDF to PNG. It's achievable using ImageMagick, but some options can be tricky. I simply need sequentially numbered files, and that's all:

alias pdftopng='counter=1; for i in *.pdf; do magick $i -background white -alpha remove $counter.png; ((counter++)); done'

Development

By "development," I specifically mean JavaScript programming for Node.js. I have many Node projects, and I needed a single command to clean all of them at once, especially if I no longer need their node_modules folders:

alias clean-node='find . -name "node_modules" -type d -prune -exec rm -rf {} \;'

Some of these projects are in my GitHub repo, and I also took a course to learn more about Git. One command proved particularly useful:

alias git-graph='git log --graph --decorate --oneline --all'

That's all for today. I hope you found something useful for yourself!