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

helix-term (995B)


      1 #!/usr/bin/env bash
      2 # SPDX-License-Identifier: GPL-3.0-or-later
      3 # SPDX-FileCopyrightText: 2023-2024 JayVii <jayvii[AT]posteo[DOT]de>
      4 
      5 # Grab command
      6 if [[ -z "$1" ]]; then
      7     CMD="$SHELL"
      8 else
      9     CMD="$1"
     10 fi
     11 
     12 # unset TMUX variable to enforce launch
     13 TMUX=""
     14 
     15 # generate tmux-session name
     16 TMUX_SESSION=$(echo "$PWD/" | base64)
     17 
     18 # set session ID for current working directory
     19 if [ ! -f "./.helixterm_session" ]; then
     20     echo "$TMUX_SESSION" | tee "./.helixterm_session"
     21 else
     22     echo "There already exists a session file in $PWD/.helixterm_session ."
     23     echo "Should we try attaching to it (it might run a different process)?"
     24     echo "[ENTER] or [CTRL-C]"
     25     read || exit 1
     26 fi
     27 
     28 # check if any tmux session fits the new name, if it does attach to it
     29 if [[ ! -z $(tmux ls | grep "$TMUX_SESSION") ]]; then
     30     tmux attach -t "$TMUX_SESSION"
     31 else
     32     tmux -2 new-session -s "$TMUX_SESSION" "$CMD"
     33 fi
     34 
     35 # Remove session ID
     36 if [ ! -f "./.helixterm_session" ]; then
     37     rm "./.helixterm_session"
     38 fi