dot

packages and services management
Log | Files | Refs | README

commit 01c6e8cdff9ca4ee5425e1278ac134c43fe5dfa8
parent 730ef8fd7529781d9720e73527dc6395cff566dd
Author: Josuah Demangeon <mail@josuah.net>
Date:   Wed, 11 Apr 2018 14:33:26 +0200

saner passing of the session name in xdg-abduco

Diffstat:
Mbin/xdg-abduco | 50++++++++++++++++++++------------------------------
Mbin/xdg-open | 32+++++++++++++++-----------------
2 files changed, 35 insertions(+), 47 deletions(-)

diff --git a/bin/xdg-abduco b/bin/xdg-abduco @@ -9,37 +9,27 @@ mkdir -p "$dir" touch "$dir/names" -# only keep existing session names +# only keep existing session in the names list grep -e "^$(abduco | sed -rn 's/.* ([0-9]+)$/\1/p') " "$dir/names" | sort -k2 -uo "$dir/names" +[ "$#" = 0 ] && exec cut -f 2 "$dir/names" +[ "$#" = 1 ] && exec printf 'usage: xdg-abduco <name> <args>...\n' + # get the real 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)" - -printf '\033]0;%s\a' "$2" 1>&2 - -case "$#" in -(0) - cut -f 2 "$dir/names" - ;; -(2) - printf '\033]0;%s\a' "$2" 1>&2 - - hash="$(printf %s "$2" | cksum | cut -d ' ' -f 1)" - printf '%s\t%s\n' "$hash" "$2" >> "$dir/names" - - if [ "$ABDUCO" ] - then - ABDUCO="$2" abduco -n "$hash" "$1" "$2" - printf '"%s" open in the background\n' "$2" - else - ABDUCO="$2" exec abduco -A "$hash" "$@" "$2" - fi - ;; -(*) - printf 'usage: xdg-abduco <command> <path>\n' - exit 1 - ;; -esac +name="$1" +[ ! -h "$1" ] || name="$(readlink -f "$1")" +[ ! -e "$1" ] || name="$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" +[ ! -d "$1" ] || name="$(cd "$1"; pwd)" +shift + +# set terminal title to the session name +printf '\033]0;%s\a' "$name" 1>&2 + +hash="$(printf %s "$name" | cksum | cut -d ' ' -f 1)" +printf '%s\t%s\n' "$hash" "$name" >> "$dir/names" + +[ -z "$ABDUCO" ] && ABDUCO="$name" exec abduco -A "$hash" "$@" + +ABDUCO="$name" abduco -n "$hash" "$@" +printf '"%s" open in the background\n' "$name" diff --git a/bin/xdg-open b/bin/xdg-open @@ -10,8 +10,6 @@ case "$(tty)" in ;; esac -[ "$ABDUCO" ] || exec xdg-abduco "$0" "$@" - # [scheme://][user[:pass]@]host[:port][/path] IFS=' ' read scheme user pass host port path << EOF $(xdg-uri "$1") @@ -54,7 +52,7 @@ esac case "$1" in (rfc://*) - exec rfc "$host" + exec xdg-abduco "$1" rfc "$host" ;; (git://*) user="" @@ -65,7 +63,7 @@ case "$1" in esac mkdir -p "$HOME/git/$host/$user" cd "$HOME/git/$host/$user" - exec git clone "$1" + exec xdg-abduco "$1" git clone "$1" ;; (9p://*) dir="$HOME/var/9p/$host" @@ -79,7 +77,7 @@ case "$1" in curl -o "$file" "$1" exec "$0" "$file" else - exec ftp "$1" + exec xdg-abduco "$1" ftp "$1" fi ;; (gopher://*) @@ -124,20 +122,20 @@ case "$1" in printf '/j #%s\n' "$path" > "$HOME/var/irc/$host/in" ;; (news://*) - exec links "$1" + exec xdg-abduco "$1" lynx "$1" ;; (sftp://*) [ "$port" = . ] && port='22' - exec sftp -P "$port" "$host" + exec xdg-abduco "$1" sftp -P "$port" "$host" ;; (ssh://*) [ "$port" = . ] && port="" || port="-p $port" [ "$user" = . ] && user="" || user="$user@" [ "$pass" = . ] && pass="" || pass="$" - exec ssh -Y $port "$user$host" + exec xdg-abduco "$1" ssh -Y $port "$user$host" ;; (telnet://*) - exec telnet "$port" "$host" + exec xdg-abduco "$1" telnet "$port" "$host" ;; (*://*) exec printf 'unsupported protocol\n' 1>&2 @@ -146,7 +144,7 @@ case "$1" in exec btcli add -d "$HOME/var/btpd/downloads" "$1" ;; (*.img|*.iso) - exec qemu-system-x86_64 -m 500M "$1" + exec xdg-abduco "$1" qemu-system-x86_64 -m 500M "$1" ;; (*.pdf) mupdf "$1" & @@ -158,19 +156,19 @@ case "$1" in jpg2ff < "$1" | lel & ;; (*.gif) - exec ffplay -loop 0 "$1" + exec xdg-abduco "$1" ffplay -loop 0 "$1" ;; (*.opus|*.mp3|*.flac|*.ogg|*.vorbis|*.wav|*.webm|*.mp4|*.mkv|*.ogv|*.avi) - exec ffplay "$1" + exec xdg-abduco "$1" ffplay "$1" ;; (*/music/*) - exec playdir "$1" + exec xdg-abduco "$1" playdir "$1" ;; (*.[0-9]|*.[0-9]p|*.[0-9].gz) - exec mandoc -a -T utf8 "$1" + exec xdg-abduco "$1" mandoc -a -T utf8 "$1" ;; (*.o|*.a) - exec objdump -D "$1" + exec xdg-abduco "$1" sh -c 'objdump -D "$0" | less' "$1" ;; (*.html) exec firefox "$1" @@ -218,7 +216,7 @@ case "$1" in exec ar vx "$1" ;; (*) - [ -f "$1" ] && exec $EDITOR "$1" - [ -d "$1" ] && cd "$1" && exec "$SHELL" + [ -f "$1" ] && exec xdg-abduco "$1" $EDITOR "$1" + [ -d "$1" ] && cd "$1" && exec xdg-abduco "$1" "$SHELL" ;; esac