From 59d1d3ebd78cb17d443877179c5fc9d74383a9d5 Mon Sep 17 00:00:00 2001 From: epoch Date: Sat, 2 Nov 2019 05:44:17 -0500 Subject: commented out weird derp+merp scheme code. added urilaunch which is meant to be done similar to how dmenu_run gets launched. I use alt+u --- urilaunch | 3 +++ uristart | 43 +++++++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 urilaunch diff --git a/urilaunch b/urilaunch new file mode 100644 index 0000000..a349502 --- /dev/null +++ b/urilaunch @@ -0,0 +1,3 @@ +#!/bin/sh +#uristart.log /should/ already be uniq'd because of uristart's code now, but might as well not rely on it. +uristart $(cat ~/.cache/uristart.log | sort | uniq | dmenu -p url\> | cut '-d ' -f1) diff --git a/uristart b/uristart index fdea944..08eede3 100755 --- a/uristart +++ b/uristart @@ -1,24 +1,26 @@ #!/bin/bash ##might have to configure me. ASKUSER="dmenu -p" -uri=$1 +uri="${1}" scheme="$(printf "%s\n" "$uri" | uricut -s)" -if grep '\+' <<< "$scheme" 2>&1 >/dev/null;then - echo "dunno wtf yet" - scheme1="$(printf "%s\n" "$scheme" | cut -d+ -f1)+" - scheme2="+$(printf "%s\n" "$scheme" | cut -d+ -f2)" - echo $scheme1 - echo $scheme2 - line1="$(grep "^${scheme1}"$'\t' ~/.config/uristart.conf | cut -d: -f2- | sed 's/^[ \t]//g')" - line2="$(grep "^${scheme2}"$'\t' ~/.config/uristart.conf | cut -d: -f2- | sed 's/^[ \t]//g')" - echo $line1 - echo $line2 - pipeline1="$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line1")" - pipeline2="$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line2")" - echo $pipeline1 - echo $pipeline2 - socat "exec:bash -c 'eval \"$pipeline1\"'" "exec:bash -c 'eval \"$pipeline2\"'" -else +### experimental crap.. let's comment it out for now. +#if grep '\+' <<< "$scheme" 2>&1 >/dev/null;then +# echo "dunno wtf yet" +# scheme1="$(printf "%s\n" "$scheme" | cut -d+ -f1)+" +# scheme2="+$(printf "%s\n" "$scheme" | cut -d+ -f2)" +# echo $scheme1 +# echo $scheme2 +# line1="$(grep "^${scheme1}:"$'\t' ~/.config/uristart.conf | tr -s '\t ' | cut -f2- | sed 's/^[ \t]//g' | sed 's/\\n/\\\\n/g')" +# line2="$(grep "^${scheme2}:"$'\t' ~/.config/uristart.conf | tr -s '\t ' | cut -f2- | sed 's/^[ \t]//g' | sed 's/\\n/\\\\n/g')" +# echo $line1 +# echo $line2 +# pipeline1="$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line1" )" +# pipeline2="$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line2" )" +# echo "$pipeline1" +# echo "$pipeline2" +# mknod /tmp/p p +# cat /tmp/p | bash -xc "$pipeline1" | bash -xc "$pipeline2" > /tmp/p +#else line="$(grep "^${scheme}:" ~/.config/uristart.conf | cut -d: -f2- | sed 's/^[ \t]//g')" if printf "%s\n" "$uri" | urimatch nP >/dev/null;then proto="$(grep ^"$scheme"'[\t ]' /etc/services | tr -s '\t ' | cut -f2 | cut -d/ -f1 | head -n1)" @@ -45,5 +47,10 @@ else fi printf '%s:\t%s\n' "${scheme}" "${line}" >> ~/.config/uristart.conf fi + ## uri *might* contain pattern matching special characters. :/ + ## which could break things in weird and exciting ways + if ! cut '-d ' -f1 ~/.cache/uristart.log | grep -Fx "$uri" 2>&1 >/dev/null;then #only log URIs that aren't already listed + printf "%s\n" "$uri" >> ~/.cache/uristart.log + fi eval "$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line")" -fi +#fi -- cgit v1.2.3 From f884100bed6e37c25c57294f20a6182677fafbce Mon Sep 17 00:00:00 2001 From: epoch Date: Sat, 2 Nov 2019 05:44:34 -0500 Subject: added urilaunch to Makefile --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index f327ba1..5a4e9e1 100644 --- a/Makefile +++ b/Makefile @@ -29,3 +29,4 @@ install: all install uriprintf $(PREFIX)/bin/uriprintf install uriunescape $(PREFIX)/bin/uriunescape install uriescape $(PREFIX)/bin/uriescape + install urilaunch $(PREFIX)/bin/urilaunch -- cgit v1.2.3 From c91aa0ac9f6c177d4b8079c052f2d88b74c55956 Mon Sep 17 00:00:00 2001 From: epoch Date: Sun, 17 Nov 2019 02:12:25 -0600 Subject: changed urilaunch to use bash because I like <() and I wanted to include default clipboard' as first choice in dmenu --- urilaunch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/urilaunch b/urilaunch index a349502..772cf93 100644 --- a/urilaunch +++ b/urilaunch @@ -1,3 +1,3 @@ -#!/bin/sh +#!/bin/bash #uristart.log /should/ already be uniq'd because of uristart's code now, but might as well not rely on it. -uristart $(cat ~/.cache/uristart.log | sort | uniq | dmenu -p url\> | cut '-d ' -f1) +uristart $(cat <(printf "%s\n" $(xclip -o | head -n1)) <(cat ~/.cache/uristart.log | sort | uniq) | dmenu -p url\> | cut '-d ' -f1) -- cgit v1.2.3 From 7fb85b98ac81064a38632e1501b72818fcc00f89 Mon Sep 17 00:00:00 2001 From: epoch Date: Sun, 17 Nov 2019 02:13:33 -0600 Subject: made uristart log $2 along with the uri so you can have tags or a "referer" in your logs --- uristart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/uristart b/uristart index 08eede3..4ff1056 100755 --- a/uristart +++ b/uristart @@ -1,4 +1,7 @@ #!/bin/bash +### arguments: +# $1: the URI we're starting +# $2: the "referer" of the URI we're starting. ##might have to configure me. ASKUSER="dmenu -p" uri="${1}" @@ -50,7 +53,11 @@ scheme="$(printf "%s\n" "$uri" | uricut -s)" ## uri *might* contain pattern matching special characters. :/ ## which could break things in weird and exciting ways if ! cut '-d ' -f1 ~/.cache/uristart.log | grep -Fx "$uri" 2>&1 >/dev/null;then #only log URIs that aren't already listed - printf "%s\n" "$uri" >> ~/.cache/uristart.log + if [ "$2" ];then + printf "%s %s\n" "$uri" "$2" >> ~/.cache/uristart.log + else + printf "%s\n" "$uri" >> ~/.cache/uristart.log + fi fi eval "$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line")" #fi -- cgit v1.2.3 From f9c00d204d42c595e740bf3b8b7e7540f3fe6afb Mon Sep 17 00:00:00 2001 From: epoch Date: Tue, 21 Jan 2020 10:05:30 -0600 Subject: got rid of "fuck" in an error message. and added a comment to partially explain a bit of magic. --- getsrv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/getsrv b/getsrv index cb6daeb..019cdf0 100755 --- a/getsrv +++ b/getsrv @@ -19,7 +19,7 @@ elif which host >/dev/null;then host -t SRV "$record" | cut '-d ' -f5- echo "after host" >&2 else - echo "fuck me. how am I supposed to get a srv record without dig or host?" >&2 + echo "how am I supposed to get a srv record without dig or host? giving up." >&2 exit 1 fi | grep '^[0-9][0-9]* [0-9][0-9]*' \ | sort -rn \ @@ -34,3 +34,4 @@ fi | grep '^[0-9][0-9]* [0-9][0-9]*' \ | cut '-d ' -f2- \ | shuf \ | head -n1 \ +## that last pipeline tries to get pretty close to printing a properly weighted response, but not perfect. -- cgit v1.2.3 From d3f5b8e73bbea0c6b40a10628e00e6cde40aeb66 Mon Sep 17 00:00:00 2001 From: epoch Date: Tue, 21 Jan 2020 10:07:05 -0600 Subject: added whitespace, deleted some commented out code, added comments to make the purpose of certain blocks clearer, escaped backslashes in $line so they get passed to uriprintf right --- uristart | 95 ++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 44 insertions(+), 51 deletions(-) diff --git a/uristart b/uristart index 4ff1056..3acf785 100755 --- a/uristart +++ b/uristart @@ -2,62 +2,55 @@ ### arguments: # $1: the URI we're starting # $2: the "referer" of the URI we're starting. +### requirements: +# getsrv, urimatch, urijoin, uricut, some-way-to-ask-the-user-for-a-line (dmenu by default) +# getsrv tries dig and host, you only need one or the other. ##might have to configure me. ASKUSER="dmenu -p" + uri="${1}" scheme="$(printf "%s\n" "$uri" | uricut -s)" -### experimental crap.. let's comment it out for now. -#if grep '\+' <<< "$scheme" 2>&1 >/dev/null;then -# echo "dunno wtf yet" -# scheme1="$(printf "%s\n" "$scheme" | cut -d+ -f1)+" -# scheme2="+$(printf "%s\n" "$scheme" | cut -d+ -f2)" -# echo $scheme1 -# echo $scheme2 -# line1="$(grep "^${scheme1}:"$'\t' ~/.config/uristart.conf | tr -s '\t ' | cut -f2- | sed 's/^[ \t]//g' | sed 's/\\n/\\\\n/g')" -# line2="$(grep "^${scheme2}:"$'\t' ~/.config/uristart.conf | tr -s '\t ' | cut -f2- | sed 's/^[ \t]//g' | sed 's/\\n/\\\\n/g')" -# echo $line1 -# echo $line2 -# pipeline1="$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line1" )" -# pipeline2="$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line2" )" -# echo "$pipeline1" -# echo "$pipeline2" -# mknod /tmp/p p -# cat /tmp/p | bash -xc "$pipeline1" | bash -xc "$pipeline2" > /tmp/p -#else - line="$(grep "^${scheme}:" ~/.config/uristart.conf | cut -d: -f2- | sed 's/^[ \t]//g')" - if printf "%s\n" "$uri" | urimatch nP >/dev/null;then - proto="$(grep ^"$scheme"'[\t ]' /etc/services | tr -s '\t ' | cut -f2 | cut -d/ -f1 | head -n1)" - if [ ! "$proto" ]; then - proto=tcp - fi - uri="$(cat <(printf "%s\n" "$uri" | uricut) \ - <(getsrv $(printf "%s\n" "$uri" | uriprintf '%s '"$proto"' %d') 2>&- | tr ':' ' ' | sed 's/ /_port: /' | sed 's/^/domain: /' | tr _ '\n') \ - | urijoin)" - printf "srv (%s) modified uri: %s\n" "$proto" "$uri" >&2 +line="$(grep "^${scheme}:" ~/.config/uristart.conf | cut -d: -f2- | sed 's/^[ \t]//g' | sed 's/\\/\\\\/g')" + +### if we do not have a port, we are going to try to get it from their srv records. +if printf "%s\n" "$uri" | urimatch nP >/dev/null;then + proto="$(grep ^"$scheme"'[\t ]' /etc/services | tr -s '\t ' | cut -f2 | cut -d/ -f1 | head -n1)" + if [ ! "$proto" ]; then + proto=tcp fi - if printf "%s\n" "$uri" | urimatch nP >/dev/null;then #if we *still* don't have a port - uri="$(cat <(printf "%s\n" "$uri" | uricut) \ - <(grep ^"$scheme"'[\t ]' /etc/services | tr -s '\t ' | cut -f2 | cut -d/ -f1 | head -n1 | sed 's/^/port: /') \ - | urijoin)" - printf "getent modified uri: %s\n" "$uri" >&2 - fi - echo "the uri we're using: $uri" + uri="$(cat <(printf "%s\n" "$uri" | uricut) \ + <(getsrv $(printf "%s\n" "$uri" | uriprintf '%s '"$proto"' %d') 2>&- | tr ':' ' ' | sed 's/ /_port: /' | sed 's/^/domain: /' | tr _ '\n') \ + | urijoin)" + printf "srv (%s) modified uri: %s\n" "$proto" "$uri" >&2 +fi + +### if they do not have srv records, fall-back to /etc/services +if printf "%s\n" "$uri" | urimatch nP >/dev/null;then #if we *still* don't have a port + uri="$(cat <(printf "%s\n" "$uri" | uricut) \ + <(grep ^"$scheme"'[\t ]' /etc/services | tr -s '\t ' | cut -f2 | cut -d/ -f1 | head -n1 | sed 's/^/port: /') \ + | urijoin)" + printf "getent modified uri: %s\n" "$uri" >&2 +fi + +### ask the user for a pipeline for starting these URIs if there isn't a pipeline already in the config. +echo "the uri we're using: $uri" +if [ "$line" = "" ];then + line="$(printf "" | $ASKUSER "protocol scheme (${scheme}) not configured yet. enter new pipeline to use:")" if [ "$line" = "" ];then - line="$(printf "" | $ASKUSER "protocol scheme (${scheme}) not configured yet. enter new pipeline to use:")" - if [ "$line" = "" ];then - echo "user noped on entering new pipeline" >&2 - exit 1 - fi - printf '%s:\t%s\n' "${scheme}" "${line}" >> ~/.config/uristart.conf + echo "user noped on entering new pipeline" >&2 + exit 1 fi - ## uri *might* contain pattern matching special characters. :/ - ## which could break things in weird and exciting ways - if ! cut '-d ' -f1 ~/.cache/uristart.log | grep -Fx "$uri" 2>&1 >/dev/null;then #only log URIs that aren't already listed - if [ "$2" ];then - printf "%s %s\n" "$uri" "$2" >> ~/.cache/uristart.log - else - printf "%s\n" "$uri" >> ~/.cache/uristart.log - fi + printf '%s:\t%s\n' "${scheme}" "${line}" >> ~/.config/uristart.conf +fi + +### log the uri if it isn't logged already. +if ! cut '-d ' -f1 ~/.cache/uristart.log | grep -Fx "$uri" 2>&1 >/dev/null;then #only log URIs that aren't already listed + if [ "$2" ];then + printf "%s %s\n" "$uri" "$2" >> ~/.cache/uristart.log + else + printf "%s\n" "$uri" >> ~/.cache/uristart.log fi - eval "$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line")" -#fi +fi + +### do the magic +eval "$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line")" -- cgit v1.2.3