The following code can serve as a template for creating a bash utility. The purpose of this wrapper utility is to checkout a file, edit in an editor and check the file back in.
The following is the command usage
root@host# ./rcwrapper [-c "comment goes here"] filename1 [filename2 filename3 ...]
#!/bin/bash
#########################
## Author: Nirav Doshi ##
## Date: Sept 25, 2012 ##
## Purpose:
## Facilitate checkout, edit
## and checkin process for code viewing,
## and editing.
#############################
export EDITOR=vim
while [ $# -gt 0 ]; do #until run out of parameters
case "$1" in
-c)
# Move the cursor to next argument which has comment information
shift
# set the comment value
if [ -n "$1" ] #compare if -c is passed with an argument
then
COMMENT=$1
echo "comment is \"$COMMENT\""
else
COMMENT="no comment supplied"
echo $COMMENT
fi
;;
*)
# Check out the file from repository
echo "CO -c \"$COMMENT\" $1"
# Calls the Editor program varriable along with filename
$EDITOR $1
# Checking file into the repository
echo "CI -c \"$COMMENT\" $1"
;;
esac
shift
done
No comments:
Post a Comment