Skip to content

Instantly share code, notes, and snippets.

@zongou
Created January 16, 2023 05:54
Show Gist options
  • Save zongou/5a6a6e58c2cc621209ce259e224cdb78 to your computer and use it in GitHub Desktop.
Save zongou/5a6a6e58c2cc621209ce259e224cdb78 to your computer and use it in GitHub Desktop.
#! /bin/sh
# send text to android using built-in command on termux and anotherterm
[ -n "$TERMSH" ] && isAnotherterm="true" || isAnotherterm="false"
[ -n "$TERMUX_VERSION" ] && isTermux="true" || isTermux="false"
recipient=""
recipient="be.shiro.android.toclipboard/.ToClipboard"
if [ -n "$1" ]; then
if "$isAnotherterm"; then
"$TERMSH" send --text "$1"
elif "$isTermux"; then
am start \
-a android.intent.action.SEND \
-t text/plain \
-e android.intent.extra.TEXT "$1"
fi
else
if "$isAnotherterm"; then
"$TERMSH" send --text-stdin
elif "$isTermux"; then
stdin=$(cat; printf x)
stdin=${stdin%x}
am start \
-a android.intent.action.SEND \
-t text/plain \
-e android.intent.extra.TEXT "$stdin"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment