Boosting Your Productivity With Aliases and Functions

Leverage your bash profile: practical tips for macOS and Linux users

Jovan Hernandez
Feb 18 · 5 min read
Build shortcuts and functions to boost your work efficiency

If you’ve read any of my prior pieces, it’s not news how much I despise using GUIs of any kind. I advocate anyone who wants to improve productivity to lay off GUIs and start utilizing CLI utilities as much as possible.

Most Mac and Ubuntu users understand the power of utilizing tools such as Terminal to perform batch operations in quick and efficient commands, such as move, copy, delete, and transfer.

Those are useful, but what if you want to go to the … next level?

Leveraging Your Bash Profile

My bash profile greets me with a cute colorful Apple logo and some system info … like a low battery!

Since the .bash_profile file is executed upon a new Terminal window launch or session, we can place commands and add files to be executed and read. This is valuable when trying to customize your shell environment for productivity and efficiency.

I’ll go over a few common uses for aliases and also how I incorporate them (as well as functions) into my workflow.

Improving Existing CLI Commands

For instance, making a directory is almost always followed up by moving into that directory. Or if you’re moving into an existing directory, that’s almost always followed by listing the contents of said directory. Creating a function can eliminate these repetitive tasks.

One of my favorite simple tricks involves combining the history command with grep to improve accuracy and reduce the time needed to scroll through your 5,000 lines of history to find that specific command you wrote several days ago.

Finding all my ssh sessions with a two-character command. Also, those are fake IPs so don’t bother.

Below are some other shortcut aliases I use that cut out annoying two-part combo commands that feel redundant.

# Bash function to change directories and list contents
cd() {
builtin cd $@
ls -lh
# Bash alias to search through history with speed accuracy
alias hs='history | grep'
# Bash alias to create unique date-stamped folders for Vagrant vms
alias vgu18='mkdir ubuntu18_$dt; cd ubuntu18_$dt; vagrant init ubuntu/bionic64; vagrant up; vagrant ssh'

Manipulating Browsers and Tabs

Creating custom functions and dropping them in your .bash_profile is a great way to gain back some time for shortcuts to everyday commands.

# opens browser pre-filled with tabs 

I created a function that opens all of my financial websites I frequent when checking in on markets or news in general. While it may seem trivial, having these processes packaged as a function grants me flexibility and creativity in how I want to call this function.

Let’s Walk Through a Practical Example

But I’m not talking about standard stuff. I’m talking about running cron jobs to call a function every morning, Monday through Friday at 9:00 a.m., a half hour before the market opens, to launch the websites you need for the day, meanwhile blocking domains you find distracting, like Twitter and Reddit, or useless, like CNN.

Calling the personal_finance function launches a browser with my listed tabs

There are other automation tools out there, but with bash functions, cron jobs, and a bit of logic, you can automate your work or dev environment to your liking, even down to the minute of every day — and for free.

You could even customize this even further by specifying specifically what browsers open which sites. I like to separate my browsers for different purposes.

  • Google Chrome is strictly used for work/dev-related items
  • Safari is for side work and freelance gigs
  • The Brave browser is for personal viewing, etc.

By creating functions for each browser and defining tabs within those browsers, I’m saving myself several hours every week by not needing to type in each address in each browser — and all the more, I’m avoiding distractions such as social media and YouTube.

Setting Up Dev Environments

Software and services such as Vagrant and VirtualBox became my go-to tools for testing scripts and automated solutions. I quickly found myself being overwhelmed keeping track of all my Vagrant VMs, though, so I built a function that helps me automate, organize, and deploy servers in a customized date-stamped system.

# Launch Vagrant boxes based on user input
# Folders are date-stamped and numbered accordingly.
echo "How many machines do you want?"; read n; \
for i in {1..$n..1}; do \
dt=$(date +"%m-%d-%y")
FOLDER=$(echo ubuntu18_${dt}_${id}); \
echo $FOLDER; mkdir $FOLDER; cd $FOLDER; vagrant init ubuntu/bionic64; \
cd ../; \
unset FOLDER; echo $id; unset id; \

Running ubuntufleet in any directory then deploys a number of servers declared by the user.

My ubuntufleet function in action


But for professional developers or even just professionals in general, repetitive tasks and redundant steps can take up a lot of your time, energy, and motivation.

It’s in your best interest to find workflows that can be streamlined and optimized and to automate them in whichever way possible. I just choose bash aliases and functions because it feels most comfortable, flexible, and granular to me.

Better Programming

Advice for programmers.

Jovan Hernandez

Written by

Active trader, systems thinker… anything DevSecOps

Better Programming

Advice for programmers.

More From Medium

More from Better Programming

More from Better Programming

More from Better Programming

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade