dot

packages and services management
Log | Files | Refs | README

commit fbe575366283e7b119c3d00dba6301e318e83a4d
parent 3561fc781d34b485f6a9104bcc51c454caa3beb6
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun, 25 Mar 2018 22:17:33 +0200

yes, this requires a ssh connection to localhost, but what to say...

Diffstat:
Mbin/xdg-open | 251++++---------------------------------------------------------------------------
1 file changed, 10 insertions(+), 241 deletions(-)

diff --git a/bin/xdg-open b/bin/xdg-open @@ -2,117 +2,27 @@ # override the xdg-open utility -[ "$DISPLAY" ] && case "$(tty)" in -(/dev/pts/*|/dev/ttyp*) - ;; -(*) - exec st -f terminus:pixelsize=16 -e xdg-open "$@" - ;; +[ "$DISPLAY" ] && case "$(tty)" in (/dev/pts/*|/dev/ttyp*) ;; +(*) ABDUCO=1 exec st -f terminus:pixelsize=16 -e xdg-open "$@" ;; esac [ "$ABDUCO" ] || exec xdg-abduco xdg-open "$@" +! [ -e "$1" ] || set -- "$1" "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" +! [ -h "$1" ] || set -- "$1" "$(readlink -f "$1")" +! [ -d "$1" ] || set -- "$1" "$(cd "$1"; pwd)" + # [scheme://][user[:pass]@]host[:port][/path] IFS=' ' read scheme user pass host port path << EOF -$(awk -v URI="$1" ' -BEGIN { - gsub(" ", "%20", URI); - gsub("\t", "%0b", URI); - - scheme = URI; - if (sub("^[^:/]*://", "", URI) > 0) - sub("://.*", "", scheme); - else - scheme = "."; - - user = URI; - if (sub("^[^@/]*@", "", URI) > 0) - sub("@.*", "", user); - else - user = "."; - - pass = user; - if (sub(":.*", "", user) > 0) - sub("[^:]*:", "", pass) ; - else - pass = "."; - - host = URI - if (sub("^[^:]*:", ":", URI) > 0) - sub(":.*", "", host); - else if (sub("[^/]*/", "/", URI) > 0) - sub("/.*", "", host); - - port = URI - if (sub("^:[0-9]+:", "", URI) > 0 || sub("^:[0-9]+/", "/", URI) > 0) { - sub(":", "", port); - sub("[:/].*", "", port); - } else if (sub("^:[0-9]+$", "", URI) > 0) { - sub(":", "", port); - } else { - port = "."; - } - - path = URI; - if (match(path, "^/") == 0) - path = ""; - sub("[#?].*", "", path); - - printf("%s\t%s\t%s\t%s\t%s\t%s", scheme, user, pass, host, port, path); -}') +$(xdg-uri "$1") EOF -case "$scheme" in -(ssh) - [ "$port" = . ] && port="" || port="-P $port" - [ "$user" = . ] && user="" || user="$user@" - [ "$pass" = . ] && pass="" || pass="$" - ;; -esac - case "$host" in (*.onion) [ "$TOR" ] || TOR="$1" exec torsocks xdg-open "$1" ;; esac -file="" - -case "$path" in -(*.torrent) - file="$HOME/var/torrent/${path##*/}" - ;; -(*.jpg|*.JPG|*.jpeg|*.JPEG|*.png|*.PNG|*.gif|*.GIF) - file="$HOME/lib/image/$host/${path##*/}" - ;; -(*.opus|*.ogg|*.mp3|*.flac) - file="$HOME/lib/music/$host/${path##*/}" - ;; -(*.webm|*.mp4|*.mkv|*.ogv|*.avi) - file="$HOME/lib/video/$host/${path##*/}" - ;; -(*.pdf|*.ps) - file="$HOME/lib/doc/$host/${path##*/}" - ;; -(*.txt) - file="$HOME/lib/text/$host/${path##*/}" - ;; -(*.tar|*.gz|*.bz2|*.xz|*.tgz|*.tgz|*.tbz2|*.txz|*.zip|*.rar) - file="$HOME/tmp/${path##*/}" - ;; -esac - -[ "$file" ] && mkdir -p "$(dirname "$file")" - -case "$(uname)" in -(Linux) - play="aplay -f cd" - ;; -(*BSD) - play="aucat -r 44100 -i -" - ;; -esac - case "$1" in (git://*) user="" @@ -121,7 +31,6 @@ case "$1" in user="$(dirname "$path")" ;; esac - mkdir -p "$HOME/git/$host/$user" cd "$HOME/git/$host/$user" exec git clone "$1" @@ -148,33 +57,6 @@ case "$1" in (gopher://*) exec sacc "$1" ;; -(http://*|https://*) - case "$host" in - (*vimeo.com*|*youtube.com*|*youtu.be*|*openload.co*) - mkdir -p "$HOME/lib/video/$host" - cd "$HOME/lib/video/$host" - file="$PWD/$(youtube-dl --get-filename "$1")" - youtube-dl "$1" - exec xdg-open "$file" - ;; - (*bandcamp.com*) - mkdir -p "$HOME/lib/music/$host" - cd "$HOME/lib/music/$host" - file="$PWD/$(youtube-dl --get-filename "$1")" - youtube-dl "$1" - exec xdg-open "$file" - ;; - (*) - if [ "$file" ] - then - curl -o "$file" "$1" - exec xdg-open "$file" - else - exec firefox "$1" - fi - ;; - esac - ;; (irc://*) [ "$port" = . ] && port='6667' mkdir -p "$SVDIR" @@ -190,126 +72,13 @@ case "$1" in [ "$port" = . ] && port='22' exec sftp -P "$port" "$host" ;; -(ssh://*/*.pdf) - ssh $port "$user$host" xz -c - "$path" | xz -d - | mupdf /dev/stdin & - exit ;; -(ssh://*/*.ff) - ssh $port "$user$host" xz -c - "$path" | xz -d - | lel - exit ;; -(ssh://*/*.png|ssh://*/*.PNG) - ssh $port "$user$host" png2ff '<' "$path"| xz -c -" | xz -d - | lel - exit ;; -(ssh://*/*.jpg|ssh://*/*.jpeg|ssh://*/*.JPG|ssh://*/*.JPEG) - ssh $port "$user$host" jpg2ff '<' "$path" | xz -c -" | xz -d - | lel - exit ;; -(ssh://*/*.opus|ssh://*/*.flac|ssh://*/*.ogg|ssh://*/*.vorbis|ssh://*/*.wav) - ssh $port "$user$host" "opusenc '$path' -" #| ffplay - - exit ;; -(ssh://*/*.webm|ssh://*/*.mp4|ssh://*/*.mkv|ssh://*/*.ogv|ssh://*/*.avi) - ssh $port "$user$host" cat "$path" | ffplay - - exit ;; -(ssh://*/*.[0-9]|ssh://*/*.[0-9]p|ssh://*/ssh://*/*.[0-9].gz) - ssh $port "$user$host" mandoc -T utf8 "$path" | less - exit ;; -(ssh://*/*) - exec ssh $port "$user$host" "\$EDITOR '$path'" - ;; -(ssh://*) - exec ssh $port "$user$host" - ;; (telnet://*) exec telnet "$port" "$host" ;; -(*://*) - exec printf 'unsupported protocol\n' 1>&2 - ;; -(r/*) - exec firefox "http://reddit.com/$1" - ;; -(*\([0-9]\)|*\([0-9]p\)) - exec man "${1%\(*}" - ;; -(*.torrent) - exec transmission-cli "$1" - ;; -(*.img|*.iso) - exec qemu-system-x86_64 -m 500M "$1" - ;; -(*.pdf) - mupdf "$1" & - ;; -(*.png|*.PNG) - png2ff < "$1" | lel & - ;; -(*.jpg|*.jpeg|*.JPG|*.JPEG) - jpg2ff < "$1" | lel & - ;; -(*.gif) - exec ffplay -loop 0 "$1" - ;; -(*.opus|*.mp3|*.flac|*.ogg|*.vorbis|*.wav|*.webm|*.mp4|*.mkv|*.ogv|*.avi) - exec ffplay "$1" - ;; -(*/music/*) - find "$1" -type f | sort | while IFS='' read -r song - do - ffplay -autoexit "$song" - done - ;; -(*.[0-9]|*.[0-9]p|*.[0-9].gz) - exec mandoc -a -T utf8 "$1" - ;; -(*.o|*.a) - exec radare2 "$1" - ;; -(*.html) - exec firefox "$1" - ;; -(*.tgz) - mv "$1" "${1%.tgz}.tar.gz" - exec xdg-open "${1%.tgz}.tar.gz" - ;; -(*.tbz) - mv "$1" "${1%.tbz}.tar.bz2" - exec xdg-open "${1%.tbz}.tar.bz2" - ;; -(*.txz) - mv "$1" "${1%.txz}.tar.xz" - exec xdg-open "${1%.txz}.tar.xz" - ;; -(*.bz2) - bzip2 -ds "$1" - exec xdg-open "${1%.bz2}" - ;; -(*.gz) - gzip -d "$1" - exec xdg-open "${1%.gz}" - ;; -(*.xz) - xz -d "$1" - exec xdg-open "${1%.xz}" - ;; -(*.tar) - exec tar -xf "$1" - ;; -(*.rar) - exec unrar x "$1" - ;; -(*.zip) - exec unzip "$1" - ;; -(*.Z) - exec uncompress "$1" - ;; -(*.7z) - exec 7z x "$1" - ;; -(*.deb) - exec ar vx "$1" +(ssh://*) + exec xdg-ssh "$1" ;; (*) - [ -f "$1" ] && exec $EDITOR "$1" - [ -d "$1" ] && cd "$1" && exec "$SHELL" + exec xdg-ssh "ssh://user@localhost$1" ;; - esac