exupero's blog

quick script for Vim and Tmux

A friend of mine created a simple live editor for shell scripts using entr. Below is my take on his original, which launched VS Code to edit the script and showed results in the terminal whenever the script file was saved. My version edits in (Neo)Vim and shows results in a new Tmux split:



# Sleep in the background to give the commands below time to create the file
# and make it executable.
  sleep 0.5
  tmux split-window -h \; \
     send -t .1 "echo $script | entr -c $script" C-m \; \
     select-pane -t .0
) &

printf '#!/bin/bash\n\n\n' > $script
chmod +x $script
nvim +'set ft=sh' +3 $script

tmux kill-pane -t .1

Note that this script will do unexpected things if you use it from a Tmux window with multiple panes, as it assumes the new pane will always be the second pane.

Joe called his script quick.

Here's a similar script that replaces entr with a Babashka nREPL.