Skip to content

Instantly share code, notes, and snippets.

@shmup
Last active January 27, 2024 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shmup/d644711dc4ad4654a4c5b8b6563ec672 to your computer and use it in GitHub Desktop.
Save shmup/d644711dc4ad4654a4c5b8b6563ec672 to your computer and use it in GitHub Desktop.
quickly run any of the breathing moos on moolist.com with tt++
#!/usr/bin/env bash
# quickly run any of the breathing moos on moolist.com with tt++
# requires: curl, fzy (or fzf but update script), tt++
# https://asciinema.org/a/633014
set -euo pipefail
html_content=$(curl -s 'https://moolist.com/all.php')
telnet_uris=$(
echo "$html_content" |
grep 'Up' | # breathing moos only
grep -oP 'telnet://[^<]+' |
sed "s/'>.*//" |
sed 's/telnet:\/\///' |
sort |
uniq
)
selected_uri=$(echo "$telnet_uris" | fzy -l 50)
[[ -z $selected_uri ]] && exit 0
host=$(echo "${selected_uri}" | awk -F':' '{print $1}')
port=$(echo "${selected_uri}" | awk -F':' '{print $2}')
tt++ -e "#session moo {$host} {$port}"
$0
@shmup
Copy link
Author

shmup commented Jan 26, 2024

I was 1-upped in the best way by @scandum

Here is native tt++ implementation:

#!/usr/bin/env tt++

#config inheritance off
#script {moos} {curl -s 'https://moolist.com/all.php'}
#list moos filter {%*Up%*telnet%*}
#loop 1 &moos[] index #replace moos[$index] {%*<a href='telnet://%*:%*'>%*} {&2 &3}
#list moos sort
#draw scaled scroll tile 1 1 1 1 $moos[]

#event {PROCESSED KEYPRESS}
{
   #screen clear scroll;
   #cursor get input;
   #showme {};
   #loop 1 &moos[] index
   {
       #regex {$moos[$index]} {^$input%*} #showme {<fca>$input<ddd>&1}
   };
   #cursor redraw;
}

#event {CATCH RECEIVED INPUT}
{
    #loop 1 &moos[] index
    {
        #if {{$moos[$index]} == {$input%*}} {#session moo $moos[$index];#break}
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment