π

A Quick Command-Line URL Shortener That Actually Saves Time ⚡

Show Sidebar

We've all been there: you need to share a long URL and spend precious minutes hunting through various URL shortening websites 😤. After doing this dance one too many times, I decided to create a simple bash function that puts URL shortening right at my fingertips.

The Solution 🛠️

Here's the bash function that has quietly revolutionized my workflow:

function shorturl() {
if [ -z "$1" ]; then
printf "Usage: shorturl <url>\n"
return 1
fi
printf "Shortening url '$1'\n"
curl -s "https://is.gd/create.php?format=simple&url=$1" \
| tee >(pbcopy)
}	  

The function is elegantly simple: it validates input, shows you which URL is being shortened, calls the is.gd API, and automatically copies the result to your clipboard (on macOS): the tee >(pbcopy) command displays the shortened URL in your terminal while simultaneously doing the clipboard copy.

Setup 🔧

Add the above to your .alias file in your home directory, then ensure your .bashrc includes:

test -e ~/.alias && . ~/.alias	  

This keeps your custom functions organized while making them available in every shell session.

Why This Matters 💡

It's not just about time saved—it's about removing friction from your workflow. Instead of opening a browser, navigating to a service, pasting, copying, and switching back, you simply type shorturl <longurl> and the shortened version is instantly ready to paste.

This tiny function represents a broader principle: automate the small, repetitive tasks that interrupt your flow. These micro-inefficiencies break your concentration and add up over time.

Using Linux?

Replace pbcopy with xclip -selection clipboard.

The Philosophy of Small Tools

This embodies the Unix philosophy of small, focused tools that do one thing well. Sometimes the most impactful improvements to your workflow are the smallest ones.

Next time you find yourself doing the same digital task repeatedly, ask: "Could I automate this with a simple function?" You might be surprised how often the answer is yes 😊.

Comment via email (persistent) or via Disqus (ephemeral) comments below: