Evaluer ses scripts en temps réel (dangereux ⚠️) - retour accueil
git clone git://bebou.netlib.re/liverepl
Log | Files | Refs | README |
pipeline (1666B)
1 #! /bin/sh 2 3 while getopts "c:t:n:" opt;do 4 eval "$opt='$OPTARG'" 5 done 6 7 create() { 8 title="$1" 9 nb="${2:-3}" 10 tmpd="/tmp/$title" 11 mkdir -p "$tmpd" 12 tmux new-session -d -s "$title" "./liverepl -o $tmpd/1 -s $tmpd/1-cmd" 13 tmux send-keys -t "$title" "seq 10" 14 for i in $(seq 2 $nb);do 15 tmux split-window -t "$title" -h "./liverepl -f -i $tmpd/$(($i-1)) -o $tmpd/$i -s $tmpd/$i-cmd" 16 done 17 tmux select-pane -t "$title":0.0 18 tmux select-layout -t "$title" even-horizontal 19 tmux attach -t "$title" 20 } 21 22 pipelineexists() { 23 title="$1" 24 tmux ls | cut -d':' -f1 | grep -qE "^$title$" && [ -d "/tmp/$title" ] 25 } 26 27 join() { 28 title="$1" 29 pipelineexists "$title" && tmux attach -t "$title" || create "$title" ${n:-3} 30 } 31 32 printp() { 33 title="$1" 34 pipelineexists "$title" || { echo "pipeline doesn't exist"; exit 1; } 35 find /tmp/$title/ -name '*-cmd' | 36 sort | 37 xargs cat | 38 paste -s -d'|' | 39 sed 's/|/ | \n/g' 40 } 41 42 execute() { 43 title="$1" 44 pipelineexists "$title" || { echo "pipeline doesn't exist"; exit 1; } 45 printp "$title" | sh 46 } 47 48 makescript() { 49 title="$1" 50 pipelineexists "$title" || { echo "pipeline doesn't exist"; exit 1; } 51 [ -e "$title" ] \ 52 && { echo "File already exists, won't overwrite" 1>&2; exit 1; } \ 53 || { printp "$title" > $title; } 54 chmod +x $title 55 } 56 57 58 delete() { 59 title="$1" 60 tmux kill-session -t "$title" 61 rm -rf /tmp/$title 62 } 63 64 [ -z "$t" ] && { echo "Missing pipeline title, give it with -t flag"; exit 1; } 65 66 case "${c:-join}" in 67 (create) create $t $n;; 68 (join) join $t ;; 69 (print) printp $t ;; 70 (exec*) execute $t ;; 71 (make) makescript $t ;; 72 (del*) delete $t ;; 73 (*) echo "command doesn't exist";; 74 esac 75