commit 6b1f70b2a66cc12ad64aaa29b8c41911a8a428d7
parent d3de19294e5f9de905b3b1b0c981bedd7032fe69
Author: Jeff <dev@watertao.xyz>
Date: Mon, 2 Mar 2026 21:22:37 -0800
Better PID/PPID handling
Ok, terminals are closing when they ought to now. Using a busybox/gnu
compatible ps and kill call to clean things up.
Diffstat:
2 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/tao_url.sh b/tao_url.sh
@@ -8,7 +8,11 @@ export PROGDIR="$(cd -- "$(dirname -- "$0")" && pwd)"
dn=/dev/null
cmdf(){ command -v $1 >$dn 2>&1; }
-cu(){ e="${1:-0}"; rm "$t" 2>$dn 1>&2; exit "$e"; }
+cu(){
+ e="${1:-0}"; rm "$t" 2>$dn 1>&2;
+ kill -1 $(ps -oppid,pid | sed -n "s/^[ ]*$$ //p") 2>$dn
+ exit "$e";
+}
trap cu INT
# dmenu command
@@ -151,12 +155,7 @@ file_action()
then
# A serarate shell runs async so we aren't
# held up by the yt-dlp process.
- if [ -z "$FETCHING_LATEST" ]
- then
- "$trm" -t "$p" -- tao_url.sh -y "$u" 1>$dn 2>&1
- else
- "$trm" -t "$p" -- tao_url.sh -y "$u" 1>$dn 2>&1 &
- fi
+ nohup "$trm" -t "$p" -- tao_url.sh -y "$u" 1>$dn 2>&1 &
cu
fi
@@ -176,8 +175,13 @@ file_action()
prnt "$t" | grep -q "DL" && dl_then_view
# open term if needed
+ # A kill line is in there as this whole thing crashes
+ # on INT ^C during mpv stream. This hopefully kills
+ # the mpv terminal. q out of mpv, no problems.
if prnt "$t" | grep -q "TERM" && [ $noterm -ne 1 ]; then
- "$trm" -- $p "$u"; cu;
+ "$trm" -- $p "$u" 1>$dn 2>&1 || \
+ kill $(ps -oppid,pid | sed -n "s/^[ ]*$$ //p") 2>$dn
+ cu
fi
# for all else just run it
@@ -264,8 +268,9 @@ ytdlp_mpv()
yt-dlp --no-warnings \
-f 'bestvideo[ext=mp4][height<=720]+bestaudio[ext=m4a]/best[height<=720]' \
- -o ${t}/'%(title)s-%(id)s.%(ext)s' "$u" && \
- $TAO_MP -- "$t"/*
+ -o ${t}/'%(title)s-%(id)s.%(ext)s' "$u" 2>$dn
+
+ $TAO_MP -- "$t"/*
read -p "Remove tmp a/v file?" yn
[ "$yn" = "n" ] && "$trm" -d "$t" || rm -r "$t"
diff --git a/tao_youtube_query.sh b/tao_youtube_query.sh
@@ -61,9 +61,7 @@ dmo="$DMENU_OPTS"
cu(){
rm -fr "$t" 2>$dn 1>&2
- if [ "$usepts" = "1" ]; then
- [ -n "$ttypid" ] && kill -9 "$ttypid" 2>$dn 1>&2
- fi
+ kill -9 $(ps -oppid,pid | sed -n "s/^[ ]*$$ //p") 2>$dn
exit 0
}
trap cu INT
@@ -110,13 +108,11 @@ pts_open()
"$TERMINAL" -t "$pts_title $q" -- tail - 2>$dn &
a="$!"
sleep 1
- b=$(ps -e -opid,tty | sed -n "/^ *$a /{
+ ttyno=$(ps -e -opid,tty | sed -n "/^ *$a /{
:st n; /\?$/{b st}
- s/^ *\(.*\)$/\1/p; q}" | \
+ s/.*\([0-9]\+\)$/\1/p; q}" | \
tr -d "\n")
- ttypid="${b%% *}"
- ttyno=$(printf "%s" "$b" | sed -n "s/.*\([0-9]\+$\)$/\1/p")
prnt_tty="--print-to-file playlist:%(title)s /dev/pts/$ttyno"
fi
}
@@ -128,7 +124,7 @@ runthething()
"$dm" -i $dmo -p "[ Latest videos ]" 2>$dn)
else
u=$(<$t "$dm" -i $dmo -p "[ $yt_dm_title > $q ]")
- fi
+ fi || return 1
[ -z "$u" ] && return 1