dot

packages and services management
Log | Files | Refs | README

commit 1ae69d15ecaf89fe1b1424c4e81a0ed29a346eae
parent 19c5ec88779e884385c473af4b22808aa2d25f84
Author: josuah <mail@josuah.net>
Date:   Wed, 28 Dec 2016 20:47:44 +0000

version: non-working prototype, with full change parsing logics

Diffstat:
M.local/bin/build | 18++++++++----------
M.local/bin/play | 12++++++++----
M.local/bin/version | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
M.profile | 1+
4 files changed, 104 insertions(+), 57 deletions(-)

diff --git a/.local/bin/build b/.local/bin/build @@ -18,16 +18,14 @@ then usage() { - printf '%s\n' "\ -usage: ${0##*/} COMMAND PACKAGE - -d[ownload] Download PACKAGE's sources -i[nstall] Download then install PACKAGE -r[emove] Remove build PACKAGE and its sources -u[pdate] Delete, then download and install PACKAGE again -l[inks] Update links from ~${PROGRAMS#$HOME} to ~${LOCAL#$HOME} -v[iew] View the list of available packages" - + printf %s "\ +${0##*/} d[ownload] PKG Download PKG's sources +${0##*/} i[nstall] PKG Download then install PKG +${0##*/} r[emove] PKG Remove build PKG and its sources +${0##*/} u[pdate] PKG Delete, then download and install PKG again +${0##*/} l[inks] Update links from ~${PROGRAMS#$HOME} to ~${LOCAL#$HOME} +${0##*/} v[iew] View the list of available packages +" exit 0 } diff --git a/.local/bin/play b/.local/bin/play @@ -1,4 +1,8 @@ -for path in "$@" -do - find "$path" -type f -name '*.flac' -prin0 -done | xargs -0 mplayer +exec mplayer $( + IFS=' +' + for path in "$@" + do + find "$path" -type f -name '*.flac' | sort + done +) diff --git a/.local/bin/version b/.local/bin/version @@ -1,12 +1,17 @@ #!/bin/sh +NL=' +' + + usage() { - printf 'usage: %s COMMAND - -n[ew] create a new version entry -' "${0##*/}" + printf %s "\ +${0##*/} i[nit] create a new version directory in working directory +${0##*/} n[ew] create a new version entry +${0##*/} m[erge] TREE merge current tree with foreign TREE +" exit 1 } @@ -43,13 +48,26 @@ root() } +init() +{ + + [ "$1" ] && die "existing .version dir in $1" + mkdir -p .version + exit 0 +} + + new() { + cd "$1" && [ -d .version ] || die "no .version dir in $1" + find . -type f $(exclude .git .version) -print0 | sort -z | xargs -0 md5sum > .version/tmp md5="$(md5sum .version/tmp | cut -d ' ' -f 1)" - if [ "$md5" = "$(tail -n 1 .version/history)" ] + + if [ -f .version/history ] && + [ "$md5" = "$(tail -n 1 .version/history)" ] then rm .version/tmp die 'already at latest version' @@ -60,70 +78,96 @@ new() } -# -# -# merge() { - version="$({ - find . -type f -maxdepth 1 + [ -d "$1/.version" ] || die "no .version dir in $PWD" + [ -d "$2/.version" ] || die "no .version dir in $2" + + # find latest common revision + revision="$({ + find .version -type f ! -name history -maxdepth 1 cd "$1" || exit - find . -type f -maxdepth 1 - } | sort -r | uniq -d)" + find .version -type f ! -name history -maxdepth 1 + } | sort -r | uniq -d | head -n 1)" + revision="${revision#*.version/}" - while read -r md5 name + # generate a diff for both trees + for root in "$1" "$2" do - while read -r m n + printf '\n%s:\n' "$root" + [ -f "$root/.version/history" ] || die "no revision in $root" + + # get all changes since "$revision" + revisions="$(cat "$root/.version/history")$NL" + revisions="${revisions##*$revision$NL}" + + # generate a diff of every revision with next one + prev="$revision" + for next in $revisions do - h="$(history "$m" "$md5" "$n" "$name" "$history")" - case "$h" in - ( e ) history=e; continue ;; - ( x ) continue ;; - esac - done < "$(tac .version/history | grep -xFm 1 "$md5 $name")" + makediff "$root" "$prev" "$next" + prev="$next" + done + done } # -# Returns a character describing the change between "$m $n" and "$md5 $name": -# c: creation d: deletion m: modification r: rename x: unexistant e: equal +# 1: root of the tree for which make a diff +# 2: previous revision for the diff +# 3: next revision for the diff # -history() +makediff() { - m="$1" md5="$2" n="$3" name="$4" history="$5" h='' + printf ' %s -> %s\n' "$2" "$3" +} - [ "$m" = "$md5" ] && h="${h}m" - [ "$n" = "$name" ] && h="${h}n" - case "$h" in ( mn ) h=e ;; ( m ) h=r ;; ( n ) h=m ;; ( '' ) h=x ;; esac - case "$history$h" in - ( *[rem]x ) h=d ;; - ( *[xd] ) h=c ;; - esac +# +# Returns a string describing the change between for "$md5 $name" since last +# revision: "[c|d|m|r|x|e] <md5sum> <filename>" +# +# with m: modification r: rename x: unexistant e: equal +# +event() +{ + root="$1" revision="$2" md5="$3" name="$4" new_md5='' new_name='' + + while read -r m n + do + match='' event='' + + [ "$m" = "$md5" ] && match="${match}m" + [ "$n" = "$name" ] && match="${match}n" - printf %s "$history" "$h" + case "${event:-x}-$match" in + ( [xrmn]-mn ) event=e; break new_md5="$md5" new_name="$name" ;; + ( [xrm]-m ) event=r; new_md5="$m" ;; + ( [xrn]-n ) event=m; new_name="$n" ;; + ( x- ) event=x; ;; + esac + done < "$root/.version/$revision" + + printf '%s %s %s\n' "$event" "${new_md5:-$md5}" "${new_name:-$name}" } main() { root="$(root)" - [ "$root" ] && cd "$root" || die "could find root tree" case "$1" in - ( n | new ) - new + ( i | init ) [ $# -ne 1 ] && usage + init "$root" ;; - ( m | merge ) - [ $# -ne 2 ] && usage - root="$(cd "$2" && root)" - [ -z "$root" ] && die "could find root tree: $2" - - merge "$root" + ( n | new ) [ $# -ne 1 ] && usage + new "$root" + ;; + ( m | merge ) [ $# -ne 2 ] && usage + merge "$root" "$2" ;; - ( * ) - usage + ( * | '' ) usage ;; esac } diff --git a/.profile b/.profile @@ -16,6 +16,7 @@ . ~/.local/bin/build export ENV="$HOME/.profile" +export TZ='Europe/Paris' # mail export NAME='Josuah Demangeon'