Skip to content

Instantly share code, notes, and snippets.

@Pistos
Last active November 6, 2024 21:11
Show Gist options
  • 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