Skip to content

Instantly share code, notes, and snippets.

@Pistos
Last active October 24, 2020 03:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Pistos/0bf26f46c04bc43cc95c224d264e9f39 to your computer and use it in GitHub Desktop.
Save Pistos/0bf26f46c04bc43cc95c224d264e9f39 to your computer and use it in GitHub Desktop.
Ruby REPL for typing text on Android via adb
require "readline"
def escaped(s)
s.gsub("'", "'\\\\''")
end
while s = Readline.readline("> ", true)
e = escaped(s)
puts `./android-type.sh '#{e}'`
end
#!/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