dot

packages and services management
Log | Files | Refs | README

commit 1634351d4d86751cf5f59114056b71055ec678e9
parent ad71681893b9fe3b3cae32567e25e0a0f0c47704
Author: Josuah Demangeon <mail@josuah.net>
Date:   Tue, 30 Jan 2018 15:29:13 +0100

grow xdg-open some more

Diffstat:
Dbin/play | 9---------
Mbin/xdg-open | 179++++++++++++++++++++++++++++++++++++++++---------------------------------------
2 files changed, 91 insertions(+), 97 deletions(-)

diff --git a/bin/play b/bin/play @@ -1,9 +0,0 @@ -#!/bin/sh -e - -IFS=' -' - -find "$@" -type f | sort | while IFS='' read -r song -do - ffplay "$song" -done diff --git a/bin/xdg-open b/bin/xdg-open @@ -2,16 +2,16 @@ # override the xdg-open utility tty | grep -q -e '^/dev/pts/.*' -e '^/dev/tty.*' || -exec st -f terminus:pixelsize=16 -e "$0" "$@" +exec st -f terminus:pixelsize=16 -e "${0}" "${@}" -[ -e "$1" ] && set -- "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" -printf '\033]0;%s\a' "$1" +[ -e "${1}" ] && set -- "$(cd "$(dirname "${1}")" && pwd)/$(basename "${1}")" +printf '\033]0;%s\a' "${1}" #--- parse uri ----------------------------------------------------------------- # scheme://[user[:pass]@]host[:port][/path] IFS=' ' read scheme user pass host port path << EOF -$(printf %s "$1" | awk '{ +$(printf %s "${1}" | awk '{ gsub(" ", "%20"); gsub("\t", "%0b"); @@ -58,75 +58,75 @@ EOF #--- hierarchical uri ---------------------------------------------------------- -case $scheme in +case "${scheme}" in (9p) - dir=$HOME/.cache/9p/$address - mkdir -p "$dir" - exec doas 9pfs "$address" "$dir" + dir="${VAR}/9p/${address}" + mkdir -p "${dir}" + exec doas 9pfs "${address}" "${dir}" ;; (ftp) - exec ftp "$1" + exec ftp "${1}" ;; (git) - mkdir -p "$HOME/git/$host" - cd "$HOME/git/$host" || exit 1 - exec git clone "$1" + mkdir -p "${HOME}/git/${host}" + cd "${HOME}/git/${host}" || exit 1 + exec git clone "${1}" ;; (gopher) - exec sacc "$1" + exec sacc "${1}" ;; (http|https) - case $host in + case "${host}" in (vimeo.com|*youtube.com|*youtu.be|*openload.co*) - mkdir -p "$HOME/lib/http/video/$host" - cd "$HOME/lib/http/video/$host" - youtube-dl "$1" - exec "$0" "$HOME/lib/http/video/$host"/*${1##*[=/]}* + mkdir -p "${HOME}/lib/http/video/${host}" + cd "${HOME}/lib/http/video/${host}" + youtube-dl "${1}" + exec "${0}" "${HOME}/lib/http/video/${host}"/*${1##*[=/]}* ;; (*bandcamp.com) - mkdir -p "$HOME/lib/music/$host" - cd "$HOME/lib/music/$host" - exec youtube-dl "$1" + mkdir -p "${HOME}/lib/music/${host}" + cd "${HOME}/lib/music/${host}" + exec youtube-dl "${1}" ;; esac - case $path in + case "${path}" in (*.torrent) - mkdir -p "$HOME/.cache/torrent" - curl -Lo "$HOME/.cache/torrent/${path##*/}" "$1" - exec "$0" "$HOME/.cache/torrent/${path##*/}" + mkdir -p "${VAR}/torrent" + curl -Lo "${VAR}/torrent/${path##*/}" "${1}" + exec "${0}" "${VAR}/torrent/${path##*/}" ;; (*.jpg|*.JPG|*.jpeg|*.JPEG|*.png|*.PNG|*.gif) - mkdir -p "$HOME/lib/http/image/$host/" - curl -Lo "$HOME/lib/http/image/$host/${path##*/}" "$1" - exec "$0" "$HOME/lib/http/image/$host/${path##*/}" + mkdir -p "${HOME}/lib/http/image/${host}/" + curl -Lo "${HOME}/lib/http/image/${host}/${path##*/}" "${1}" + exec "${0}" "${HOME}/lib/http/image/${host}/${path##*/}" ;; (*.opus|*.ogg|*.mp3|*.flac) - mkdir -p "$HOME/lib/http/music/$host" - curl -Lo "$HOME/lib/http/music/$host/${path##*/}" "$1" - exec "$0" "$HOME/lib/http/music/$host/${path##*/}" + mkdir -p "${HOME}/lib/http/music/${host}" + curl -Lo "${HOME}/lib/http/music/${host}/${path##*/}" "${1}" + exec "${0}" "${HOME}/lib/http/music/${host}/${path##*/}" ;; (*.webm|*.mp4|*.mkv|*.ogv|*.avi) - mkdir -p "$HOME/lib/http/video/$host" - curl -Lo "$HOME/lib/http/video/$host/${path##*/}" "$1" - exec "$0" "$HOME/lib/http/video/$host/${path##*/}" + mkdir -p "${HOME}/lib/http/video/${host}" + curl -Lo "${HOME}/lib/http/video/${host}/${path##*/}" "${1}" + exec "${0}" "${HOME}/lib/http/video/${host}/${path##*/}" ;; (*.pdf|*.ps) - mkdir -p "$HOME/lib/http/doc" - curl -Lo "$HOME/lib/http/doc/${path##*/}" "$1" - exec "$0" "$HOME/lib/http/doc/${path##*/}" + mkdir -p "${HOME}/lib/http/doc" + curl -Lo "${HOME}/lib/http/doc/${path##*/}" "${1}" + exec "${0}" "${HOME}/lib/http/doc/${path##*/}" ;; (*.txt) - mkdir -p "$HOME/lib/http/text/$host" - curl -Lo "$HOME/lib/http/text/$host/${path##*/}" "$1" - exec "$0" "$HOME/lib/http/text/$host/${path##*/}" + mkdir -p "${HOME}/lib/http/text/${host}" + curl -Lo "${HOME}/lib/http/text/${host}/${path##*/}" "${1}" + exec "${0}" "${HOME}/lib/http/text/${host}/${path##*/}" ;; (*.gz|*.bz2|*.xz|*.tgz|*.tgz|*.tbz2|*.txz) - mkdir -p "$HOME/tmp" - curl -Lo "$HOME/tmp/${path##*/}" "$1" - exec "$0" "$HOME/tmp/${path##*/}" + mkdir -p "${HOME}/tmp" + curl -Lo "${HOME}/tmp/${path##*/}" "${1}" + exec "${0}" "${HOME}/tmp/${path##*/}" ;; (*) - exec firefox "$1" + exec firefox "${1}" ;; esac ;; @@ -138,125 +138,128 @@ case $scheme in printf '/j #%s\n' "${path}" > "${VAR}/irc/${host}/in" ;; (news) - exec retawq "$1" + exec retawq "${1}" ;; (sftp) - address=${1#*://} - address=${address%*:} - [ "$port" = . ] && port=22 - exec sftp -P "$port" "$address" + address="${1#*://}" + address="${address%*:}" + [ "${port}" = . ] && port='22' + exec sftp -P "${port}" "${address}" ;; (ssh) - address=${1#*://} - address=${address%:*} - [ "$port" = . ] && port=22 - exec ssh -p "$port" "$address" + address="${1#*://}" + address="${address%:*}" + [ "${port}" = . ] && port='22' + exec ssh -p "${port}" "${address}" ;; (telnet) - address=${1#telnet://} + address="${1#telnet://}" exec telnet "${address%:*}" "${address##*:}" ;; esac #--- short uri ----------------------------------------------------------------- -case $1 in +case "${1}" in (mailto:*) exec mcom "${1#mailto:}" ;; (magnet:*) - exec transmission-cli "$1" + exec transmission-cli "${1}" ;; esac #--- files --------------------------------------------------------------------- -[ -e "$1" ] && case "$1" in +[ -e "${1}" ] && case "${1}" in (*.torrent) - exec transmission-cli "$1" + exec transmission-cli "${1}" ;; (*.img|*.iso) exec qemu-system-x86_64 -m 500M \ -device e1000,netdev=net0 \ -netdev user,id=net0,hostfwd=tcp::5555-:22 \ - "$1" + "${1}" ;; #--- media --------------------------------------------------------------------- (*.pdf) - mupdf "$1" & + mupdf "${1}" & exit ;; (*.png|*.PNG) - png2ff < "$1" | lel & + png2ff < "${1}" | lel & exit ;; (*.jpg|*.jpeg|*.JPG|*.JPEG) - jpg2ff < "$1" | lel & + jpg2ff < "${1}" | lel & exit ;; (*.gif) - exec mplayer -loop 0 "$1" + exec mplayer -loop 0 "${1}" ;; (*.webm|*.mp4|*.mkv|*.ogv|*.avi|*.opus|*.mp3|*.flac|*.ogg) - exec ffplay "$1" + exec ffplay "${1}" ;; (*/music/*) - exec play "$1" + find "${1}" -type f | sort | while IFS='' read -r song + do + ffplay "${song}" + done ;; #--- pager --------------------------------------------------------------------- (*.[0-9]|*.[0-9]p|*.[0-9].gz) - exec mandoc -a "$1" + exec mandoc -a "${1}" ;; (*.o|*.a) - exec radare2 "$1" + exec radare2 "${1}" ;; (*.html) - exec retawq "$1" + exec retawq "${1}" ;; #--- archive ------------------------------------------------------------------- (*.tgz) - mv "$1" "${1%.tgz}.tar.gz" - exec "$0" "${1%.tgz}.tar.gz" + mv "${1}" "${1%.tgz}.tar.gz" + exec "${0}" "${1%.tgz}.tar.gz" ;; (*.tbz) - mv "$1" "${1%.tbz}.tar.bz2" - exec "$0" "${1%.tbz}.tar.bz2" + mv "${1}" "${1%.tbz}.tar.bz2" + exec "${0}" "${1%.tbz}.tar.bz2" ;; (*.txz) - mv "$1" "${1%.txz}.tar.xz" - exec "$0" "${1%.txz}.tar.xz" + mv "${1}" "${1%.txz}.tar.xz" + exec "${0}" "${1%.txz}.tar.xz" ;; (*.bz2) - bzip2 -d "$1" - exec "$0" "${1%.bz2}" + bzip2 -ds "${1}" + exec "${0}" "${1%.bz2}" ;; (*.gz) - gzip -d "$1" - exec "$0" "${1%.gz}" + gzip -d "${1}" + exec "${0}" "${1%.gz}" ;; (*.xz) - xz -d "$1" - exec "$0" "${1%.xz}" + xz -d "${1}" + exec "${0}" "${1%.xz}" ;; (*.tar) - exec tar -xf "$1" + exec tar -xf "${1}" ;; (*.rar) - exec unrar x "$1" + exec unrar x "${1}" ;; (*.zip) - exec unzip "$1" + exec unzip "${1}" ;; (*.Z) - exec uncompress "$1" + exec uncompress "${1}" ;; (*.7z) - exec 7z x "$1" + exec 7z x "${1}" ;; (*.deb) - exec ar vx "$1" + exec ar vx "${1}" ;; esac -[ -d "$1" ] && exec io-src "$1" -[ -f "$1" ] && exec $EDITOR "$1" +[ -d "${1}" ] && exec io-src "${1}" +[ -f "${1}" ] && exec ${EDITOR} "${1}"