Shell scripts minimizing machine time, maximizing tao time.

git clone git://watertao.xyz/programs/tao_shells.git

commit 2a8b92dff677cbd5e28907461c307bd955ec89c1
parent cff6e94aaca8443b5d621bd43db6739446f458b1
Author: Jeff <dev@watertao.xyz>
Date:   Sat, 28 Feb 2026 12:19:46 -0800

Tags for openers, readme, various fixes

tao_url.sh

Converted an env var system into tag system for opener cmds. If a
command required a terminal for example, the tag "TERM" is added to the
command. Much easier to manage and configure.

Added the tag, MEDIA_PLAYER, for the openers to determine the default
media player for yt/mpv task.

Added the tag DL in addition to the DL_OPT tag so that if a command or
program will always need to download url first (ie image), the DL tag
makes that happen. DL_OPT still exists for optional download first
situations (ie mpv).

Fixed some error msgs for rm and tac calls.

tao_youtube_query.sh

Added another check on exiting to remove the pts that monitors yt-dlp.

The tty/pts issue occured when a channel's playlist was loaded into
dmenu, and if ESC out of dmenu instead of selection, sometimes the
pts would not close and hangs. Manual kill is required to close it in
this case. The problem occured when the dmenu screen was left unattended
for some time. A couple of edits to the tao_youtube_query.sh seem to
have corrected the problem. Although I'm uncertain. Will keep an eye on
it.

README

Lots of additions here, importantly an installation section and
tao_openers.conf section.

Diffstat:
MREADME | 217+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Mtao_url.sh | 84+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
Mtao_youtube_query.sh | 17+++++++++++------
3 files changed, 226 insertions(+), 92 deletions(-)

diff --git a/README b/README @@ -17,16 +17,31 @@ Usage $ tao_youtube_query.sh # Youtube videos from listed channels -Requirements +Base Requirements ------------ - your-favorite-terminal-emulator -- your-favorite-terminal-text-editor -- your-favorite-cli-browser -- your-favorite-gui-browser +- your-favorite-text-editor - dmenu (or bemenu/rofi) -- mpv +- wget + + +Youtube Requirements +-------------------- - yt-dlp +- mediaplayer + + +Turn Key Out of the Box Requirements / Default Opener Options +--------------------------------------------------------------- +- st +- dmenu - wget +- mpv +- yt-dlp +- Gui browsers (qutebrowser, firefox, surf) +- Tui browsers (w3m, links) +- nsxiv (images) +- zathura (pdfs) Description @@ -40,44 +55,81 @@ get started, using a terminal text editor (e.g. vim) is a great way to get your hands dirty. You'll be searching for files cli style and editing them all in the terminal. Maybe start a journal this way. -The tao_url.sh is a core utility that has undergone maybe 6 rewrites. I learn -something new and then all of a sudden, everything needs to be rewritten. And I -do enjoy the process. It is a hobby of mine. And I feel these scripts are in a -good enough place to be shared. So here we are. Welcome the tao shells. +The tao_url.sh is a core utility that has undergone maybe 6 rewrites. I +learn something new and then all of a sudden, everything needs to be +rewritten. And I do enjoy the process. It is a hobby of mine. And I feel +these scripts are in a good enough place to be shared. So here we are. +Welcome the tao shells. + +The purpose of these programs, particularly tao_url, is to minimize +distraction in our lives. The internet is a massive distraction +downpour. The tao_url.sh is not an umbrella, it removes you from the +storm and keeps you above it, as much as it can. The idea is to pull +things out of the storm, into your the light of your home, for +intentional purposes. tao_url.sh is there to help users take control and +hone their relationship with the internet. So how does it work. The +primary interface is suckless.org's wonderful dmenu. If you are an X11 +user, please install dmenu ( See dmenu below ). If you are running a +Wayland environment, you'll want to install bemenu. Rofi will also work. +But one of the three are required to use the tao shells. How each tao +shell program works is outlined below. + + +Install +------- +Clone the git repo. +cd into tao_shells directory. +cp the files into your user's local bin. The following should do it: + + a=~/.local/bin/; for i in *.sh; do cp $i $a$i; chmod a+x $a$i; done + +Check that ~/.local/bin is in your PATH env. If you already are setup +with a user local executable path, just be sure to install the shells +respectively. + +Also, see TERMINAL in the tao_url.conf and env vars section below. -The purpose of these programs, particularly tao_url, is to minimize distraction -in our lives. The internet is a massive distraction downpour. The tao_url.sh is -not an umbrella, it removes you from the storm and keeps you above it, as much -as it can. The idea is to pull things out of the storm, into your the light of -your home, for intentional purposes. tao_url.sh is there to help users take -control and hone their relationship with the internet. So how does it work. The -primary interface is suckless.org's wonderful dmenu. If you are an X11 user, -please install dmenu ( See dmenu below ). If you are running a Wayland -environment, you'll want to install bemenu. Rofi will also work. But one of -the three are required to use the tao shells. How each tao shell program works -is outlined below. +Based on the requirements that suit your need, install any programs +and/or configure the tao_opener.conf file accordingly. See +tao_opener.conf section below. + +### Rofi +If using rofi, you'll definitely need to set some flags for rofi to work +well. After your initial run of tao_url.sh which will have created the +tao config directory, the following command should do the trick: + +Likely most window tiling manager environments: + + printf "%s\n" "-dmenu" > ~/.config/tao/tao_dmenu.conf + +Deeply GUI environments (ie Ubuntu Gnome): + + printf "%s\n" "-dmenu -normal-window" > ~/.config/tao/tao_dmenu.conf Environment Variables --------------------- A word regarding env vars first. Although not required, you may set the following to the programs you run on your local system: + - TERMINAL - DMENU - EDITOR For the unlettered, please refer to your shell's man page for further -reading on environment variables. These can also be set in tao_url.conf -(See Files below). +reading on environment variables. + +If unset, tao shells will try to discover each for the following programs: -tao shells will try to discover each for the following programs: - TERMINAL=st,urxvt,xterm - DMENU=dmenu,rofi,bemenu +The tao shells do no work whatsoever in the search for an EDITOR. This +invaluable antique is entirely on you and absolutely a necessity. + tao_url.sh ---------- - There is a lot going on here with such a simple utility, so get a cup coffee or tea or water, get your cozy's on, and let's get into it. @@ -87,6 +139,7 @@ First, the flow of what happens when this program runs. ### Url mode: 01 + You are prompted to enter a url. The dmenu list will be populated with history and bookmarks below the prompt. As you type, the fuzzy find reduces the list accordingly. You can quickly find history urls and @@ -94,6 +147,7 @@ bookmarks this way, or simply enter a fresh url to do something with. And because dmenu is amazing, it's fast. 02 + After url selection, you are prompted with a list of programs. How will you be opening or using this url? Web browsers of course are a natural method. Defaults are qutebrowser, firefox, w3m, and links (See Text @@ -106,6 +160,7 @@ you'd like to download the file first. In most case, unless it's a/v, downloading first is and excellent idea. More on that later. 03 + If you're opening the url with a browser, you'll be off and running. If downloading first, you'll see a terminal open running wget to download the file, then once completed, the respective opener will launch and @@ -113,16 +168,17 @@ you'll be greeted with the content requested. ### Query mode: - You are afforded the same steps as above, with a few important differences. 01 + You are prompted initally for query/search terms instead of a url address. The history of your searches will be at your disposal as you type. 02 + Once your query is ready, you can select any browser to open it, and the default duckduckgo will provide the results. If it is a youtube video, you can ytdlp/mpv option is there to download first, then mpv play the @@ -130,12 +186,10 @@ video locally. ### Youtube: - See Youtube Videos below. ### Local mode: - I'd avoid using this for now. It's well overdue for some tuning. I never use it anymore, I don't recommend it, and as such may be removed entirely in the unforseeable future. @@ -186,7 +240,6 @@ tao_youtube_query.sh. ### Download and view: - Running 'tao_url.sh -r', type or paste the youtube video link, hit Enter, then you are prompted as usual with a list of opener options. Select 'yt/mpv' to download first, then play locally using mpv. @@ -195,53 +248,46 @@ Select 'yt/mpv' to download first, then play locally using mpv. ### Streaming video: - -Same process as 'Download and view' above, except instead of -'yt/mpv', simply open with 'mpv' instead. You'll be prompted to -'Download first?', whereupon you'll answer no, and mpv will begin -streaming the video. +Same process as 'Download and view' above, except instead of 'yt/mpv', +simply open with 'mpv' instead. You'll be prompted to 'Download first?', +whereupon you'll answer no, and mpv will begin streaming the video. tao_url.sh -r; [enter link]; mpv; n; ### Search: - -tao_url.sh -q as usual for internet searching, including youtube. -After entering/selecting keywords to search, in the opener prompt, -select 'yt search'. You are then presented with a list of youtube -videos. Once a video is selected, you'll be prompted with opener -options, 'yt/mpv' to download then view, or 'mpv' for streaming. +tao_url.sh -q as usual for internet searching, including youtube. After +entering/selecting keywords to search, in the opener prompt, select 'yt +search'. You are then presented with a list of youtube videos. Once a +video is selected, you'll be prompted with opener options, 'yt/mpv' to +download then view, or 'mpv' for streaming. tao_url.sh -q; [enter search words]; yt search; ### Channel videos: - -Same process as above for download/view/streaming, except for the -url, you enter a youtube channel's url, then select either of the -two 'yt channel...' options. The first limits the video list to 50 -for speed of service purposes. The other gets fetches everything, -takes a little longer, but worth it if you're digging into history. +Same process as above for download/view/streaming, except for the url, +you enter a youtube channel's url, then select either of the two 'yt +channel...' options. The first limits the video list to 50 for speed of +service purposes. The other gets fetches everything, takes a little +longer, but worth it if you're digging into history. tao_url.sh -r; [enter yt channel address]; yt channel; [select video]; ... ### Fetching latest videos from a list of channels: - With a populated tao_channel_fetch_latest.sites config file, running -tao_youtube_query.sh fetches a list of latest videos from every -listed channel, sorts in date order, and offers this list for your -perusal and selection, dmenu style. As many videos as you like can -be launched using yt/mpv opener option, as each video will download -in its own terminal window and play automatically once respective -download completes. A nice way to catch up very quickly with -channels of interest. +tao_youtube_query.sh fetches a list of latest videos from every listed +channel, sorts in date order, and offers this list for your perusal and +selection, dmenu style. As many videos as you like can be launched using +yt/mpv opener option, as each video will download in its own terminal +window and play automatically once respective download completes. A nice +way to catch up very quickly with channels of interest. tao_youtube_query.sh; ### Recommended keybinds for your window manager: - tao_url.sh -r tao_url.sh -q tao_youtube_query.sh @@ -269,6 +315,49 @@ tao_url.conf optional variables: ``` +tao_url.conf +------------ +### TAO_QUERY_ENG +Set the query url for search engine in tao_url.conf. Default: + + TAO_QUERY_ENG="https://ddg.gg?q=" + + +tao_opener.conf +--------------- +Upon initial use of tao_url.sh, ~/.config/tao/tao_opener.conf is auto +generated if not already exists. It contains a default opener/program +list, the tao_url.sh task menu for urls. See Turn-key Out of the Box +Requirements for the default list. The format for program entries is as +follows: + +menu name (optional) %% program :: tags (optional) + +Examples: + + w3m :: TERM + firefox + mpv %% mpv --msg-level=ffmpeg/video=error :: DL_OPT MEDIA_PLAYER TERM + nsxiv :: DL + +### Opener Tags + +- DL: wget downloads url first, then program selected opens it. +- DL_OPT: Same as DL, but offered as an interactive option. This is + useful with mpv for example, where you can opt to not download and + just run the url with mpv, whereupon the video is streamed. Or you + can choose to download first then play locally. Each has their + advantages. +- MEDIA_PLAYER: Sets the program as the yt/mpv media player where the + entire program call including options and flags is used to run the + downloaded youtube video. Only one program is used with this tag, if + multiple programs are tagged with this, the first in the list is + used. If the tag isn't used, the default player is mpv. +- TERM: Launch the program in a terminal. Text browsers such as w3m are + fine candidates of this tag. If you wish to monitor the stdout/err + msgs from any program, this tag is useful. + + Ethos: Computers and our Relationship with the Internet ------------------------------------------------------- What's the point of all of this? I happen to be a shell scripting @@ -339,3 +428,23 @@ a handful of utilities for the unix/linux user. There exist other tao shells for a myriad of other tasks, and when the time comes that they find comfort within themselves, they will walk out the front door as these shells have done and join the world of open source. + + +TECHNICAL NOTES +--------------- +### tao_opener.conf - yt/mpv menu name customization + +Although a yt/mpv name can be customized for the menu, the command +cannot be changed. And tags do not apply and if added, will break the +command: + +Acceptable: + + yt/mpv + yt custom menu name %% yt/mpv + +Unacceptable: + + yt/mpv :: tags that should not be here + yt custom menu name %% yt-wrong-name-for-yt/mpv-command + yt custom menu name %% yt/mpv :: tags that should not be here diff --git a/tao_url.sh b/tao_url.sh @@ -3,14 +3,14 @@ # A core component of the url tao shells. # See README -cu(){ e="${1:-0}"; rm "$t"; exit "$e"; } -trap cu INT - 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"; } +trap cu INT + # dmenu command if [ -z "$DMENU" ] then @@ -40,8 +40,6 @@ a="$HOME/.config/tao/tao_url.conf" && [ -f "$a" ] && . "$a" ofile="$HOME/.config/tao/tao_openers.conf" TAO_QUERY_ENG="${TAO_QUERY_ENG:-"https://ddg.gg?q="}" TAO_LOCAL_DIRS="${TAO_LOCAL_DIRS:-"$(printf "%s\n" "$HOME")"}" -TAO_EXEC_IN_TERM="${TAO_EXEC_IN_TERM:-"w3m links mpv"}" -TAO_DL_THEN_OPEN="${TAO_DL_THEN_OPEN:-"nsxiv mpv zathura"}" # File types: Local(1)(default) Remote(2) Query(3) ft=2 @@ -56,18 +54,18 @@ mk_ofile() { cat <<EOF >"$ofile" qutebrowser -w3m +w3m :: TERM firefox -links +links :: TERM surf ytdlp/mpv -tao_youtube_query.sh -c%%yt channel (50) -tao_youtube_query.sh -c -a%%yt channel (all) -tao_youtube_query.sh -q%%yt search -tao_copy.sh%%yank -mpv --msg-level=all=status,ffmpeg/video=error%%mpv -zathura -nsxiv +yt channel (50) %% tao_youtube_query.sh -c +yt channel (all) %% tao_youtube_query.sh -c -a +yt search %% tao_youtube_query.sh -q +yank %% tao_copy.sh +mpv %% mpv --msg-level=all=status,ffmpeg/video=error :: DL_OPT MEDIA_PLAYER TERM +zathura :: DL +nsxiv :: DL bookmark EOF } @@ -89,7 +87,9 @@ prnt(){ printf "%s\n" "$1"; } dl_then_view() { - dmenu_yn "[ Download then view? ]" && return 0 + if prnt "$t" | grep -q "DL_OPT"; then + dmenu_yn "[ Download then view? ]" && return 0 + fi x="$(mktemp -d)"; [ ! -d "$x" ] && cu "$trm" -- wget --user-agent=Firefox "$u" -P "$x" @@ -128,15 +128,22 @@ file_action() if [ $ft -ne 1 ] then - p=$(<$ofile sed 's/.*\%\%//' | "$dm" $dmo -p "[ $u ]") + p=$(<$ofile sed 's/[ ]\?\%\%.*$//; t; s/[ ]\?::.*$//' | "$dm" $dmo -p "[ $u ]") [ -z "$p" ] && cu - # From ofile, translate opener name to command (if different) + # Sanitize $p for sed matching p=$(prnt "$p" | sed 's/\([\/\#%]\)/\\\1/g') - p=$(<$ofile sed -n "/^$p$/{b a;}; /\%\%$p$/{b a;}; T; :a s/\%\%.*$//; p; q;") + # From ofile, translate opener name to command (if different) (with tags included) + p=$(<$ofile sed -n "/^$p\([ ]\?::.*\)\?$/{b a;} + s/^$p[ ]\?%%//; T + :a s/^[ ]//; s/[ ]*::/::/ + p; q") + + # Get tags + t=$(prnt "$p" | sed -n 's/.*:://p') + p="${p%%::*}" - prnt "$p" # yt-dlp, special if [ "$p" = "ytdlp/mpv" ] then @@ -151,25 +158,26 @@ file_action() cu fi - # download-then-views first - prnt "$TAO_DL_THEN_OPEN" | grep -q "${p%% *}" && dl_then_view - [ "$p" != "tao_youtube_query.sh -q" ] && query_stage + # download-then-views first + prnt "$t" | grep -q "DL" && dl_then_view + # open term if needed - prnt "$TAO_EXEC_IN_TERM" | grep -q "${p%% *}" && [ $noterm -ne 1 ] && \ - "$trm" -- $p "$u" && cu + if prnt "$t" | grep -q "TERM" && [ $noterm -ne 1 ]; then + "$trm" -- $p "$u"; cu; + fi # for all else just run it $p "$u" && cu else case "$(prnt "$(file --mime-type -b "$u")" | tr "[:upper:]" "[:lower:]")" in - *webp|*jpeg|*jpg|*png|*gif|*svg ) p="$imager" ;; - *mp4|*m4a|*avi|*mpg|*ogg|*mp3|*flac|*flv|*matroska ) p="$trm -- $mpv" ;; + *webp|*jpeg|*jpg|*png|*gif|*svg ) p="nsxiv" ;; + *mp4|*m4a|*avi|*mpg|*ogg|*mp3|*flac|*flv|*matroska ) p="$trm -- mpv" ;; *txt|*md|*text ) p="$trm -- $EDITOR" ;; - *pdf ) p="$pdf" ;; - * ) p="$sbrowser" ;; + *pdf ) p="zathura" ;; + * ) p="w3m" ;; esac $p "$u" 2>$dn & @@ -200,7 +208,7 @@ input_remote() { # Dmenu for url to task u="$(<"$bfile" sed 's/$/ bookmark/' | \ - tac "$hfile" "$w3mh" - | \ + tac "$hfile" "$w3mh" - 2>$dn | \ sed '/^file:/d' | \ "$dm" $dmo -p "[ url ]")" \ || cu @@ -227,15 +235,27 @@ query_stage() tr " " "%")" } +tao_mp_set() +{ + [ -z "$TAO_MP" ] && \ + TAO_MP=$(<$ofile sed -n ' + /::.*MEDIA_PLAYER/ { + s/.*%%[ ]\?// + s/[ ]\?::.*$// + p; q; + }; $c mpv') +} ytdlp_mpv() { + tao_mp_set + t=$(mktemp -d) - + 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" && \ - mpv "$t"/* - + $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 @@ -59,10 +59,14 @@ dmo="$DMENU_OPTS" # Safety first cu(){ - rm -fr "$t" 2>$dn + + rm -fr "$t" 2>$dn 1>&2 if [ "$usepts" = "1" ]; then - ptsid="$(ps --no-headers -t pts/$ttyno -o pid)" - [ -n "$ptsid" ] && ( kill -9 "$ptsid" 2>$dn 1>&2; ) + ptsid="$(ps --no-headers -t pts/$ttyno -o pid)" && \ + [ -n "$ptsid" ] && kill -9 "$ptsid" 2>$dn 1>&2 + #dbl chk + a=$(ps -C $TERMINAL -o args,pid | grep "$(printf "%.15s" "$pts_title")") + [ -n "$a" ] && kill -9 ${a##* } fi exit 0 } @@ -122,11 +126,12 @@ pts_open() runthething() { - [ "$typ" = "d" ] && \ + if [ "$typ" = "d" ]; then u=$(<$t grep -v '^N' | sort -r | \ - "$dm" -i $dmo -p "[ Latest videos ]" 2>$dn; \ - return 0) || \ + "$dm" -i $dmo -p "[ Latest videos ]" 2>$dn) + else u=$(<$t "$dm" -i $dmo -p "[ $yt_dm_title > $q ]") + fi [ -z "$u" ] && return 1