dot

packages and services management
Log | Files | Refs | README

commit b5432829289fdcf48f2d40b20c4ea9012c305638
parent 9a669f78f1c2259305a976638ab7d538539e5287
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun,  3 Dec 2017 17:08:45 +0100

uri parser for xdg-open

Diffstat:
Mbin/io | 4++--
Abin/uri | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mbin/xdg-open | 125+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
Mdot/bashrc | 7+++----
Mdot/ssh/config | 4++++
Apackage/sup/build | 3+++
Apackage/sup/tar | 1+
Muri | 12+++++++++---
8 files changed, 160 insertions(+), 46 deletions(-)

diff --git a/bin/io b/bin/io @@ -39,10 +39,10 @@ $(cat "$HOME/etc/uri") EOF ) -name=${sel#* } +name=${sel##* } case ${sel%% *} in (*mail*) - printf %s "$name" | cut -f 2 | mlist | mthread | msort -r -d | + printf %s "$name" | mlist | mthread | msort -r -d | mseq -S | mscan -f '%6n %u %D %20f %t%2i%120S' | iomenu -p mail | sed -r 's/^ *([0-9]*) .*/\1/'| xargs mless ;; diff --git a/bin/uri b/bin/uri @@ -0,0 +1,50 @@ +# scheme://[user[:pass]@]host[:port][/path] +IFS=' ' read scheme user pass host port path << EOF +$(printf %s "$1" | awk '{ + gsub(" ", "%20"); + gsub("\t", "%0b"); + + scheme = $0; + if (sub("[^:/]*://", "", $0) > 0) + sub("://.*", "", scheme); + else + scheme = "."; + + user = $0; + if (sub("[^@/]*@", "", $0) > 0) + sub("@.*", "", user); + else + user = "."; + + pass = user; + if (sub(":.*", "", user) > 0) + sub("[^:]*:", "", pass) ; + else + pass = "."; + + printf("\n\t[ %s ]\n\n", $0) > "/dev/stderr"; + + host = $0 + if (sub("[^:]*:", "", $0) > 0) + sub(":.*", "", host); + else if (sub("[^/]*/", "/", $0) > 0) + sub("/.*", "", host); + + port = $0 + if (sub(":[0-9]+", "", $0) > 0) + sub("[^:]*:", "", port); + else + port = "."; + + path = $0; + + printf("%s\t%s\t%s\t%s\t%s\t%s", scheme, user, pass, host, port, path); +}') +EOF + +printf 'scheme: %s\n' "$scheme" +printf 'user: %s\n' "$user" +printf 'pass: %s\n' "$pass" +printf 'host: %s\n' "$host" +printf 'port: %s\n' "$port" +printf 'path: %s\n' "$path" diff --git a/bin/xdg-open b/bin/xdg-open @@ -1,6 +1,13 @@ #!/bin/sh # override the xdg-open utility +aexec() +{ + name=$(printf %s "$name" | tr / ! | sed -r 's/.*(.{53})$/\1/') + [ "$SSH_TTY" ] && e='^Z' || e='^\' + ABDUCO=$name exec abduco -e "$e" -A "$name" "$@" +} + for name in "$@"; do continue; done [ -e "$name" ] && name=$(cd "$(dirname "$1")"; pwd)/$(basename "$1") printf '\033]0;%s\a' "$name" @@ -8,66 +15,110 @@ printf '\033]0;%s\a' "$name" tty | grep -q -e '^/dev/pts/.*' -e '^/dev/tty*' || exec st -f terminus:pixelsize=18 -e "$0" "$@" -aexec() -{ - name=$(printf %s "$name" | tr / ! | sed -r 's/.*(.{53})$/\1/') - [ "$SSH_TTY" ] && e='^Z' || e='^\' - ABDUCO=$name exec abduco -e "$e" -A "$name" "$@" -} +# scheme://[user[:pass]@]host[:port][[:][/]path][/path] +IFS=' ' read scheme user pass host port path << EOF +$(printf %s "$1" | awk '{ + gsub(" ", "%20"); + gsub("\t", "%0b"); -case $1 in -(http*://*.mp3) - aexec mplayer "$1" - ;; -(news://*|nntp://) + scheme = $0; + if (sub("[^:/]*://", "", $0) > 0) + sub("://.*", "", scheme); + else + scheme = "."; + + user = $0; + if (sub("[^@/]*@", "", $0) > 0) + sub("@.*", "", user); + else + user = "."; + + pass = user; + if (sub(":.*", "", user) > 0) + sub("[^:]*:", "", pass) ; + else + pass = "."; + + host = $0 + if (sub("[^:]*:", "", $0) > 0) + sub(":.*", "", host); + else if (sub("[^/]*/", "/", $0) > 0) + sub("/.*", "", host); + + port = $0 + if (sub(":[0-9]+", "", $0) > 0) + sub("[^:]*:", "", port); + else + port = "."; + + path = $0; + + printf("%s\t%s\t%s\t%s\t%s\t%s", scheme, user, pass, host, port, path); +}') +EOF + +#--- hierarchical uri ---------------------------------------------------------- + +case $scheme in +(news|nntp) aexec retawq "$1" ;; -(http*://*) +(http|https) for b in retawq firefox chromium chromium-browser chrome x-www-browser do command -v "$b" && break done aexec "$b" "$1" ;; -(gopher://*) +(gopher) aexec sacc "$1" ;; -(ssh://*) - address=${1#ssh://} - case $address in - (*:*) - aexec ssh -p "${address#*:}" "${address%:*}" - ;; - (*) - aexec ssh "$address" - ;; - esac - ;; -(sftp://*) - aexec sftp ${1#sftp://} - ;; -(ftp://*) - aexec ftp ${1#ftp://} - ;; -(9p://*) - address=${1#9p://} +(ssh) + address=${1#*://} + address=${address%*:} + if [ "$port" = . ] + then exec ssh "$address" + else exec ssh -p "$port" "$address" + fi + ;; +(sftp) + address=${1#*://} + address=${address%*:} + if [ "$port" = . ] + then aexec sftp "$address" + else aexec sftp -p "$port" "$address" + fi +(ftp) + aexec ftp "$1" + ;; +(9p) dir=$HOME/var/9p/$address mkdir -p "$dir" aexec doas 9pfs "$address" "$dir" ;; -(git://*) +(git) cd "$HOME/src" || exit 1 aexec git clone "$1" ;; -(telnet://*) +(telnet) address=${1#telnet://} aexec telnet "${address%:*}" "${address##*:}" ;; -(mailto:*) +esac + +#--- other uri ----------------------------------------------------------------- + +case ${1%%*:} in +(mailto) aexec mcom "${1#mailto:}" ;; -(magnet:*) - aexec transmission-cli "${1#magnet:}" +(magnet) + aexec transmission-cli "$1" ;; +esac + +#--- local resources ----------------------------------------------------------- + +[ -e "$1" ] && case "$1" in (*.torrent) aexec transmission-cli "$1" ;; diff --git a/dot/bashrc b/dot/bashrc @@ -5,12 +5,11 @@ PS1='$( )' PS2=' -- ' -alias blih="blih -u $BLIH" -alias c='cd "$(find . -maxdepth 4 -name .git -prune -o -type d | iomenu)"' +alias blih='blih -u "$BLIH"' alias c='cd "$(find . -maxdepth 4 -name .git -prune -o -type d | iomenu)"' +alias f='f=$(find . -name .git -prune -o -print | iomenu)' +alias p='p=$(io-ps)' alias cl='printf "\033[H\033[2J"' -alias f='f=$(io find)' alias l='ls -Alp' -alias p='p=$(io ps)' alias o='xdg-open' alias s='git status -s --branch' diff --git a/dot/ssh/config b/dot/ssh/config @@ -29,3 +29,7 @@ host josuah.net host git.josuah.net IdentityFile /mnt/key/ssh/josuah.net.key AddKeysToAgent yes + +host bitreich.org + IdentityFile /mnt/key/ssh/josuah.key + AddKeysToAgent yes diff --git a/package/sup/build b/package/sup/build @@ -0,0 +1,3 @@ +case $(uname) in (Linux) make=make ;; (*BSD) make=gmake ;; (*) make=echo ;; esac + +$make && $make PREFIX="$OPT" install diff --git a/package/sup/tar b/package/sup/tar @@ -0,0 +1 @@ +https://files.dyne.org/sup/sup-1.1.tar.gz diff --git a/uri b/uri @@ -10,9 +10,9 @@ gopher://josuah.net gopher://me0w.net/7/searx.dcgi gopher://port70.net gopher://r-36.net +gopher://suckless.org gopher://tx.god.jp gopher://z3bra.org -gopher://suckless.org http://2f30.org http://calomel.org http://cyberia.systems @@ -26,6 +26,7 @@ http://lobste.rs http://mixtape.moe http://n-gate.com http://n-gate.com +http://netsukuku.freaknet.org http://nixers.net http://nixers.net http://nullprogram.com @@ -43,17 +44,22 @@ https://gxamjbnu7uknahng.onion.rip/wiki/index.php/Infornography:_The_Tao_of_Meme https://wiby.me https://www.destroyallsoftware.com/compendium/network-protocols irc://irc.cyberia.is:6697 +irc://irc.dyne.org +irc://irc.efnet.org irc://irc.freenode.net:6697 +irc://irc.hackint.org:6697 irc://irc.lainchan.org:6697 irc://irc.oftc.net:6697 -irc://irc.scalix.gandi.net:6667 +irc://irc.rezosup.org +irc://pstyx.god.jp:6697 irc://unix.chat:6697 +sftp://josuah@store.josuah.net:2222 sftp://lainon@archive.sh ssh://josuah@cyberia.systems ssh://josuah@josuah.net ssh://josuahdemangeon@grex.org ssh://root@0.0.0.0:5555 -ssh://root@pushswap.josuah.net +ssh://root@store.josuah.net ssh://root@store.josuah.net:2222 telnet://entropy.bbses.info:23999 telnet://lain.codes:7777