Skip to content

Instantly share code, notes, and snippets.

@vrinek
Created February 2, 2022 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrinek/dc401714ad8e8212d49b13bce422432a to your computer and use it in GitHub Desktop.
Save vrinek/dc401714ad8e8212d49b13bce422432a to your computer and use it in GitHub Desktop.
Fish function to run multiple commands in parallel
argparse "n/name=" "c/commands=+" -- $argv
or return
set n (count $_flag_commands)
tmux has-session -t "$_flag_name"
if test "$status" -eq "0"
echo "tmux session already exists for $_flag_name, maybe still running?"
echo "Try `tmux new -As $_flag_name` to attach to it."
return 1
end
tmux new-session -ds "$_flag_name" -x $COLUMNS -y $LINES
# Split the first pane into many
for i in (seq 2 $n)
tmux split-window -t "$_flag_name"
end
# Even out tiles horizontally and vertically
tmux select-layout -t "$_flag_name":0.0 tiled
for i in (seq $n)
set pane (math $i-1)
tmux send-keys -t "$_flag_name":0."$pane" "fish -c \"$_flag_commands[$i] && exit\" && exit" Enter
end
tmux attach-session -t "$_flag_name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment