Skip to content

Instantly share code, notes, and snippets.

@alexfouche
Last active January 4, 2020 18:24
Show Gist options
  • Save alexfouche/9d278a67f98080417cb321a725d02f11 to your computer and use it in GitHub Desktop.
Save alexfouche/9d278a67f98080417cb321a725d02f11 to your computer and use it in GitHub Desktop.
Commit and push Gist from symlink to the gist file
#!/bin/bash
# set -e
# set -x
main() {
symlink="$1"
comment="$2"
file=`readlink -e "$symlink"`
where=`dirname "$file"`
what=`basename "$file"`
pushd "$where" >/dev/null
git add "$what"
git commit --quiet -m "$comment"
git push --quiet
popd >/dev/null
}
function check_args() {
test -z "$1" && die_show_help
test -z "$2" && die_show_help
test -L "$1" || die "\"$1\" is not a symlink (to a gist)"
}
function show_help() {
>&2 echo "Usage: $0 <symlink to gist file> <\"Git comment\">"
}
function die() {
printf '%s\n' "$1" >&2
exit 1
}
function die_show_help() {
show_help
exit 2
}
check_args "$@"
main "$@"; exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment