From 8ec0b3da94b3bbc18140bdea22488d51676d2634 Mon Sep 17 00:00:00 2001 From: epoch Date: Mon, 20 Apr 2020 03:33:21 -0500 Subject: more of the breaking-change. code to get the line moved to external program so it can be rewritten easier. copy_start_nevermind.sh uses it now. cleaned up Makefile styling. --- Makefile | 25 +++++++++++++------------ copy_start_nevermind.sh | 2 +- urigetline | 25 +++++++++++++++++++++++++ uristart | 27 +++------------------------ uristart.conf.example | 10 +++++----- 5 files changed, 47 insertions(+), 42 deletions(-) create mode 100755 urigetline diff --git a/Makefile b/Makefile index f8079ce..b6e3ab8 100644 --- a/Makefile +++ b/Makefile @@ -21,17 +21,18 @@ clean: rm -f *.o install: all - install urimatch $(PREFIX)/bin/urimatch - install uricut $(PREFIX)/bin/uricut - install urijoin $(PREFIX)/bin/urijoin - install uricmp $(PREFIX)/bin/uricmp - install uristart $(PREFIX)/bin/uristart - install uriprintf $(PREFIX)/bin/uriprintf - install uriunescape $(PREFIX)/bin/uriunescape - install uriescape $(PREFIX)/bin/uriescape - install urilaunch $(PREFIX)/bin/urilaunch - install search $(PREFIX)/bin/search - install getsrv $(PREFIX)/bin/getsrv - install urititle $(PREFIX)/bin/urititle + install -t $(PREFIX)/bin urimatch + install -t $(PREFIX)/bin uricut + install -t $(PREFIX)/bin urijoin + install -t $(PREFIX)/bin uricmp + install -t $(PREFIX)/bin uristart + install -t $(PREFIX)/bin uriprintf + install -t $(PREFIX)/bin uriunescape + install -t $(PREFIX)/bin uriescape + install -t $(PREFIX)/bin urilaunch + install -t $(PREFIX)/bin search + install -t $(PREFIX)/bin getsrv + install -t $(PREFIX)/bin urititle + install -t $(PREFIX)/bin urigetline install -t $(PREFIX)/bin copy_start_nevermind.sh install -t $(PREFIX)/bin choose diff --git a/copy_start_nevermind.sh b/copy_start_nevermind.sh index ec8f102..cae5668 100755 --- a/copy_start_nevermind.sh +++ b/copy_start_nevermind.sh @@ -1,7 +1,7 @@ #!/bin/bash scheme="$(uricut -s <<< "$1")" selection="$(printf "%s\ncopy\nstart\nnevermind\n" "$(printf "%s\n" "$1" | uricut | grep -v '^whole')" \ - | choose "$(printf "uri: '%s'\nwill be ran with: %s\n" "$1" "$(grep "^${scheme}:" ~/.config/uristart.conf | tr -s '\t' | cut -f2- )" )")" + | choose "$(printf "uri: '%s'\nwill be ran with: %s\n" "$1" "$(urigetline "$1")" )")" echo "$selection" if [ "$selection" = "copy" ];then printf "%s" "$1" | xclip -i diff --git a/urigetline b/urigetline new file mode 100755 index 0000000..81e28c9 --- /dev/null +++ b/urigetline @@ -0,0 +1,25 @@ +#!/bin/bash +uri="$1" +### old way. +# line="$(grep "^${scheme}:" ~/.config/uristart.conf | cut -d: -f2- | sed 's/^[ \t]*//g' | sed 's/\\/\\\\/g')" + +### fancy way. +cat ~/.config/uristart.conf \ + | while read -r l;do + uritmp="$uri" + uritmp="$(printf "%s\n" "$l" \ + | cut -d: -f1 \ + | tr ' ' '\n' \ + | paste '-d ' - - \ + | while read -r a b;do + uritmp="$(printf "%s\n" "${uritmp}" | urimatch "$a" "$b")" + printf "%s\n" "$uritmp" + done | tail -n1)" + if [ "$uritmp" ];then + printf '%s\n' "$l" + break + fi + done \ + | cut -d: -f2- \ + | sed 's/^[ \t]*//g' \ + | sed 's/\\/\\\\/g' diff --git a/uristart b/uristart index d36764f..17a5af9 100755 --- a/uristart +++ b/uristart @@ -17,29 +17,8 @@ fi uri="${1}" scheme="$(printf "%s\n" "$uri" | uricut -s)" -#line="$(grep "^${scheme}:" ~/.config/uristart.conf | cut -d: -f2- | sed 's/^[ \t]*//g' | sed 's/\\/\\\\/g')" -line="$( -cat ~/.config/uristart.conf \ - | while read -r l;do - uritmp="$uri" - uritmp="$(printf "%s\n" "$l" \ - | cut -d: -f1 \ - | tr ' ' '\n' \ - | paste '-d ' - - \ - | while read -r a b;do - uritmp="$(printf "%s\n" "${uritmp}" | urimatch "$a" "$b")" - printf "%s\n" "$uritmp" - done | tail -n1)" - if [ "$uritmp" ];then - printf '%s\n' "$l" - break - fi - done \ - | cut -d: -f2- \ - | sed 's/^[ \t]*//g' \ - | sed 's/\\/\\\\/g' -)" +line="$(urigetline "$uri")" ### 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 @@ -49,7 +28,7 @@ if printf "%s\n" "$uri" | urimatch nP >/dev/null;then fi uri="$(cat <(printf "%s\n" "$uri" | uricut) \ <(getsrv $(printf "%s\n" "$uri" | uriprintf '%s '"$proto"' %d' | cut -d+ -f2-) 2>&- | tr ':' ' ' | sed 's/ /_port: /' | sed 's/^/domain: /' | tr _ '\n') \ - | urijoin)" + | urijoin 2>/dev/null)" printf "srv (%s) modified uri: %s\n" "$proto" "$uri" >&2 fi @@ -57,7 +36,7 @@ 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)" + | urijoin 2>/dev/null)" printf "getent modified uri: %s\n" "$uri" >&2 fi diff --git a/uristart.conf.example b/uristart.conf.example index 27fab79..53fc08b 100644 --- a/uristart.conf.example +++ b/uristart.conf.example @@ -1,8 +1,8 @@ ### uristart will escape only single-quotes in the url parts. ### so place them inside single-quotes when creating handler pipelines. or else! ### (if you're given a bad link someone might be able to run shell commands) -finger: printf "%%s\r\n" '%p' | ncat '%d' 79 | tr -d '\r' | xmessage -file - -whois: whois "$(printf '%%s\\\\n' '%d' | sed 's/^..*$/-h/')" '%d' '%p' | xmessage -file - -irc: x-terminal-emulator -e irssi -c '%d' -p '%P' -http: firefox --new-tab '%U' -DEFAULT: xdg-open '%U' +s finger: printf "%%s\r\n" '%p' | ncat '%d' 79 | tr -d '\r' | xmessage -file - +s whois: whois "$(printf '%%s\\\\n' '%d' | sed 's/^..*$/-h/')" '%d' '%p' | xmessage -file - +s irc: x-terminal-emulator -e irssi -c '%d' -p '%P' +s http: firefox --new-tab '%U' +s DEFAULT: xdg-open '%U' -- cgit v1.2.3