Skip to content

Instantly share code, notes, and snippets.

@jduck
Created February 6, 2014 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jduck/8849310 to your computer and use it in GitHub Desktop.
Save jduck/8849310 to your computer and use it in GitHub Desktop.
Patch for AOSP's adb client to automatically change directory, set terminal size, and set environment vars.
#
# patch adb to:
# 1. use busybox to set the same terminal size
# 2. change directory to /data/local/tmp automatically
#
# NOTE: needs an executable busybox in /data/local/tmp
#
# Joshua J. Drake - jduck
#
diff --git a/adb/commandline.c b/adb/commandline.c
index 956ac42..62f40d7 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -22,6 +22,7 @@
#include <limits.h>
#include <stdarg.h>
#include <sys/types.h>
+#include <sys/ioctl.h>
#include <sys/stat.h>
#include <ctype.h>
#include <assert.h>
@@ -358,15 +359,24 @@ static void *stdin_read_thread(void *x)
int interactive_shell(void)
{
adb_thread_t thr;
- int fdi, fd;
+ int fdi = 0, fd;
int *fds;
+ struct winsize w;
+ char buf[4096];
- fd = adb_connect("shell:");
+ if (ioctl(fdi, TIOCGWINSZ, &w) == -1) {
+ perror("error: ioctl TIOCGWINSZ");
+ strcpy(buf, "shell:");
+ }
+ else {
+ sprintf(buf, "shell:export HOME=/data/local/tmp;cd;./busybox stty rows %d cols %d;sh", w.ws_row, w.ws_col);
+ }
+
+ fd = adb_connect(buf);
if(fd < 0) {
fprintf(stderr,"error: %s\n", adb_error());
return 1;
}
- fdi = 0; //dup(0);
fds = malloc(sizeof(int) * 2);
fds[0] = fd;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment