dot

packages and services management
Log | Files | Refs | README

commit 3a6e316d186aceee7b704f18c1d881a4f872d910
parent 915db33f5974f32e99770b670233dccb40fa28cd
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Fri, 11 Aug 2017 15:26:49 +0200

iomenu/bin/io, abduco/bin/abduco-list: merged the two scripts

this permits me to remove 33 lines of useless shell script and
make the resulting script fitting into one reasonable screen

Diffstat:
Dabduco/bin/abduco-list | 49-------------------------------------------------
Miomenu/bin/io | 47+++++++++++++++++++++++++++++------------------
Miomenu/bin/io-cache | 83++++++++++++++++++++++++++++++++++++++++++-------------------------------------
3 files changed, 73 insertions(+), 106 deletions(-)

diff --git a/abduco/bin/abduco-list b/abduco/bin/abduco-list @@ -1,49 +0,0 @@ -# attach to an abduco sessions and manage the names - - -export LC_COLLATE=C - - -mkdir -p "$HOME/.abduco" -touch "$HOME/.abduco/names" - - -# --- option ------------------------------------------------------------------- - -[ "$1" = -n ] && A=-n && shift || A=-A - -if [ $# = 1 ] -then - name="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" - set -- $EDITOR "$1" - -elif [ $# -gt 1 ] -then - name="$1" - shift -fi - - -# --- update session names ----------------------------------------------------- - -hash=$(printf %s "$name" | cksum | cut -d ' ' -f 1) - -{ - [ "$#" -gt 0 ] && printf '%s %s\n' "$hash" "$name" - - { - abduco | awk -v FS='\t' 'NR > 1 { printf("-e\n%s\n", $3); }' - printf '%s\n' "$HOME/.abduco/names" - - } | xargs grep -F - -} | sort -k 1,1 -u -o "$HOME/.abduco/names" - -if [ "$#" -gt 0 ] -then - [ "$SSH_TTY" ] && e='^\' || e='^Z' - [ "$ABDUCO" != "$1" ] && - ABDUCO=$1 exec abduco -e "$e" $A "$hash" "$@" -else - sed 's/[^ ]* //' "$HOME/.abduco/names" | sort -fi diff --git a/iomenu/bin/io b/iomenu/bin/io @@ -1,32 +1,43 @@ -# execute one item as argument of a program +# attach to an abduco sessions and manage the names -[ "$ABDUCO" != dvtm ] && [ "$ABDUCO" ] && exit 1 +export LC_COLLATE=C +mkdir -p "$HOME/.abduco" +touch "$HOME/.abduco/names" -# --- select ------------------------------------------------------------------- -selection=$({ +# --- session name ------------------------------------------------------------- - printf '# %s\n' abduco - abduco-list +grep -F -e "$( + abduco | awk -F '\t' 'NR > 1 { print $3 }' +)" "$HOME/.abduco/names" | sort -ouk 2,2 "$HOME/.abduco/names" - cat "$HOME/var/cache/io" - printf '# %s\n' uri - cat "$HOME"/lib/url/* "$PKG/lib/url" - cut -d ' ' -f 1 "$HOME/.ssh/known_hosts" | sed -r 's|^|ssh://root@|' +# --- arguments ---------------------------------------------------------------- -} | iomenu -p io -s -h | cut -c 3-) +if [ $# -gt 0 ] +then + for path in "$@"; do :; done # set path to last arg +else + selection=$({ + cut -d ' ' -f 3- "$HOME/.abduco/names" + cat "$VAR/cache/io" + } | iomenu -p io -s -h | sed 's/# //') -command="${selection%% *}" -path="${selection#* }" + command=$(printf %s "$selection" | cut -d ' ' -f 1) + path=$( printf %s "$selection" | cut -d ' ' -f 2-) + set -- $command "$path" +fi -# --- run ---------------------------------------------------------------------- +[ $# = 1 ] && set -- $EDITOR "$@" -printf '\033[H\033[2J' +hash=$(printf %s "$path" | cksum | cut -d ' ' -f 1) -cd "$(dirname "$path")" +printf '%s %s\n' "$hash" "$path" >> "$HOME/.abduco/names" +sort -ouk 2,2 "$HOME/.abduco/names" "$HOME/.abduco/names" -command -v "${command%% *}" && [ "$path" ] && -exec abduco-list "$path" $command "$path" +# --- attach ------------------------------------------------------------------- + +[ "$SSH_TTY" ] && e='^\' || e='^Z' +[ "$ABDUCO" != "$hash" ] && ABDUCO=$hash exec abduco -e "$e" -A "$hash" "$@" diff --git a/iomenu/bin/io-cache b/iomenu/bin/io-cache @@ -8,56 +8,61 @@ find "$HOME" \ -path "*/.hg/*" -prune -o \ -path "${MAIL%/*}/*/*" -prune -o \ -type d -exec printf '%s/\n' {} + -o \ - -print 2> /dev/null | sort | + -print 2> /dev/null | sort | { -awk -v MAIL="${MAIL%/*}" ' + awk -v MAIL="${MAIL%/*}" ' - $0 ~ ENVIRON["VAR"] "/irc/.*/$" { - ircv[ircc++] = $0 - } + $0 ~ ENVIRON["VAR"] "/irc/.*/$" { + ircv[ircc++] = $0 + } - $0 ~ MAIL "/*/" { - mailv[mailc++] = $0 - } + $0 ~ MAIL "/*/" { + mailv[mailc++] = $0 + } - $0 ~ "/[.]git/$" || - $0 ~ "/src/[^/]*/$" && - $0 !~ "/git/.*/src/" && - $0 !~ "/src/.*/src/" { - sub("/[.]git/$", "/") - searchv[searchc++] = $0 - } + $0 ~ "/[.]git/$" || + $0 ~ "/src/[^/]*/$" && + $0 !~ "/git/.*/src/" && + $0 !~ "/src/.*/src/" { + sub("/[.]git/$", "/") + searchv[searchc++] = $0 + } - $0 ~ VAR "/music" { - musicv[musicc++] = $0 - } + $0 ~ VAR "/music" { + musicv[musicc++] = $0 + } - $0 ~ ".*\\.[1-9]p?(.gz)?$" { - manv[manc++] = $0 - } + $0 ~ ".*\\.[1-9]p?(.gz)?$" { + manv[manc++] = $0 + } - $0 !~ "/$" { - filesv[filesc++] = $0 - } + $0 !~ "/$" { + filesv[filesc++] = $0 + } - END { - print "# ii-client" - for (i = 0; i < ircc; i++) print(ircv[i] ) + END { + print "# ii-client" + for (i = 0; i < ircc; i++) print(ircv[i] ) - print "# io-mail" - for (i = 0; i < mailc; i++) print(mailv[i] ) + print "# io-mail" + for (i = 0; i < mailc; i++) print(mailv[i] ) - print "# io-search" - for (i = 0; i < searchc; i++) print(searchv[i]) + print "# io-search" + for (i = 0; i < searchc; i++) print(searchv[i]) - print "# io-music" - for (i = 0; i < musicc; i++) print(musicv[i] ) + print "# io-music" + for (i = 0; i < musicc; i++) print(musicv[i] ) - print "# mandoc -a" - for (i = 0; i < manc; i++) print(manv[i] ) + print "# mandoc -a" + for (i = 0; i < manc; i++) print(manv[i] ) - print "# " ENVIRON["EDITOR"] - for (i = 0; i < filesc; i++) print(filesv[i] ) - } + print "# " ENVIRON["EDITOR"] + for (i = 0; i < filesc; i++) print(filesv[i] ) + } -' > "$VAR/cache/io" + ' + printf '# uri\n' + cat "$HOME/lib/url"/* "$PKG/lib/url" + cut -d ' ' -f 1 "$HOME/.ssh/known_hosts" | sed -r 's|^|ssh://root@|' + +} > "$VAR/cache/io"