DEV Community

Show me your Bash Functions / Aliases!

Fred Richards on September 21, 2019

Do any of you have your favorite bash functions or aliases? I've always been a fan of quick "lightning tips" that you can show maybe on one line, ...
Collapse
 
lbonanomi profile image
lbonanomi • Edited

Do you use Github gists as a notebook?

gist ()
{
    GISTTMP=$(mktemp -d) && GISTFILE=$(basename $1) && GISTPATH=$(readlink -f $1)
    GIST_URL=$((echo curl -snk -X POST -d \'{\"files\":{\"$GISTFILE\":{\"content\":\".\"}}}\' https://api.github.com/gists | sh ) | awk -F'"' '/git_pull_url/ { print $4 }' | head -1 )
    (
        cd $GISTTMP
        git clone -q $GIST_URL
        cd $(ls)
        cat $GISTPATH > $GISTFILE;
        git add $GISTFILE && git commit -q -a -m "$GISTFILE" && git push -q
    )
}

Collapse
 
lbonanomi profile image
lbonanomi

I also work with throwaway-VMs, so you may do well rm -rf-ing $GISTTMP when you're done

Collapse
 
lbonanomi profile image
lbonanomi

Alert my terminal if someone else has logged-into the same box that I am using.

unset MAIL; export MAILCHECK=1; export MAILPATH='/var/log/wtmp?You have company'