Skip to content

Commit dc0d100

Browse files
committed
Use awk when untrashing files
Need to get the filename from a file that looks like: [Trash Info] Path=/home/ben/myprojects/vv/f(o)o%5C'&$%7Bx%7D%3C%7C%3E!.gif DeletionDate=Y-05-20T15:44:21 Previously was doing `eval $(grep Path filename.info)` to set Path, but that was silly as certain metacharacters that are special to the shell are not special to URIs and aren't percent encoded. [Okay, to be honest, using "eval" is always silly.] Fixed it by simply using awk instead of grep so I could output just the filename. That replaces a dozen lines of kludges to make it work (+ more lines of comments for explanations) with a single line. Yay!
1 parent 495da54 commit dc0d100

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

vv

+1-27
Original file line numberDiff line numberDiff line change
@@ -2193,24 +2193,6 @@ unuriescape() {
21932193
echo
21942194
}
21952195

2196-
uriescapeshell() {
2197-
# Given a string that has already been URI escaped, also
2198-
# percent-escape the characters that would confuse eval.
2199-
# Any data after a newline are ignored.
2200-
2201-
# These characters will already be URI encoded: "#%< >[\]^`{|}
2202-
# So all we need to encode are: $&'()
2203-
2204-
sed -n '1 {
2205-
s#\$#%24#g;
2206-
s#&#%26#g;
2207-
s#'\''#%27#g;
2208-
s#(#%28#g;
2209-
s#)#%29#g;
2210-
p
2211-
}'
2212-
}
2213-
22142196
untrash() {
22152197
# untrash: Take the most recent file out of ~/.local/share/Trash/files.
22162198
#
@@ -2246,15 +2228,7 @@ untrash() {
22462228
fi
22472229
done
22482230

2249-
2250-
local infoline=$(grep 'Path=' "$infofile" | uriescapeshell)
2251-
if [[ -z "$infoline" ]]; then
2252-
E "$infofile does not contain a valid Path" >&2
2253-
return 1
2254-
fi
2255-
2256-
local Path
2257-
eval "$infoline"
2231+
local Path=$(awk -e '/^Path=/ {print substr($0,6); exit;}' "$infofile")
22582232
Path=$(unuriescape "$Path")
22592233

22602234
# Does directory even existing for us to write to?

0 commit comments

Comments
 (0)