这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions scripts/termux-open.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ if [ -f "$FILE" ]; then
FILE=$(realpath "$FILE")
fi

urlencode() {
string="$1"
length=$(echo "$string" | wc -c)
length=$((length - 1))
encoded=""

i=1
while [ "$i" -le "$length" ]; do
char=$(echo "$string" | cut -c "$i")
case "$char" in
[a-zA-Z0-9.~_-]) encoded="$encoded$char";;
*) encoded="$encoded%$(printf "%02X" "'$char")";;
esac
i=$((i + 1))
done

echo "$encoded"
Comment on lines +44 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be done much easier without invoking external commands lots of times.

Suggested change
string="$1"
length=$(echo "$string" | wc -c)
length=$((length - 1))
encoded=""
i=1
while [ "$i" -le "$length" ]; do
char=$(echo "$string" | cut -c "$i")
case "$char" in
[a-zA-Z0-9.~_-]) encoded="$encoded$char";;
*) encoded="$encoded%$(printf "%02X" "'$char")";;
esac
i=$((i + 1))
done
echo "$encoded"
for ((i=0; i<${#1}; i++)); do
case "${1:i:1}" in
[a-zA-Z0-9.~_-]) printf '%s' "${1:i:1}" ;;
*) printf '%%%02X' "'${1:i:1}" ;;
esac
done
echo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it is regular /bin/sh, not a bash. Right.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we switch to bash here?

}

FILE=$(urlencode "$FILE")

am broadcast --user 0 \
-a $ACTION \
-n com.termux/com.termux.app.TermuxOpenReceiver \
Expand Down