Skip to content

Instantly share code, notes, and snippets.

@relsqui
Created March 23, 2015 21:06
Show Gist options
  • Save relsqui/12a2b2b5cff608b818f9 to your computer and use it in GitHub Desktop.
Save relsqui/12a2b2b5cff608b818f9 to your computer and use it in GitHub Desktop.
Check a file out of RCS, edit it, check it back in.
#!/bin/bash
if [ "$1" == "-h" -o "$1" == "--help" ]; then
echo "Usage: rcsedit (filename|-h|--help)"
echo
echo "Checks a file out of RCS, opens it in your \$EDITOR, and checks it back in if the editor exits successfully." | fmt -$COLUMNS
exit 0
fi
if [ $# -ne 1 ]; then
echo "$0: You must supply exactly one filename (got $#)." >&2
exit 1
fi
if [ ! -e "$EDITOR" ]; then
echo "$0: Couldn't find your \$EDITOR ($EDITOR)." >&2
exit 2
fi
if [ ! -x "$EDITOR" ]; then
echo="$0: Your \$EDITOR ($EDITOR) isn't executable to you." >&2
exit 3
fi
if [ ! -e "$1" ]; then
echo "$0: Couldn't find target file ($1)." >&2
exit 4
fi
if ! rlog "$1" >/dev/null; then
echo "$0: Target file ($1) doesn't appear to be in RCS." >&2
exit 5
fi
if ! co -l "$1"; then
echo "$0: Couldn't check out $1 from RCS." >&2
exit 6
fi
if ! "$EDITOR" "$1"; then
echo "$0: $EDITOR returned non-zero. $1 has not been checked back in yet." >&2
exit 7
fi
if ! ci -u "$1"; then
echo "$0: Couldn't check $1 into RCS." >&2
exit 8
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment