Skip to content

Instantly share code, notes, and snippets.

@ewdurbin
Last active August 29, 2015 14:05
Show Gist options
  • Save ewdurbin/91ac38fde7c599452f59 to your computer and use it in GitHub Desktop.
Save ewdurbin/91ac38fde7c599452f59 to your computer and use it in GitHub Desktop.
GISTAGE OMG

gistage

Edit/manage gists, even with multiple files, in an editor of your choice.

Requirements

  • bash
  • gist cli
  • git
  • common shell utils: awk, sed, xargs

Usage

usage: gistage [[[-n] [-e gist]] [-d description] | [-h]]
  • -n Create a new Gist
  • -e gist_id Edit a Gist
  • -d "description here" add/edit a description to your gist

Configuration

Export a GIST_EDITOR environment variable which accepts a directory as its argument ala:

vim /tmp/lol_im_a_gist/

#!/bin/bash
function usage
{
echo "usage: gistage [[[-n] [-e gist]] [-d description] | [-h]]"
}
function workon
{
ID=$1
GIST_EDITOR="$2"
INITIAL=$3
git clone [email protected]:/$ID.git /tmp/$ID
pushd /tmp/$ID/
if [[ $INITIAL ]]; then
rm "0-created.md"
fi
${GIST_EDITOR} /tmp/$ID
git status | grep "deleted:" | awk -F":" '{print $NF}' | sed -e 's/^ *//' -e 's/ *$//' | xargs git rm
git add *
git commit -m "gistage"
git push origin master
popd
}
description="gistage"
GIST_EDITOR=${GIST_EDITOR:="/Applications/LightPaper.app/Contents/MacOS/LightPaper"}
while [ "$1" != "" ]; do
case $1 in
-n | --new )
new=1
;;
-e | --edit )
edit=1
shift
gist=$1
;;
-d | --description )
shift
description=$1
;;
-h | --help )
usage
exit
;;
* )
usage
exit 1
esac
shift
done
if [[ "x${new}" == "x${edit}" ]]; then
echo "You must choose one of -n/--new or -e/--edit"
usage
exit 1
fi
if [[ "x${edit}" == "x1" ]] && [[ "x${gist}" == "x" ]]; then
echo "You must specify a gist with -e/--edit"
usage
exit
fi
if [[ "x${new}" == "x1" ]]; then
OUTPUT=$(gist -p -f "0-created.md" -d "${description}" <<EOF
created with [gistage](https://github.com/ewdurbin/gistage)
EOF)
ID=$(basename $OUTPUT)
workon $ID "$GIST_EDITOR" 1
fi
if [[ "x${edit}" == "x1" ]]; then
ID="${gist}"
workon $ID "$GIST_EDITOR"
fi
echo ""
echo "Gist ID: $ID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment