Standardized indentation and moved url encoding/decoding to a more

standardized location.
This commit is contained in:
Bruce Hill 2020-08-06 15:25:48 -07:00
parent f154424db2
commit 9d18bcc775

39
bin
View File

@ -31,7 +31,7 @@ fail() {
}
show_usage() {
cat << EOU
cat <<-EOU
Usage: $progname [OPTION]... FILE...
Move files into the trash bin.
@ -104,6 +104,34 @@ has_arg() {
fi
}
encoder=
if command -v php &> /dev/null; then
encoder=php
elif command -v python3 &> /dev/null; then
encoder=python
elif command -v perl &> /dev/null; then
encoder=perl
else
echo "No URL encoder found! Please install php, python3, or perl!" 1>&2
exit 1
fi
urlencode() {
case "$encoder" in
php) php -r 'echo urlencode($argv[1]);' -- "$1" ;;
perl) perl -MURI::Escape -e 'print uri_escape $ARGV[0]' -- "$1" ;;
python) python3 -c 'import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))' "$1";;
esac
}
urldecode() {
case "$encoder" in
php) php -r 'echo urldecode($argv[1]);' -- "$1" ;;
perl) perl -MURI::Escape -e 'print uri_unescape $ARGV[0]' -- "$1" ;;
python) python3 -c 'import urllib.parse, sys; print(urllib.parse.unquote(sys.argv[1]))' "$1";;
esac
}
is_valid_trashdir() {
[ -d "$1" ] && expr "$(stat -c '%a' "$1")" : '^1[0-7]\{3\}' >/dev/null && ! [ -L "$1" ]
}
@ -150,8 +178,7 @@ init_trashdir() {
}
path_from_trashinfo() {
#sed -n 's/^Path=//p' "$1" | php -r 'echo urldecode(fgets(STDIN));'
sed -n 's/^Path=//p' "$1" | perl -MURI::Escape -ne 'print uri_unescape $_'
urldecode "$(sed -n 's/^Path=//p' "$1")"
}
date_from_trashinfo() {
@ -159,10 +186,9 @@ date_from_trashinfo() {
}
trashinfo_for_file() {
#php -r 'echo urlencode($argv[1]);' -- "$1"
cat <<END
cat <<-END
[Trash Info]
Path=$(perl -MURI::Escape -e 'print uri_escape $ARGV[0]' -- "$1")
Path=$(urlencode "$1")
DeletionDate=$(date +"%FT%H:%M:%S")
END
}
@ -299,3 +325,4 @@ case "$action" in
done
;;
esac
# vim: ts=2:noexpandtab:ft=sh