-
Notifications
You must be signed in to change notification settings - Fork 0
/
migPutCommentInFile.sh
executable file
·73 lines (61 loc) · 2.04 KB
/
migPutCommentInFile.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#
# Written and contributed by:
# Artem G. Abanov <aga@andrey.physics.wisc.edu>
#
#######################################################################
#
# Here is a very amateurish script to show a jpg image an ask for a
# new comment to be put into the jpeg file.
# It does not do any checking or anything whatsoever.
#
# IT REPLACES ALL OLD COMMENTS!!!!!
#
#######################################################################
#
# This script requires these external programs:
#
# "rdjpgcom" (part of the "jpeg" package)
# "wrjpgcom" (part of the "jpeg" package)
#
# If you do not have these programs, you can get a copy of the jpeg package
# by anonymous FTP at ftp://ftp.uu.net/graphics/jpeg/ or if you are using
# something like Linux you can probably install it with an RPM (these are
# part of the "libjpeg-6b-9" Redhat package at time of this writing).
#
# "eog" (this can be replaced by any other image viewer... ee, xv, etc.
#
# Put here the name of the comand you want to view your jpegs with
viewcommand=eog
echo ""
echo " Look at the picture and enter new comment at prompt."
echo " To finish your comment enter <RETURN> twice."
echo ""
for filename in "$@"; do
# Start the view command
$viewcommand "$filename" &
# Get the old comment
oldcomment=$(rdjpgcom "${filename}")
# Ask for the new comment
echo "$filename"
echo "Enter new comment [ $oldcomment ]? "
read -r comment1
while test "${comment1}"; do
sep=""
if test "${comment}"; then
sep='\n'
fi
comment="${comment}${sep}${comment1}"
read -r comment1
done
# Kill the viewer
kill $!
# Echo the new comment back (use the old comment if the new wasn't set)
echo -e "new comment:\n${comment:=$oldcomment}"
echo ""
# Replace the comment in the file
TEMP_FILE=$(mktemp)
wrjpgcom -replace -comment "\"${comment}\"" "${filename}" > "${TEMP_FILE}"
# Move the newly commented file back
mv "${TEMP_FILE}" "${filename}"
done