几分钟即可拥有一个花里胡哨的 adb shell~

原理就是 termux + ssh + fish shell + tmux。
配置步骤
下载 termux
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| 安装 termux.apk # 选择 china 镜像源 termux-change-repo # 更新 apt update && apt upgrade # 安装 fish/tmux/openssh/bat/fd apt install fish tmux openssh fd bat # 配置 fish 为默认 termux shell,输入 fish chsh # 下次默认会自动进 fish,这次我们要手动进 fish fish # 安装 fisher https://github.com/jorgebucaran/fisher curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher # 安装 fzf,`CTRL+R` 搜索历史命令... fisher install PatrickF1/fzf.fish # 安装 zoxide,快速跳转 cd 过的目录。z + 缩写,就能跳转目录 fisher install kidonng/zoxide.fish # 修改 termux 用户密码 passwd # 启动 ssh 服务 sshd
|
使用电脑连接到手机
配置工作完成,有两种方式可以在电脑上连接:
- USB 连接手机.
1 2 3 4
| # 将 termux ssh 端口转发到电脑 adb forward tcp:8022 tcp:8022 # 连接手机,密码就是刚才 passwd 设置的密码 ssh root@localhost -p 8022
|
- 局域网直连.
也可以直接 ssh 连手机 ip 。关于 tmux
tmux 是一个超屌的工具,网上一堆介绍,简单来说就是可以在一个终端开多个窗口,同时搬更多的砖。这里放上我的快捷键配置 .tmux.conf
。
vim ~/.tmux.conf
内容见下面文件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| set -g default-shell /data/data/com.termux/files/usr/bin/fish #set -g default-command /usr/bin/zsh #设置前缀为Ctrl + a set -g prefix C-a #解除Ctrl+b 与前缀的对应关系 unbind C-b #up bind-key k select-pane -U #down bind-key j select-pane -D #left bind-key h select-pane -L #right bind-key l select-pane -R #copy-mode 将快捷键设置为vi 模式 setw -g mode-keys vi # split window unbind '"' # vertical split (prefix -) bind - splitw -v unbind % bind | splitw -h # horizontal split (prefix |)
|
简单使用:
- 输入
tmux
,启动 tmux
CTRL+a
: 进入命令模式
CTRL+a
之后按 -
垂直分割窗口
CTRL+a
之后按 |
水平分割窗口
CTRL+a
之后按上下左右,切换窗口关于 fish shell 样式
强烈推荐 oh-my-zsh 的 ys
主题,超好看。简单复刻了一个到 fish,编辑 ~/.config/fish/function/fish_prompt.fish
,具体内容见下面文件。
1 2 3 4 5 6
| function fish_prompt -d "Write out the prompt" printf '%s %s @ %s in %s [%s] \n%s ' (set_color blue)(echo \ (set_color yellow)(prompt_pwd)(set_color normal) \ (echo -n (date +%H:%M:%S)) \ (set_color red)(echo \$)(set_color normal) end
|
关于 root
如果你有 root 权限,在 termux 内输入 tsu
即可进入 root 环境。
但是我们刚配置好的内容,对 root 用户是不生效的。我是用软链接把配置放到了 root 用户目录一份。
1 2 3 4 5 6 7 8 9 10
| # 链接 .config 目录 ln -s /data/data/com.termux/files/home/.config/ /data/data/com.termux/files/home/.suroot/.config # 链接 tmux 配置 ln -s /data/data/com.termux/files/home/.tmux.conf /data/data/com.termux/files/home/.suroot/.tmux.conf # 进入 root tsu # 切换默认 shell chsh # 下次默认会自动进 fish,这次我们要手动进 fish fish
|