#!/bin/csh -f # diffrecent # ----------------------------------------------------------------------------- # Shell script to find all recently edited files in the current folder tree # and compare each with recent versions of it in my backup directory. # ----------------------------------------------------------------------------- # Usage: See Usage section below or run with -h or --help to see usage. # Assumptions: # Effects: # - Compares file # Notes: # Implementation Notes: # Portability Issues: # Revision History: # $Log$ # ----------------------------------------------------------------------------- # Collect command line options set option_quick = "false" set find_maxdepth_primary = "-maxdepth 0" while ($#argv > 0) if ("$1" == "-h" || "$1" == "--help") then echo "Usage: $0:t [options] [number_of_days]" echo "Options:" echo " -h = Show this help text" echo " --help = Show this help text" echo " -d n = Max depth of subfolders to search (default: 0)" echo " --maxdepth n = Max depth of subfolders to search (default: 0)" echo "Args:" echo " number_of_days = Number of days considered recent (default: 1)" echo " or "all" for all days" exit 1 else if ("$1" == "-d" || "$1" == "--maxdepth") then shift if ("$1" == "") then echo "Error: Missing argument to -d or --maxdepth option" $0 --help exit 1 else set find_maxdepth_primary = "-maxdepth $1" shift endif else if ("-" == "`echo $1:q | cut -c 1`") then echo "Error: Invalid option: $1:q" $0 --help exit 1 else # Not a recognized option. Assume it's the first argument break endif end if ($#argv > 1) then $0 -h exit 1 endif # Collect command line arguments set find_mtime_primary = "" set day_count = "" if ("$1" == "all") then set day_count = "all" set find_mtime_primary = "" else if ("$1" == "") then set day_count = "1" set find_mtime_primary = "-mtime -1" else set day_count = "$1" set find_mtime_primary = "-mtime -$1" endif # Create a command to loop through all files modified in the optionally # specified number of days, most recently modified first, searching the # optionally specified number of subfolder levels. # Notes: # "''" Double quotes outside the backticks cause the list of # filenames, one per line, generated by find, to be quoted # so that embedded whitespace and special chars are tolerated. # The foreach command then operates on each line as a # filename, not each word of each line as a filename. # find A command to find files # * Start searching at each file in the current folder, except # those whose names start with "." # -mtime -$1 Find files modified at a time less than or equal (-) to # the specified number of days ($1). # -maxdepth $1 Search recursively from each starting file only to the # specified depth of subfolders ($1). # -exec Run the stat command for each found file, so that its output # to stdout can be piped through the sort command. # stat A command to echo info about a specified file # -f Format string for output of stat # %m Echo the modified timestamp as a decimal number of seconds # %t Echo a tab char # %N Echo the filename # '{}' Insert filename into the stat command executed by -exec # ";" End of the command to be executed by exec # | sort A command to sort the output # | cut A command to cut out portions of each line # -f2 Cut all except the 2nd tab-delimited field (the filename) set find_cmd = "find * $find_mtime_primary $find_maxdepth_primary -not -ipath '*Mozilla/*' -exec stat -f '%m%t%N' '{}' ';' | sort --numeric-sort --reverse | cut -f2" # Check explicitly for zero local files. Otherwise, it causes find to # report "find: No match.". ls * >& /dev/null if ($status) then set file_count = "0" else set file_count = "`$find_cmd | wc -l`" # Strip off leading and trailing spaces @ file_count = $file_count endif # Report the number of files found echo -n "$file_count file" if ("$file_count" != "1") echo -n "s" echo -n " modified" if ("$day_count" == "all") then echo -n " in forever" else echo -n " in past $day_count day" if ("$day_count" != "1") echo -n "s" endif if ("$file_count" == "0") then echo "." exit 0 endif echo ":" ls -Fldt "`$find_cmd`" # Process each file foreach file ("`$find_cmd`") echo "" echo "File: $file:q" ls -Fld $file:q if (-d $file:q) then echo "Skipping modified folder $file:q, unless -d option was used." pause else if (-l $file:q) then echo "Skipping modified symlink $file:q." pause else set action = `promptloop "Review via windiff(w), via diff(d), skip(s) or quit(q)? " w d s q` if ("${action}" == "q") then exit 0 else if ("${action}" == "s") then continue else if ("${action}" == "d") then diffquick -q $file:q else if ("${action}" == "w") then diffquick -i $file:q endif endif end