(Somewhat) useful Bash scripts

Lazygit

I use this one all the time. I also have a lazygitmaster which is identical but pushes on the master branch

function lazygit() {
	git add -v *
	git commit -a -m "$1"
	git push origin main
}
Oneko PID Handler

This one can really be expanded to any function you want to run in the background while keeping note of its PID (who really wants to ps -ef?)

Usage: oneko_bg start to start, oneko_bg end to end

function oneko_bg() {
   	if [[ $1 = "start" ]]; then
           	if [ ! -s ~/oneko_pid.txt ]; then
                   	(&>/dev/null nohup oneko &)
                   	pgrep -f oneko > ~/oneko_pid.txt
            else
                    echo "~/oneko_pid.txt isn't empty, you might have an instance running already"
            fi
    elif [[ $1 = "end" ]]; then
            if [ -s ~/oneko_pid.txt ]; then
                    kill -9 $(cat ~/oneko_pid.txt) > /dev/null 2>&1
                    cp /dev/null ~/oneko_pid.txt
            else
                    echo "~/oneko_pid.txt is empty, doesn't look like you have an oneko instance running"
            fi
    else
            echo "Argument $1 not recognized"
    fi
}
Netcat Payload

I keep this one around for any CTFs that I do, I always forget how to deposit payloads through netcat

Usage: nc_payload <payload> <address> <port>

cat $1 | nc $2 $3 -N
Clang-Format + CMake

I use this to format and compile my code with some boilerplate to make the output look pretty. This usually ends up as a bash script in my project directory, not a function in ~/.bashrc. If working with other languages, make sure to replace the "*.c" and "*.h" in the clang-format line with the appropriate file extensions. This requires a .clang-format file in the project directory. To remove this requirement, remove style=file from the clang-format line.

echo "---CLANG-FORMAT----"
clang-format -i $(find src -name "*.c") $(find include -name "*.h")
echo "-----CMAKE---------"
cd build
if cmake .. ; then
    echo "-----MAKE----------"
    if make -j$(nproc) ; then
        cd ../bin
        echo "-----EXECUTING-----"
		./helloworld
    else
        echo "-----MAKE FAILURE-----"
    fi
else
    echo "-----CMAKE FAILURE-----"
fi
Steampipe Upload

I use this for pushing builds for my steam releases

steamcmd +login <username> <password> +run_app_build \
	~/steamworksSDK/tools/ContentBuilder/scripts/app_build_<ApplicationID>.vdf +quit