#/bin/sh # @(#) viall Edit all files into one large file # # Define a temporary file : t=/tmp/`basename $0`.$$ # # Erase the temporary file when script is interrupted : trap 'rm -f $t ; exit 0' 1 2 15 # # Process command line arguments : if [ $# -ne 0 ] ; then # user specified arguments echo $* | tr ' ' '\012' # separate them by newlines else # no command-line file arguments cat # gather names from stdin fi | { # # Write header at beginning of combined file : echo 't=/tmp/$$ ; e=0' # define temp. file, exit status # # Define function to unpack shell archive : echo 'la_fonc() { cat >$t && { cmp -s $t $f || { echo $f ; cp $t $f ; } ; } || e=1 ; }' # # Process the file names : while read f ; do [ ! -f $f ] && continue # fetch next name if file doesn't exist echo ":" [ ! -w $f ] && (echo ': %%%%%%%%%%%%%%%'; echo ': % READ-ONLY %') #if not writable echo ": %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" echo " f=$f" echo ": %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" echo ":" # # Create shell archive containing file contents : echo "la_fonc <<'END_OF_FILE '$f" # construct "here" document cat $f # include file contents echo END_OF_FILE $f # end of "here" document done # # Write commands to end clean up and exit : echo 'rm -f $t' # rmove the temporary file echo 'exit $e' # exit status with $e } > $t # everything combined in temp. file trap 1 2 15 # reset default signal handling trap '' 2 3 # ignore intr, quit signals while editing # # Invoke the editor specified as VISUAL, EDITOR or vi by default ${VISUAL-${EDITOR-vi}} $t