#!/bin/tcsh -f # # Add a tag to photos. # Any arguments that are existing files will be added to the file list. # Any arguments that are not files will be added to the tags list. # (It's probably easier to delete unwanted tags afterward # than to add tags to photos individually.) # # File arguments should be the jpg/JPG files. # OR the jpg.txt or JPG.txt files. 2020/Dec/24 # # Brent Chivers 2016/Dec/07 # # Expand directory arguments into file lists. 2016/Feb/27 # Tags should be added to the .txt files, not .tag. 2016/Aug/ 2016/Nov/06 # Use photo-path to find website path to photo. 2020/Nov/10 # This allows using short file names. # Exit if no tags (i.e. args all all filenames). # Don't continue if no files are found. (Don't add tag(s) to everything!) # Allow .txt files as arguments; don't create .txt.txt files. ##! /bin/tcsh -fb # for setuid/setgid scripts (tsk) # set verbose # see commands before variable substitution # set echo # see commands after variable substitution unset histchars # get other users' history characters out of the way unalias * # get other users' .cshrc stuff out of the way ## set nonomatch # don't require wildcard matches set FILES = "" set TAGS = "" # echo "pwd is `pwd`" foreach ARG ( $* ) if ( -d $ARG ) then set FILES = ( $FILES `/usr/bin/find $ARG -type f -name '*.[Jj][Pp][Gg]'` ) else if ( -f $ARG ) then set FILES = ( $FILES $ARG ) else set FILEPATH = `photo-path $ARG` if ( "$FILEPATH" == "" ) then # no file matches $ARG set TAGS = ( $TAGS $ARG ) else set FILES = ( $FILES $FILEPATH ) endif endif endif end if ( "$TAGS" == "" ) then # no new tags to add echo "No tags provided." exit endif if ( "$FILES" == "" ) then echo "No files found." exit endif #if ( "$FILES" == "" ) then # tag all pictures in the directory tree # set FILES = `/usr/bin/find . -type f -name '*.[Jj][Pp][Gg]' | /usr/bin/cut -c3-` # endif # # need to make changes here.... # foreach FILE ($FILES) set FILE = `echo $FILE | /bin/sed 's/\.txt//'` # chop .txt from file names if ( -f $FILE.txt ) then # .txt file exists set TAGLINE = `/bin/grep '^tags:' $FILE.txt` if ( "$TAGLINE" == "" ) then # no tags: line; add one echo "creating tags line for $FILE.txt." echo "tags: $TAGS" >> $FILE.txt else # foreach TAG ( $TAGS ) # echo $TAG >> $FILE.tags # end set NEWTAGS = `echo $TAGLINE $TAGS | /bin/sed 's/^tags://' | /usr/bin/tr ", " '\012' | /usr/bin/sort | /usr/bin/uniq ` # echo 'TAGLINE is "'$TAGLINE'".' # echo 'NEWTAGS is "'$NEWTAGS'".' # echo 'FILE is "'$FILE'".' /home/bchivers/commands/chstrp "$TAGLINE" "tags: $NEWTAGS" $FILE.txt endif else # no .txt file; create one with the tag(s) echo "creating new $FILE.txt file." echo "tags: $TAGS" >> $FILE.txt endif end