dot

packages and services management
Log | Files | Refs | README

commit 750b87d2e6e52425434abb21da1353b393e8ecff
parent fdad43669a58c35f06f25f6308900ef9c306112f
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun, 18 Nov 2018 13:23:05 +0100

bring open back to its simpler form

Diffstat:
Mbin/open | 185+++++++------------------------------------------------------------------------
Ropen/extension/0 -> dot/config/open/extension/0 | 0
Ropen/extension/0p -> dot/config/open/extension/0p | 0
Ropen/extension/1 -> dot/config/open/extension/1 | 0
Ropen/extension/1p -> dot/config/open/extension/1p | 0
Ropen/extension/2 -> dot/config/open/extension/2 | 0
Ropen/extension/2p -> dot/config/open/extension/2p | 0
Ropen/extension/3 -> dot/config/open/extension/3 | 0
Ropen/extension/3p -> dot/config/open/extension/3p | 0
Ropen/extension/4 -> dot/config/open/extension/4 | 0
Ropen/extension/4p -> dot/config/open/extension/4p | 0
Ropen/extension/5 -> dot/config/open/extension/5 | 0
Ropen/extension/5p -> dot/config/open/extension/5p | 0
Ropen/extension/6 -> dot/config/open/extension/6 | 0
Ropen/extension/6p -> dot/config/open/extension/6p | 0
Ropen/extension/7 -> dot/config/open/extension/7 | 0
Ropen/extension/7p -> dot/config/open/extension/7p | 0
Ropen/extension/7z -> dot/config/open/extension/7z | 0
Ropen/extension/8 -> dot/config/open/extension/8 | 0
Ropen/extension/8p -> dot/config/open/extension/8p | 0
Ropen/extension/9 -> dot/config/open/extension/9 | 0
Ropen/extension/9p -> dot/config/open/extension/9p | 0
Ropen/extension/a -> dot/config/open/extension/a | 0
Ropen/extension/avi -> dot/config/open/extension/avi | 0
Ropen/extension/bz2 -> dot/config/open/extension/bz2 | 0
Ropen/extension/deb -> dot/config/open/extension/deb | 0
Ropen/extension/flac -> dot/config/open/extension/flac | 0
Ropen/extension/gif -> dot/config/open/extension/gif | 0
Ropen/extension/gz -> dot/config/open/extension/gz | 0
Ropen/extension/html -> dot/config/open/extension/html | 0
Ropen/extension/ics -> dot/config/open/extension/ics | 0
Ropen/extension/iso -> dot/config/open/extension/iso | 0
Ropen/extension/jpeg -> dot/config/open/extension/jpeg | 0
Ropen/extension/jpg -> dot/config/open/extension/jpg | 0
Ropen/extension/lz -> dot/config/open/extension/lz | 0
Ropen/extension/mkv -> dot/config/open/extension/mkv | 0
Ropen/extension/mp3 -> dot/config/open/extension/mp3 | 0
Ropen/extension/mp4 -> dot/config/open/extension/mp4 | 0
Ropen/extension/o -> dot/config/open/extension/o | 0
Ropen/extension/ogg -> dot/config/open/extension/ogg | 0
Ropen/extension/ogv -> dot/config/open/extension/ogv | 0
Ropen/extension/opus -> dot/config/open/extension/opus | 0
Ropen/extension/pdf -> dot/config/open/extension/pdf | 0
Ropen/extension/png -> dot/config/open/extension/png | 0
Ropen/extension/ps -> dot/config/open/extension/ps | 0
Ropen/extension/rar -> dot/config/open/extension/rar | 0
Ropen/extension/tar -> dot/config/open/extension/tar | 0
Ropen/extension/tbz -> dot/config/open/extension/tbz | 0
Ropen/extension/tgz -> dot/config/open/extension/tgz | 0
Ropen/extension/tlz -> dot/config/open/extension/tlz | 0
Ropen/extension/txz -> dot/config/open/extension/txz | 0
Ropen/extension/vorbis -> dot/config/open/extension/vorbis | 0
Ropen/extension/wav -> dot/config/open/extension/wav | 0
Ropen/extension/webm -> dot/config/open/extension/webm | 0
Ropen/extension/xz -> dot/config/open/extension/xz | 0
Ropen/extension/zip -> dot/config/open/extension/zip | 0
Adot/config/open/file | 2++
Ropen/protocol/9p -> dot/config/open/protocol/9p | 0
Ropen/protocol/ftp -> dot/config/open/protocol/ftp | 0
Ropen/protocol/git -> dot/config/open/protocol/git | 0
Ropen/protocol/gopher -> dot/config/open/protocol/gopher | 0
Ropen/protocol/http -> dot/config/open/protocol/http | 0
Ropen/protocol/https -> dot/config/open/protocol/https | 0
Ropen/protocol/news -> dot/config/open/protocol/news | 0
Ropen/protocol/sftp -> dot/config/open/protocol/sftp | 0
Ropen/protocol/ssh -> dot/config/open/protocol/ssh | 0
Ropen/protocol/telnet -> dot/config/open/protocol/telnet | 0
Ropen/protocol/vnc -> dot/config/open/protocol/vnc | 0
68 files changed, 18 insertions(+), 169 deletions(-)

diff --git a/bin/open b/bin/open @@ -1,174 +1,21 @@ -#!/bin/sh -e -# open the argument according to its name +#!/usr/bin/env execlineb +importas 1 1 +backtick -n x { whoami } importas user x +backtick -n x { homeof $user } importas home x +backtick -n x { pipeline { echo $1 } sed "s/.*\\.//" } importas protocol x +backtick -n x { pipeline { echo $1 } sed "s,://.*,," } importas extension x +importas -D ${home}/.config/open OPEN OPEN -uri='[^@:/#]+://(([^@:/#]*)@)?([^:/#]*)?(:([^/#]*))?(/([^#]*))?(#.*)?' -read -r user host port file << EOF -$(echo $1 | sed -r 's,'$uri',:\2 :\3 :\5 :\7,') -EOF -user=${user#:} host=${host#:} port=${port#:} file=${file#:} +ifelse { if { test $protocol } test -e ${OPEN}/protocol/${protocol} } + { ${OPEN}/protocol/${protocol} $1 } -test $# = 0 && exec echo 'usage: xdg-open <pattern>' +ifelse { if { test $extension } test -e ${OPEN}/extension/${extension} } + { ${OPEN}/extension/${extension} $1 } -case $1 in (*://*.onion) exec torsocks "$0" "$1" ;; esac +ifelse { if { test -d $1 } test -e ${OPEN}/file } + { ${OPEN}/file $1 } -case $1 in -('') - exit 1 - ;; -(git://*) - dir=$HOME/git/$host - case $1 in (*github.com*|*bitbucket.com*) - dir=$dir/$(dirname "$file") - esac - mkdir -p "$dir" - cd $dir - exec git clone "$1" - ;; -(9p://*) - dir=/mnt/9p/$host - mkdir -p "$dir" - exec 9pfs "$host" "$dir" - ;; -(ftp://*) - exec ftp "$1" - ;; -(gopher://*) - exec sacc "$1" - ;; -(http://*|https://*) - exec web "$1" - ;; -(irc://*) - exec echo not implemented - ;; -(news://*) - exec links "$1" - ;; -(sftp://*) - test -z "$port" && port='22' - exec sftp -P $port $host - ;; -(ssh://*) - test "$user" && host=$user@$host - test "$port" && port=-p' '$port - exec ssh $port "$host" - ;; -(telnet://*) - exec telnet "$port" "$host" - ;; -(radio://*|radios://*) - exec ffplay "$(echo "$1" | sed 's,radio,http,')" - ;; -(vnc://*) - exec vncviewer -use8 $(echo "$1" | sed 's,vnc://,,') & exit - ;; -(*://*) - exec echo unsupported protocol - ;; -(*.torrent) - exec echo "TODO: use transmission" - ;; -(*.img|*.iso) - exec qemu-system-x86_64 -m 333M "$1" - ;; -(*.ps) - exec gs "$1" & - ;; -(*.pdf) - exec 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|\ -*/music/*) - exec ffplay "$1" - ;; -(*.[0-9]|*.[0-9]p|*.[0-9].gz) - exec mandoc -a -T utf8 "$1" - ;; -(*.o) - exec sh -c "objdump -D '$1' | exec less" "$1" - ;; -(*.a) - exec nm "$1" | exec less "$1" - ;; -(*.ics) - exec sh -c "ics2txt txt '$1' | exec less" "$1" - ;; -(*.html) - exec links "$1" - ;; -(*.tgz) - file=$(echo "$1" | sed 's,.tgz$,.tar.gz,') - mv "$1" "$file" - exec xdg-open "$file" - ;; -(*.tbz) - file=$(echo "$1" | sed 's,.tbz$,.tar.bz2,') - mv "$1" "$file" - exec xdg-open "$file" - ;; -(*.txz) - file=$(echo "$1" | sed 's,.txz$,.tar.xz,') - mv "$1" "$file" - exec xdg-open "$file" - ;; -(*.tlz) - file=$(echo "$1" | sed 's,.tlz$,.tar.lz,') - mv "$1" "$file" - exec xdg-open "$file" - ;; -(*.bz2) - file=$(echo "$1" | sed 's,.bz2,,') - bzip2 -ds "$1" - exec xdg-open "$file" - ;; -(*.gz) - file=$(echo "$1" | sed 's,.gz,,') - gzip -d "$1" - exec xdg-open "$file" - ;; -(*.xz) - file=$(echo "$1" | sed 's,.xz,,') - xz -d "$1" - exec xdg-open "$file" - ;; -(*.lz) - file=$(echo "$1" | sed 's,.lz,,') - lzip -d "$1" - exec xdg-open "$file" - ;; -(*.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" - ;; -(*) - if test -d "$1" - then cd "$1" - exec $SHEL - else cd "$(dirname "$1")" - exec $EDITOR "$(basename "$1")" +ifelse { if { test -f $1 } test -e ${OPEN}/file } + { ${OPEN}/file $1 } - fi -esac +foreground { echo no handler found for $1 } exit 2 diff --git a/open/extension/0 b/dot/config/open/extension/0 diff --git a/open/extension/0p b/dot/config/open/extension/0p diff --git a/open/extension/1 b/dot/config/open/extension/1 diff --git a/open/extension/1p b/dot/config/open/extension/1p diff --git a/open/extension/2 b/dot/config/open/extension/2 diff --git a/open/extension/2p b/dot/config/open/extension/2p diff --git a/open/extension/3 b/dot/config/open/extension/3 diff --git a/open/extension/3p b/dot/config/open/extension/3p diff --git a/open/extension/4 b/dot/config/open/extension/4 diff --git a/open/extension/4p b/dot/config/open/extension/4p diff --git a/open/extension/5 b/dot/config/open/extension/5 diff --git a/open/extension/5p b/dot/config/open/extension/5p diff --git a/open/extension/6 b/dot/config/open/extension/6 diff --git a/open/extension/6p b/dot/config/open/extension/6p diff --git a/open/extension/7 b/dot/config/open/extension/7 diff --git a/open/extension/7p b/dot/config/open/extension/7p diff --git a/open/extension/7z b/dot/config/open/extension/7z diff --git a/open/extension/8 b/dot/config/open/extension/8 diff --git a/open/extension/8p b/dot/config/open/extension/8p diff --git a/open/extension/9 b/dot/config/open/extension/9 diff --git a/open/extension/9p b/dot/config/open/extension/9p diff --git a/open/extension/a b/dot/config/open/extension/a diff --git a/open/extension/avi b/dot/config/open/extension/avi diff --git a/open/extension/bz2 b/dot/config/open/extension/bz2 diff --git a/open/extension/deb b/dot/config/open/extension/deb diff --git a/open/extension/flac b/dot/config/open/extension/flac diff --git a/open/extension/gif b/dot/config/open/extension/gif diff --git a/open/extension/gz b/dot/config/open/extension/gz diff --git a/open/extension/html b/dot/config/open/extension/html diff --git a/open/extension/ics b/dot/config/open/extension/ics diff --git a/open/extension/iso b/dot/config/open/extension/iso diff --git a/open/extension/jpeg b/dot/config/open/extension/jpeg diff --git a/open/extension/jpg b/dot/config/open/extension/jpg diff --git a/open/extension/lz b/dot/config/open/extension/lz diff --git a/open/extension/mkv b/dot/config/open/extension/mkv diff --git a/open/extension/mp3 b/dot/config/open/extension/mp3 diff --git a/open/extension/mp4 b/dot/config/open/extension/mp4 diff --git a/open/extension/o b/dot/config/open/extension/o diff --git a/open/extension/ogg b/dot/config/open/extension/ogg diff --git a/open/extension/ogv b/dot/config/open/extension/ogv diff --git a/open/extension/opus b/dot/config/open/extension/opus diff --git a/open/extension/pdf b/dot/config/open/extension/pdf diff --git a/open/extension/png b/dot/config/open/extension/png diff --git a/open/extension/ps b/dot/config/open/extension/ps diff --git a/open/extension/rar b/dot/config/open/extension/rar diff --git a/open/extension/tar b/dot/config/open/extension/tar diff --git a/open/extension/tbz b/dot/config/open/extension/tbz diff --git a/open/extension/tgz b/dot/config/open/extension/tgz diff --git a/open/extension/tlz b/dot/config/open/extension/tlz diff --git a/open/extension/txz b/dot/config/open/extension/txz diff --git a/open/extension/vorbis b/dot/config/open/extension/vorbis diff --git a/open/extension/wav b/dot/config/open/extension/wav diff --git a/open/extension/webm b/dot/config/open/extension/webm diff --git a/open/extension/xz b/dot/config/open/extension/xz diff --git a/open/extension/zip b/dot/config/open/extension/zip diff --git a/dot/config/open/file b/dot/config/open/file @@ -0,0 +1,2 @@ +#!/usr/bin/env execlineb +importas 1 1 vi $1 diff --git a/open/protocol/9p b/dot/config/open/protocol/9p diff --git a/open/protocol/ftp b/dot/config/open/protocol/ftp diff --git a/open/protocol/git b/dot/config/open/protocol/git diff --git a/open/protocol/gopher b/dot/config/open/protocol/gopher diff --git a/open/protocol/http b/dot/config/open/protocol/http diff --git a/open/protocol/https b/dot/config/open/protocol/https diff --git a/open/protocol/news b/dot/config/open/protocol/news diff --git a/open/protocol/sftp b/dot/config/open/protocol/sftp diff --git a/open/protocol/ssh b/dot/config/open/protocol/ssh diff --git a/open/protocol/telnet b/dot/config/open/protocol/telnet diff --git a/open/protocol/vnc b/dot/config/open/protocol/vnc