pub / helix-term

Interactive console for the Helix-Editor using TMUX
git clone https://https://src.jayvii.de/pub/helix-term.git
Home | Log | Files | Exports | Refs | README | RSS

commit febb0f5e9d361f6cf0c290a1df06c66a9b64091a
parent 9729e9de93a8079a29a6b4f19973b54cbe469a1f
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Wed, 16 Oct 2024 10:04:51 +0200

feat: give option to attach to tmux if session exists already

Diffstat:
Mbin/helix-term | 30+++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/bin/helix-term b/bin/helix-term @@ -2,6 +2,13 @@ # SPDX-License-Identifier: GPL-3.0-or-later # SPDX-FileCopyrightText: 2023-2024 JayVii <jayvii[AT]posteo[DOT]de> +# Grab command +if [[ -z "$1" ]]; then + CMD="$SHELL" +else + CMD="$1" +fi + # unset TMUX variable to enforce launch TMUX="" @@ -10,21 +17,22 @@ TMUX_SESSION=$(echo "$PWD/" | base64) # set session ID for current working directory if [ ! -f "./.helixterm_session" ]; then - echo "$TMUX_SESSION" > "./.helixterm_session" + echo "$TMUX_SESSION" | tee "./.helixterm_session" else - echo "There already exists a session in $PWD!" - exit 1; + echo "There already exists a session file in $PWD/.helixterm_session ." + echo "Should we try attaching to it (it might run a different process)?" + echo "[ENTER] or [CTRL-C]" + read || exit 1 fi -# Grab command -if [[ -z "$1" ]]; then - CMD="$SHELL" +# check if any tmux session fits the new name, if it does attach to it +if [[ ! -z $(tmux ls | grep "$TMUX_SESSION") ]]; then + tmux attach -t "$TMUX_SESSION" else - CMD="$1" + tmux -2 new-session -s "$TMUX_SESSION" "$CMD" fi -# Create new tmux session -tmux -2 new-session -s "$TMUX_SESSION" "$CMD" - # Remove session ID -rm "./.helixterm_session" +if [ ! -f "./.helixterm_session" ]; then + rm "./.helixterm_session" +fi