dot

packages and services management
Log | Files | Refs | README

commit 7058730530e94164f954439f40ba0aca9ae9e4d6
parent fbe575366283e7b119c3d00dba6301e318e83a4d
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon, 26 Mar 2018 01:39:47 +0200

split xdg-open into multiple files

Diffstat:
M.ssh/config | 6++++++
Mbin/xdg-abduco | 6+++---
Mbin/xdg-open | 8++++----
Abin/xdg-ssh | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/xdg-store | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/xdg-uri | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 227 insertions(+), 7 deletions(-)

diff --git a/.ssh/config b/.ssh/config @@ -1,5 +1,11 @@ AddKeysToAgent yes +host ::1 + IdentityFile /mnt/key/josuah.key + +host 127.0.0.1 + IdentityFile /mnt/key/josuah.key + host nas.josuah.net IdentityFile /mnt/key/josuah.key diff --git a/bin/xdg-abduco b/bin/xdg-abduco @@ -16,9 +16,9 @@ grep -e "^$(abduco | sed -rn 's/.* ([0-9]+)$/\1/p') " "$dir/names" | sort -k2 -uo "$dir/names" # get the reas path name -! [ -h "$2" ] || set -- "$1" "$(readlink -f "$2")" -! [ -e "$2" ] || set -- "$1" "$(cd "$(dirname "$2")"; pwd)/$(basename "$2")" -! [ -d "$2" ] || set -- "$1" "$(cd "$2"; pwd)" +[ ! -h "$2" ] || set -- "$1" "$(readlink -f "$2")" +[ ! -e "$2" ] || set -- "$1" "$(cd "$(dirname "$2")"; pwd)/$(basename "$2")" +[ ! -d "$2" ] || set -- "$1" "$(cd "$2"; pwd)" case "$#" in (0) diff --git a/bin/xdg-open b/bin/xdg-open @@ -6,11 +6,11 @@ (*) ABDUCO=1 exec st -f terminus:pixelsize=16 -e xdg-open "$@" ;; esac -[ "$ABDUCO" ] || exec xdg-abduco xdg-open "$@" +[ "$ABDUCO" ] || exec xdg-abduco xdg-open "$1" -! [ -e "$1" ] || set -- "$1" "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" -! [ -h "$1" ] || set -- "$1" "$(readlink -f "$1")" -! [ -d "$1" ] || set -- "$1" "$(cd "$1"; pwd)" +[ ! -e "$1" ] || set -- "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" +[ ! -h "$1" ] || set -- "$(readlink -f "$1")" +[ ! -d "$1" ] || set -- "$(cd "$1"; pwd)" # [scheme://][user[:pass]@]host[:port][/path] IFS=' ' read scheme user pass host port path << EOF diff --git a/bin/xdg-ssh b/bin/xdg-ssh @@ -0,0 +1,104 @@ +#!/bin/sh -ex + +# get content from remote or locally the same way + +# [scheme://][user[:pass]@]host[:port][/path] +IFS=' ' read scheme user pass host port path << EOF +$(xdg-uri "$1") +EOF + +[ "$port" = . ] && port="" +[ "$user" = . ] && user="" || user="$user@" +[ -d "$1" ] && path="$path/" + +[ "$port" = . ] && ssh="ssh -P $port $host" || ssh="ssh $host" +ssh="$ssh -t . ./.profile;" + +case "$path" in +(*.pdf) + $ssh "xz -c - '$path'" | xz -d - | mupdf /dev/stdin & + exit ;; +(*.ff) + $ssh "xz -c - '$path'" | xz -d - | lel + exit ;; +(*.png|*.PNG) + $ssh "png2ff < '$path' | xz -c -" | xz -d - | lel + exit ;; +(*.jpg|*.jpeg|*.JPG|*.JPEG) + $ssh "jpg2ff < '$path' | xz -c -" | xz -d - | lel + exit ;; +(*.gif) + $ssh "xz -c - '$path'" ffplay -loop 0 "$path" + exit ;; +(*.opus|*.flac|*.ogg|*.vorbis|*.wav) + $ssh "opusenc '$path' -" | ffplay - + exit ;; +(*.webm|*.mp4|*.mkv|*.ogv|*.avi) + $ssh "xz -c - '$path'" | xz -d - | ffplay - + exit ;; +(*.[0-9]|*.[0-9]p|*/[0-9].gz) + $ssh mandoc -T utf8 "$path" | less + exit ;; +(*.torrent) + exec $ssh transmission-cli "$path" + ;; +(*/music/*) + $ssh "find '$path' -type f | sort" | while IFS='' read -r song + do xdg-ssh "$host" "$song" + done + exit ;; +(*.o|*.a) + exec $ssh "exec radare2 '$path'" + ;; +(*.tgz) + $ssh "exec mv '$path' '${path%.tgz}.tar.gz'" + exec xdg-ssh "${path%.tgz}.tar.gz" + ;; +(*.tbz) + $ssh "exec mv '$path' '${path%.tbz}.tar.bz2'" + exec xdg-ssh "$host" "${path%.tbz}.tar.bz2" + ;; +(*.txz) + $ssh "exec mv '$path' '${path%.txz}.tar.xz'" + exec xdg-ssh "$host" "${path%.txz}.tar.xz" + ;; +(*.bz2) + $ssh "exec bzip2 -ds '$path'" + exec xdg-ssh "${path%.bz2}" + ;; +(*.gz) + $ssh "exec gzip -d '$path'" + exec xdg-ssh "${path%.gz}" + ;; +(*.xz) + $ssh "exec xz -d '$path'" + exec xdg-ssh "${path%.xz}" + ;; +(*.tar) + exec $ssh "exec tar -xf '$path'" + ;; +(*.rar) + exec $ssh "exec unrar x '$path'" + ;; +(*.zip) + exec $ssh "exec unzip '$path'" + ;; +(*.Z) + exec $ssh "exec uncompress '$path'" + ;; +(*.7z) + exec $ssh "exec 7z x '$path'" + ;; +(*.deb) + exec $ssh "exec ar vx '$path'" + ;; +(*) + exec $ssh "exec $EDITOR '$path'" + ;; +('') + exec $ssh + ;; +(*/) + exec $ssh "cd '$path' && exec '$SHELL'" + ;; +esac diff --git a/bin/xdg-store b/bin/xdg-store @@ -0,0 +1,50 @@ +#!/bin/sh -e + +# get resource from remote and store them + +# usage: xdg-store <uri> + +path="" + +case "$1" in +(*vimeo.com*|*youtube.com*|*youtu.be*|*openload.co*) + mkdir -p "$HOME/lib/video/$host" + cd "$HOME/lib/video/$host" + path="$PWD/$(youtube-dl --get-filename "$1")" + youtube-dl "$1" + ;; +(*bandcamp.com*) + mkdir -p "$HOME/lib/music/$host" + cd "$HOME/lib/music/$host" + path="$PWD/$(youtube-dl --get-filename "$1")" + youtube-dl "$1" + ;; +(*.torrent) + path="$HOME/var/torrent/${path##*/}" + ;; +(*.jpg|*.JPG|*.jpeg|*.JPEG|*.png|*.PNG|*.gif|*.GIF) + path="$HOME/lib/image/$host/${path##*/}" + ;; +(*.opus|*.ogg|*.mp3|*.flac) + path="$HOME/lib/music/$host/${path##*/}" + ;; +(*.webm|*.mp4|*.mkv|*.ogv|*.avi) + path="$HOME/lib/video/$host/${path##*/}" + ;; +(*.pdf|*.ps) + path="$HOME/lib/doc/$host/${path##*/}" + ;; +(*.txt) + path="$HOME/lib/text/$host/${path##*/}" + ;; +(*.tar|*.gz|*.bz2|*.xz|*.tgz|*.tgz|*.tbz2|*.txz|*.zip|*.rar) + path="$HOME/tmp/${path##*/}" + ;; +esac + +[ "$path" ] || exit + +mkdir -p "$(dirname "$path")" +curl -o "$path" "$1" + +printf '%s\n' "$path" diff --git a/bin/xdg-uri b/bin/xdg-uri @@ -0,0 +1,60 @@ +#!/usr/bin/awk -f + +# parse an uri and return tab separated values with '.' for empty + +# It can be used in POSIX shell with: +# +# [scheme://][user[:pass]@]host[:port][/path] +#IFS=' ' read scheme user pass host port path << EOF +#$(xdg-uri) +#EOF + +# usage: xdg-uri <uri> + +BEGIN { + URI = ARGV[1]; + + 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); +}