Evaluer ses scripts en temps réel (dangereux ⚠️) - retour accueil
git clone git://bebou.netlib.re/liverepl
Log | Files | Refs | README |
commit 745aa24fd44447c2f2f1251835407133e338dff3 parent f1a317b4965461fbfc08ece6c7ba6a7c9882afc0 Auterice: Arthur Pons <arthur.pons@unistra.fr> Date: Wed, 28 Aug 2024 23:12:38 +0200 Création de sous commandes de pipeline Et factorisation avec Y'a create : créer la session tmux print : affiche le pipeline formaté exécute : exec le pipeline make : créer un script du pipeline dans le dossier courant Diffstat:
M | pipeline | | | 57 | +++++++++++++++++++++++++++++++++++++++++++++------------ |
1 file changed, 45 insertions(+), 12 deletions(-)
diff --git a/pipeline b/pipeline @@ -1,18 +1,51 @@ #! /bin/sh -while getopts "t:n:" opt;do +while getopts "c:t:n:" opt;do eval "$opt='$OPTARG'" done -nb="${n:-1}" -tmpd=$(mktemp -d) -tmux new-session -d -s "$t" "./liverepl -o $tmpd/1" -tmux send-keys -t "$t" "seq 10" -for i in $(seq 2 $nb);do - tmux split-window -t "$t" -h "./liverepl -f -i $tmpd/$(($i-1)) -o $tmpd/$i" -done -tmux select-pane -t "$t":0.0 -tmux select-layout -t "$t" even-horizontal -# Attach to session -tmux attach -t "$t" +create() { + nb="${1:-1}" + title="$2" + tmpd="/tmp/$title" + mkdir "$tmpd" + tmux new-session -d -s "$title" "./liverepl -o $tmpd/1 -s $tmpd/1-cmd" + tmux send-keys -t "$title" "seq 10" + for i in $(seq 2 $nb);do + tmux split-window -t "$title" -h "./liverepl -f -i $tmpd/$(($i-1)) -o $tmpd/$i -s $tmpd/$i-cmd" + done + tmux select-pane -t "$title":0.0 + tmux select-layout -t "$title" even-horizontal + tmux attach -t "$title" +} + +printp() { + title="$1" + find /tmp/$title/ -name '*-cmd' | + sort | + xargs cat | + paste -s -d'|' | + sed 's/|/ | \n/g' +} + +execute() { + title="$1" + printp "$title" | sh +} + +makescript() { + title="$1" + [ -e "$title" ] \ + && { echo "File already exists, won't overwrite" 1>&2; exit 1; } \ + || { printp "$title" > $title; } + chmod +x $title +} + +case "$c" in + (create) create $n $t;; + (print) printp $t ;; + (exec) execute $t ;; + (make) makescript $t ;; +esac +