[Sussex] workaround script

Steve Dobson steve at dobson.org
Sun Oct 3 23:08:56 UTC 2004


John / Thomas

On Sun, Oct 03, 2004 at 10:51:06PM +0100, Thomas Adam wrote:
> On Sun, Oct 03, 2004 at 10:40:42PM +0100, John Crowhurst wrote:
> > joe does, but the script falls over terribly, as it tries to create a file
> > /tmp/path/to/filename.
> 
> Let me re-write your script in bash:
> --------
> #!/bin/sh
> for i in "$@"; do
>   a=$(basename $i)
>   [ -f "/tmp/$a" ] && rm -f /tmp/$a
>   cp "$i" /tmp/$a
>   joe /tmp/$a
>   diff -u /tmp/$a $a > /tmp/changes
>   mail -s "joe: $PWD/$x changes" $USER </tmp/changes
>   rm /tmp/$a
> done
> ----------

May I suggest that by standing back there is a better way of keeping
track of changes to file - Version Control!  There is no need to 
keep loads of little e-mails with the edits to your files, all edits
can be stored in the VC file.

I've selected RCS here as it uses a local file for the repository so
you can create a new repository very easily.

----- vedit ------
#!/bin/bash
#
# By Steve Dobson
for filespec in "$@"; do
  dir=`dirname ${filespec}`
  file=`basename ${filespec}`

  # If the file is under version control get it out for editing
  if [ -f ${dir}/RCS/${file},v ] ; then
    # Need to make sure that the file is not writeable
    #  Just incase some id10t has not be using this script
    #  to edit the file
    chmod a-w ${filespec}

    # Update the file under version control
    (cd ${dir}; co -l -q ${file})
  fi

  # Now edit the file using the user's editor of choice.
  ${EDITOR} ${filespec}

  # Create the RCS repository if it doesn't exist
  mkdir -p ${dir}/RCS

  # Put this new version of the file under version control
  #  Note the use of /dev/null to supprest the prompting
  #  for a version message
  if [ -f ${dir}/RCS/${file},v ] ; then
    # Update the file under version control
    (cd ${dir}; cat /dev/null | ci -u -q ${file})
  else
    # As this is a new file put it under version control
    (cd ${dir}; cat /dev/null | ci -u -q ${file})
  fi
done

exit 0
-----------------

You can then see all version of the file with the "rlog" command
thus:

	$ rlog vedit
	
	RCS file: RCS/vedit,v
	Working file: vedit
	head: 1.2
	branch:
	locks: strict
	access list:
	symbolic names:
	keyword substitution: kv
	total revisions: 2;     selected revisions: 2
	description:
	----------------------------
	revision 1.2
	date: 2004/10/03 23:01:00;  author: steve;  state: Exp;  lines: +2 -2
	*** empty log message ***
	----------------------------
	revision 1.1
	date: 2004/10/03 22:57:38;  author: steve;  state: Exp;
	Initial revision
	=====================================================================

An the changes to the file can be view with the "rsdiff" command:

	 $ rcsdiff -u -r1.1 vedit
	===================================================================
	RCS file: RCS/vedit,v
	retrieving revision 1.1
	diff -u -r1.1 vedit
	--- vedit       2004/10/03 22:57:38     1.1
	+++ vedit       2004/10/03 23:01:04
	@@ -1,4 +1,4 @@
	-#!/bin/bash
	+#!/bin/bash -x
 	#
 	# By Steve Dobson
 	for filespec in "$@"; do
	@@ -6,7 +6,7 @@
   	file=`basename ${filespec}`
	
   	# If the file is under version control get it out for editing
	-  if [ -f ${dir}/CVS/${file},v ] ; then
	+  if [ -f ${dir}/RCS/${file},v ] ; then
     	# Need to make sure that the file is not writeable
     	#  Just incase some id10t has not be using this script
     	#  to edit the file
	
Steve




More information about the Sussex mailing list