From 98de67a6cda1173faaf8ec8afe5041ba8c62096f Mon Sep 17 00:00:00 2001 From: Q Date: Sun, 27 Oct 2024 09:04:51 +0200 Subject: [PATCH] even more stuff to tsp-menu --- shell/tsp-menu | 84 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/shell/tsp-menu b/shell/tsp-menu index 6db8097..302dd66 100755 --- a/shell/tsp-menu +++ b/shell/tsp-menu @@ -14,6 +14,10 @@ function fkey_colorize() { echo } +function _title() { + echo -e "${_U}${_S}======= $@ =======${_Z}" +} + function get_id() { tsp -l echo -e "${_Y}" @@ -36,23 +40,85 @@ function shuffle_jobs() { done } + +function _del_logs() { + shopt -s nullglob + if [[ -z $( ls -1 /tmp/ | grep ^ts-out\. ) ]]; then + return + fi + ls -1 -l /tmp/ts-out.* + read -p"sure to delete logs? y/n " -n1 deletelogs + echo + if [[ "$deletelogs" = y ]]; then + find /tmp -mindepth 1 -maxdepth 1 -name 'ts-out.*' -delete -print + fi + +} + +function _kill_all() { + tsp -l + read -p"sure to kill all jobs (and daemon)? y/n " -n1 killtsp + echo + if [[ "$killtsp" = y ]]; then + tsp -K + fi +} + +function _status() { + _title Status + echo -n "Parallel jobs (-S): " + tsp -S + echo -n "Running jobs: " + tsp -l | tail -n +2 | awk '{print $2}' | grep -c running + echo -n "Queued jobs: " + tsp -l | tail -n +2 | awk '{print $2}' | grep -c queued + echo -n "Finished jobs in success: " + tsp -l | tail -n +2 | awk '{print $2 $4}' | grep -c finished0 + echo -n "Finished jobs with error: " + tsp -l | tail -n +2 | awk '{print $2 $4}' | grep finished | grep -v -c finished0 + read -p "OK " foo +} +function _create_tsp_jobs() { + for i in {1..5}; do + tsp sleep 0.1 + done + for i in {1..5}; do + tsp sleep 10 + done + for i in {1..5}; do + tsp sleep 180 + done +} + + while true; do + _title "TSP" echo '$ 'tsp $cmd $id - eval tsp $cmd $id + if [[ "$cmd" = "-c" ]]; then + eval tsp $cmd $id | less -R +G + else + eval tsp $cmd $id + fi id="" cmd="" echo - fkey_colorize list console info remove kill Clear Slots shuffle Killall quit + fkey_colorize list console info remove kill Clear Slots shuffle DelLogs Killall @status quit read -p"tsp " -n1 menu + if [[ "$menu" = "" ]]; then + read -t 0.1 -n1 special + if [[ -n "$special" ]]; then menu=l; fi + fi echo case "$menu" in - q) break;; + q|) break;; l) cmd=-l;; - c|i|r|k) cmd=-"$menu"; get_id; ;; - C) id=""; cmd=-C; ;; - S) cmd=""; echo Current:; tsp -S; read -p "new? " -i 1 -e num; tsp -S $num; ;; - K) read -p "sure? ctrl-c " foo; id=""; cmd=-K; ;; - s) shuffle_jobs; ;; - *) break;; + c|i|r|k) cmd=-"$menu"; _title "Which ID?"; get_id; ;; + C) cmd=-C; ;; + S) cmd=""; _title Current:; tsp -S; read -p "new? " -i 1 -e num; tsp -S $num; ;; + K) _kill_all ;; + D) _del_logs ;; + s) shuffle_jobs ;; + @) _status ;; + *) cmd=-l;; esac done