commit 6bd89bfe578f3f4b602cecdff40b39e950513c92
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Sat, 18 May 2024 15:38:01 +0200
initial version
Diffstat:
5 files changed, 123 insertions(+), 0 deletions(-)
diff --git a/README b/README
@@ -0,0 +1,42 @@
+helix-term
+==========
+
+Please send patches or remarks to <jayvii[AT]posteo[DOT]de>
+
+Interactive console for the Helix editor (https://helix-editor.com/) using the
+terminal multiplexer TMUX (https://github.com/tmux/tmux/wiki).
+
+This script is primarily written for working with R (https://www.r-project.org/)
+but should work with any other script language and REPL.
+
+Installation
+------------
+
+The scripts in "bin/" are intended to go into your "~/.local/bin/" folder, or
+any other directory within your "$PATH".
+
+The snippets in "helix_config.toml" belong into your helix configuration
+(typically located in "~/.config/helix/config.toml").
+
+You need "tmux" to be installed on your system. An example configuration is
+provided in "tmux.conf", which you can copy to "~/.tmux.conf"
+
+Usage
+-----
+
+Working on some script in helix, execute the "helix-term" command in another
+terminal window or by splitting the terminal window helix is running in
+(ctrl+h or ctrl+v). For example, if you want to run the R-REPL, issue
+following command:
+
+ helix-term R
+
+This creates a temporary file in the current working directory
+"./.helix_session" containing the current session's ID (base64 encoded path).
+Any helix session opened with the same root path is bound to that helix-term
+session. Upon exiting the REPL, the session file is removed.
+
+From helix, you can now send commands to the REPL via Ctrl+C, Ctrl+C. In normal
+mode, this send the current code paragraph the pointer is located within. If in
+insert mode, the shortcut enters normal mode and goes on from there. If in
+selection mode, the current selection is send to the REPL.
diff --git a/bin/helix-term b/bin/helix-term
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+
+# unset TMUX variable to enforce launch
+TMUX=""
+
+# generate tmux-session name
+TMUX_SESSION=$(echo "$PWD/" | base64)
+
+# set session ID for current working directory
+if [ ! -f "./.helixterm_session" ]; then
+ echo "$TMUX_SESSION" > "./.helixterm_session"
+else
+ echo "There already exists a session in $PWD!"
+ exit 1;
+fi
+
+# Grab command
+if [[ -z "$1" ]]; then
+ CMD="$SHELL"
+else
+ CMD="$1"
+fi
+
+# Create new tmux session
+tmux -2 new-session -s "$TMUX_SESSION" "$CMD"
+
+# Remove session ID
+rm "./.helixterm_session"
diff --git a/bin/send-to-tmux b/bin/send-to-tmux
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+
+# fetch tmux session
+TMUX_SESSION=$(cat "./.helixterm_session")
+
+# read piped input
+readarray -t lines
+
+# enter input into tmux line-by-line
+for line in "${lines[@]}"; do
+ tmux send-keys -t "$TMUX_SESSION" "$line" "Enter"
+done
+
+# EOF send-to-tmux
diff --git a/helix_config.toml b/helix_config.toml
@@ -0,0 +1,10 @@
+
+[keys.normal]
+C-c = { C-c = ["goto_prev_paragraph", "collapse_selection", "goto_next_paragraph", ":pipe-to ~/.local/bin/send-to-tmux", "collapse_selection"] }
+
+[keys.insert]
+C-c = { C-c = ["normal_mode", "goto_prev_paragraph", "collapse_selection", "goto_next_paragraph", ":pipe-to ~/.local/bin/send-to-tmux", "collapse_selection"] }
+
+[keys.select]
+C-c = { C-c = [":pipe-to ~/.local/bin/send-to-tmux"] }
+
diff --git a/tmux.conf b/tmux.conf
@@ -0,0 +1,29 @@
+# Options to enable mouse support in Tmux
+#set -g terminal-overrides 'xterm*:smcup@:rmcup@'
+# For Tmux >= 2.1
+set -g mouse on
+
+# Escape time for libtermkey
+# (see https://github.com/neovim/neovim/issues/2035):
+set -sg escape-time 0
+
+# Set history limits
+set -g history-limit 2000
+
+# split-controls (shift+arrow)
+bind -n C-left select-pane -L
+bind -n C-down select-pane -D
+bind -n C-up select-pane -U
+bind -n C-right select-pane -R
+bind -n C-h split-window -v -c '#{pane_current_path}'
+bind -n C-v split-window -h -c '#{pane_current_path}'
+
+# Color-support
+#set -g default-terminal "screen-256color"
+set -g default-terminal "xterm-256color"
+set-option -sa terminal-overrides ",xterm*:Tc"
+
+# Do not show any TMUX UI
+set -g status off
+
+