Skip to content

Commit e1e625c

Browse files
ZeroPointEnergybhush9
authored andcommitted
support existing tmux session
Create a new windows instead of a new session if the current terminal already runs a tmux session.
1 parent a058ac4 commit e1e625c

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

halium-chroot

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,20 @@ if [ $# -eq 0 ]
4444
then # Interactive shell
4545
if [ $(which tmux) ]
4646
then # with tmux installed
47-
tmux new-session -s halium-adb -d 'adb shell'
47+
TARGET="halium-adb-$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)"
48+
if [ $TMUX ]
49+
then # create new window if we are in a tmux session
50+
tmux new-window -n $TARGET -d 'adb shell'
51+
SWITCH='select-window'
52+
else # create a new tmux session if none exists
53+
tmux new-session -s $TARGET -d 'adb shell'
54+
SWITCH='attach-session'
55+
let LINES-=1
56+
fi
4857
sleep 1
49-
let LINES-=1
50-
tmux send-keys -t halium-adb "export LINES=${LINES}; export COLUMNS=${COLUMNS}"$'\n'
51-
tmux send-keys -t halium-adb "${CHROOT} /bin/bash; exit"$'\n'
52-
tmux attach -t halium-adb
58+
tmux send-keys -t $TARGET "export LINES=${LINES}; export COLUMNS=${COLUMNS}"$'\n'
59+
tmux send-keys -t $TARGET "${CHROOT} /bin/bash; exit"$'\n'
60+
tmux $SWITCH -t $TARGET
5361
else # without tmux installed
5462
echo 'To automatically get an interactive chroot session, install'
5563
echo 'The program "tmux". To enter the chroot environment run:'

0 commit comments

Comments
 (0)