#!/bin/ksh # written as part of the oldcomputerchallenge 2024 # automa.triapul.cz/occ # The links2 companion edition # This will only work with links2 # Add a keybind in tmux # to split a window and run tmenu. # After tmenu exits, the pane is # killed automatically. # : bind F4 split -l 5 ~/bin/tmenu-links # The rest of this code is ~/bin/tmenu-links # CAREFUL, there is currently no sanity # check for the c)opy and b)ookmark commands # to see if pane 0 is actually links2. # Those commands are expected to be only # run inside a tmux window with a single # links2 pane. # copied url is printed to ~/url # bookmarks are appended to ~/bookmarks.txt # also depending on how fast your machine # is, you might have to decrease or increase # the sleep period variable below. # This is because there can be a slight delay # when opening links2' menu (Escape) # the rip option only works on highlighted # youtoob/invidious urls and you need yt-dlp # installed for it to work. By default it # downloads to ~/ # the two bookmark commands work like copy url, # but the user is prompted to label the url # and it is then appended to ~/bookmarks # loading a bookmark works similarly to the # search, url and wiki commands, such as that # a new window with the loaded bookmark is # opened. browser=links sleep=.2 inp() { key=$( os=$(stty -g);stty raw -echo; dd if=/dev/tty bs=1 count=1 2>/dev/null; stty $os) } run_browser() { tmux new-window -c "~/" -n"browser" $browser $* } print -n "u)rl s)earch-ddg w)iki c)opy highlighted url C)opy current url" print " r)ip from yt" print "b)bookmark highlighted url B)ookmark current url l)oad bookmark" inp clear case $key in u*) read url?"url: " run_browser "$url" ;; s*) read search?"search: " search=$(print $search | sed 's/ /+/g') run_browser "https://ddg.gg/lite/?q=$search" ;; w*) read wiki?"wiki: " wiki=$(print $wiki | sed 's/ /+/g') tmux new-window \ links "https://en.wikipedia.org/wiki\ /Special:Search?go=Go&search=\ $wiki&ns0=1#bodyContent" ;; [rcb]*) touch ~/url tmux send-keys -t"0" C-g C-u Escape sleep $sleep tmux send-keys -t"0" Escape v v "url" Enter Enter if [[ $key = r ]]; then yt-dlp -x --audio-format mp3 $(cat ~/url) & elif [[ $key = b ]]; then clear; read title?"bookmark title: " print "$title|$(cat ~/url)" >> ~/bookmarks.txt clear; print $title bookmared in ~/bookmarks.txt sleep 1 else clear; print -n "url is in ~/url" sleep 1 fi ;; [BC]*) touch ~/url tmux send-keys -t"0" G C-u Escape sleep $sleep tmux send-keys -t"0" Escape v v "url" Enter Enter clear; print -n "url is in ~/url" if [[ $key = B ]]; then clear; read title?"bookmark title: " print "$title|$(cat ~/url)" >> ~/bookmarks.txt clear; print $title bookmared in ~/bookmarks.txt fi sleep 1 ;; l*) clear read load?"type a part of the bookmark: " if [[ $(grep -e "$load" ~/bookmarks.txt) = "" ]]; then print "no such bookmark" sleep 1 else x=1 for i in $(grep -e "$load" ~/bookmarks.txt |\ sed 's/ /_/' | head -n9 | sort | uniq); do bm[$x]=$(print $i | cut -d"|" -f2-) print "$x) $i" | sed 's/|/ /' | rev | tail -c 60 | rev ((x++)) done print "Open bookmark number? (q to cancel)" inp case $key in q) return 0;; [1-9]) if [[ ${bm[$key]} != "" ]]; then run_browser "${bm[$key]}" fi;; esac fi ;; esac return 0