Last active
November 6, 2024 21:11
-
-
Save Pistos/0bf26f46c04bc43cc95c224d264e9f39 to your computer and use it in GitHub Desktop.
Ruby REPL for typing text on Android via adb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "readline" | |
def escaped(s) | |
s.gsub("'", "'\\\\''") | |
end | |
while s = Readline.readline("> ", true) | |
e = escaped(s) | |
puts `./android-type.sh '#{e}'` | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Expanded from https://stackoverflow.com/a/46751558/28558 | |
text=$(printf '%s%%s' ${@}) # concatenate and replace spaces with %s | |
text=${text%%%s} # remove the trailing %s | |
text=${text//\'/\\\'} # escape single quotes | |
text=${text//\"/\\\"} # escape double quotes | |
text=${text//\&/\\\&} # escape ampersands | |
text=${text//\;/\\\;} # escape semicolons | |
text=${text//\(/\\\(} # escape opening parentheses | |
text=${text//\)/\\\)} # escape closing parentheses | |
text=${text//\|/\\\|} # escape pipes | |
text=${text//\$/\\\$} # escape dollar signs | |
# echo "[$text]" # debugging | |
adb shell input text "$text" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment