dot

packages and services management
Log | Files | Refs | README

commit 2de1648660a030ee91efe563d5970aaf6d26cab6
parent 9152f24bb447a239f23090d17586138a72cff34d
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon, 26 Mar 2018 21:40:31 +0200

back to good'ol xdg-open

Diffstat:
Mbin/xdg-open | 259+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 247 insertions(+), 12 deletions(-)

diff --git a/bin/xdg-open b/bin/xdg-open @@ -2,22 +2,116 @@ # override the xdg-open utility -[ "$DISPLAY" ] && case "$(tty)" in (/dev/pts/*|/dev/ttyp*) ;; -(*) ABDUCO=1 exec st -f terminus:pixelsize=16 -e xdg-open "$@" ;; +[ "$DISPLAY" ] && case "$(tty)" in +(/dev/pts/*|/dev/ttyp*) + ;; +(*) + exec st -f terminus:pixelsize=16 -e xdg-open "$@" + ;; esac -[ "$ABDUCO" ] || exec xdg-abduco xdg-open "$1" - -[ ! -e "$1" ] || set -- "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" -[ ! -h "$1" ] || set -- "$(readlink -f "$1")" -[ ! -d "$1" ] || set -- "$(cd "$1"; pwd)" +[ "$ABDUCO" ] || exec xdg-abduco xdg-open "$@" # [scheme://][user[:pass]@]host[:port][/path] IFS=' ' read scheme user pass host port path << EOF -$(xdg-uri "$1") +$(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); +}') EOF -case "$host" in (*.onion) [ "$TOR" ] || TOR="$1" exec torsocks "$0" "$1" ;; esac +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://*) @@ -27,6 +121,7 @@ case "$1" in user="$(dirname "$path")" ;; esac + mkdir -p "$HOME/git/$host/$user" cd "$HOME/git/$host/$user" exec git clone "$1" @@ -53,6 +148,33 @@ 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" @@ -68,13 +190,126 @@ 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" ;; -(ssh://*) - exec xdg-ssh "$1" +(*://*) + 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" ;; (*) - exec xdg-ssh "ssh://user@localhost$1" + [ -f "$1" ] && exec $EDITOR "$1" + [ -d "$1" ] && cd "$1" && exec "$SHELL" ;; + esac