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

send-to-tmux (941B)


      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 # fetch tmux session
      6 if [ -f "./.helixterm_session" ]; then
      7   TMUX_SESSION=$(cat "./.helixterm_session")
      8 else
      9   echo "There is no open session!"
     10   exit 1;
     11 fi
     12 
     13 # read piped input
     14 readarray -t lines
     15 
     16 # enter input into tmux line-by-line
     17 for line in "${lines[@]}"; do
     18   # Workaround:
     19   # if the piped line ONLY contains the string "Enter", send it to tmux
     20   # character-by-character. Otherwise, send the entire line as a whole.
     21   if [ "$line" != "Enter" ]; then
     22     tmux send-keys -t "$TMUX_SESSION" "$line" "Enter"
     23   else 
     24     tmux send-keys -t "$TMUX_SESSION" "E"
     25     tmux send-keys -t "$TMUX_SESSION" "n"
     26     tmux send-keys -t "$TMUX_SESSION" "t"
     27     tmux send-keys -t "$TMUX_SESSION" "e"
     28     tmux send-keys -t "$TMUX_SESSION" "r"
     29     tmux send-keys -t "$TMUX_SESSION" "Enter"
     30   fi
     31 done
     32 
     33 # EOF send-to-tmux