u/EvilSupahFly

Anybody else write custom BASH functions for repetitive tasks?

Over the last few years, I've built a collection of "function cheats" for things I'm always doing in the terminal that I've dropped into /etc/bash.bashrc and ~/.bashrc, and I'm wondering if anybody else does the same thing.

For example, back when I was working on a Flatpak project, and needed to test the source under different Python versions, I wrote a function called "pyvenv" for managing Python virtual environments that utilizes PythonZ to create, use, and manage Python Virtual Environments (VENVs). You can give it nothing, and it will ask for everything. Give it some, and it will ask for whatever's missing. Give it everything, and it asks for nothing.

It's a very handy one-line shortcut that does a lot of heavy lifting for me.

I've also implemented functions that remap cp and mv to a same-name wrapper that does rsync calls instead, a whole slew of ffmpeg cheats, and most recently, my newest project, which I called "nuke" - a pattern-matched, staged deletion. With recursion.

I'm not talking just simple alias definitions. These are full on, proper functions:

# ffmpeg cheats
mix() {
    echo -e "Merging $1 and $2 into $3."
    ffmpeg -i "$1" -i "$2" -c:v copy -map 0:v -map 1:a -y "$3"
}

ffmp4() {
    echo -e "Converting $1 to ${1%.*}.mp4."
    ffmpeg -i "$1" -codec copy "${1%.*}.mp4"
}

ffmkv() {
    echo -e "Converting $1 to ${1%.*}.mkv."
    ffmpeg -i "$1" -codec copy "${1%.*}.mkv"
}

I first started using Linux when I was in college, back in the late '90s, and right away, I was extremely impressed by how much more functional Linux shell scripts could be, ESPECIALLY compared to the batch files on DOS and Windows I was used to from high school.

So now I'm curious to know if anybody else does things like this, or if I'm just strange. Every time I have a new idea for one of these, and even still, after twenty years, each time I try to tell my wife, she just rolls her eyes and says something like, "Isn't there an app or something that does that?" or "But why is it always text mode?", or "Will it take out the kitchen garbage or recycling? No? Don't care."

So now I'm here, taking my case to strangers and fellow nerds, on the interwebs. 😜

I'm not going to violate Rule 3 with links, but if YOU'RE curious, you can Google me + GitHub - I'm not hard to find. 😜

reddit.com
u/EvilSupahFly — 8 hours ago