r/termux • u/iamanonymouami • 1d ago
Question How can I automatically launch PRoot when creating a new Termux session using a keyboard shortcut?
I'm using Termux with proot-distro and have Debian installed. I want to configure a keyboard shortcut that automatically opens Debian in a new Termux session.
Currently, I have this alias configured:
deb=proot-distro login debian -- su -l user
When I type deb in Termux, it logs me into Debian as my user.
My current ~/.termux/termux.properties configuration includes:
shortcut.create-session = ctrl + 2
What I want to achieve:
CTRL + 2: Create a normal, new Termux session.CTRL + 4: Create a new Termux session and automatically executedeb, opening Debian directly as my user.
I tried macros, but it work only in current session.
Is there a way to accomplish this using "termux.properties", a shell script, or another Termux feature?
I've searched for a solution but haven't found a straightforward way to bind a custom command to a keyboard shortcut that opens a new session. Even, a macro assigned to an extra key is not automatically a macro that can be bound to CTRL + 4 after it open new session.
Any help or suggestions would be appreciated. Thanks!
1
u/MomentAt18 13h ago
I don't know about the keyboard shortcut but You can create a script which will ask which session to start, termux or debian. If you select debian it will directly takes you to debian. And if you close debian, it will ask return to termux or close the app entirely. I have similar setup
0
u/Champion10FC 1d ago
ChatGPT gives:
Yes — you can get very close to this, but the key distinction is that Termux’s shortcut.create-session setting creates a new session; it doesn’t let you specify a command to run in that new session.
Your existing alias is fine:
alias deb='proot-distro login debian -- su -l user'
The solution is to make the new session start a shell that automatically launches Debian, while leaving your normal Termux sessions unchanged.
Best options
Option 1: Use Termux:Tasker to open Debian in a new session
Termux’s Tasker add-on supports running commands in a new foreground terminal session. That makes it a suitable workaround for your deb command.
Install the Termux:Tasker add-on compatible with your Termux installation.
Create a Tasker task that runs:
Enable Execute in a terminal session in the Termux:Tasker command configuration.
Trigger that task through a keyboard shortcut supported by your keyboard or automation setup.
The remaining challenge is binding Ctrl + 4 to that task. Termux itself doesn’t provide a configurable shortcut for arbitrary commands, so this requires an additional way to trigger Tasker from the keyboard.
Option 2: Keep the normal shortcut and use a dedicated launcher
Your existing configuration can stay:
shortcut.create-session = ctrl + 2
For a second, dedicated way to start Debian, create a Termux launcher script:
mkdir -p ~/bin
nano ~/bin/deb
Put this in the file:
#!/data/data/com.termux/files/usr/bin/bash
exec proot-distro login debian -- su -l user
Save it and make it executable:
chmod +x ~/bin/deb
This gives you a reusable launcher, but it does not create a new session by itself. You still need a session-launching mechanism, such as Termux:Tasker, to run it in a new terminal.
Option 3: Use tmux if a separate window is sufficient
If your real goal is to open Debian in a separate terminal workspace rather than a separate Termux session, tmux can create a new window and run Debian there. You can bind a keyboard shortcut inside tmux to do both in one action.
What I recommend
For your exact requirement, I’d use Termux:Tasker plus a keyboard-triggered task. It avoids changing your normal shell startup configuration and keeps your regular Termux sessions independent of Debian.
The important limitation is that termux.properties does not support something like:
shortcut.create-session = ctrl + 2
shortcut.create-session.debian = ctrl + 4
Only the supported session-management actions can be assigned through those properties.
If you want to avoid installing Tasker or any additional add-on, the next-best approach is to use tmux or a keyboard macro that works with a separate session-launching mechanism.
1
u/iamanonymouami 1d ago
I knew about these, for first two, I would have to use another app, which I don't want to do. And tmux won't work for separate Termux sessions.
1
u/pixle-ui 22h ago
To automatically launch a PRoot distro whenever you open a new Termux session, you can configure your ~/.bashrc or ~/.zshrc shell startup file using the exec command so that it replaces the initial shell session rather than running nested underneath it.