dot

packages and services management
Log | Files | Refs | README

commit 46992c5a4d07363eed989d1e56aadc08b1701f94
parent dae2e4e5e920ae77d0b6c81f6429596c52390a46
Author: josuah <mail@josuah.net>
Date:   Wed, 16 Nov 2016 02:22:14 -0500

Added version, a version history and sync tool

Diffstat:
Mbin/build | 42+++++++++++++++++++++---------------------
Dbin/lsync | 28----------------------------
Abin/version | 197+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mbuild/iomenu | 2+-
Abuild/libtermkey | 10++++++++++
Abuild/lpeg | 8++++++++
Abuild/vis | 10++++++++++
Mshell/environment | 13++++++++++---
Avis/.config/visrc.lua | 15+++++++++++++++
9 files changed, 272 insertions(+), 53 deletions(-)

diff --git a/bin/build b/bin/build @@ -47,6 +47,27 @@ info() } +# +# Default build function, to be overriden in the build recipes scripts +# +build() +{ + for patch in $(find "$CONFIG/$1" -name '*.diff') + do + patch -p1 < "$patch" + done + + [ -f "$CONFIG/$1/config.mk" ] && cp -f "$CONFIG/$1/config.mk" . + [ -f "$CONFIG/$1/config.h" ] && cp -f "$CONFIG/$1/config.h" . + [ -f ./autogen.sh ] && ./autogen.sh + [ -f ./configure ] && ./configure --prefix="$PREFIX" + + make + make prefix="$PREFIX" PREFIX="$PREFIX" install clean + return 0 +} + + compile() { local name="$1" tar="$2" @@ -113,27 +134,6 @@ index() } -# -# Default build function, to be overriden in the build recipes scripts -# -build() -{ - for patch in $(find "$CONFIG/$1" -name '*.diff') - do - patch -p1 < "$patch" - done - - [ -f "$CONFIG/$1/config.mk" ] && cp -f "$CONFIG/$1/config.mk" . - [ -f "$CONFIG/$1/config.h" ] && cp -f "$CONFIG/$1/config.h" . - [ -f ./autogen.sh ] && ./autogen.sh - [ -f ./configure ] && ./configure --prefix="$PREFIX" - - make - make prefix="$PREFIX" PREFIX="$PREFIX" install clean - return 0 -} - - main() { mkdir -p "$PROGRAMS" "$PREFIX" diff --git a/bin/lsync b/bin/lsync @@ -1,28 +0,0 @@ -lcp() -{ - printf '%s' "cp \"$1"\ "\$2"\" -} - - -main() -{ - local dir1="$1" dir2="$2" - local path - - for dir in "$dir1" "$dir2" - do - ( - cd "$dir1" - find . -type f | xargs md5sum - ) - done | sort | uniq -u | while read -r hash file - do - printf '%s %s\n' "$hash" "$file" - done | sort | uniq -w 32 -u | while read -r hash file - do - printf '%s %s\n' "$hash" "$file" - done -} - - -main $@ diff --git a/bin/version b/bin/version @@ -0,0 +1,197 @@ +DIR='.version' + + +usage() +{ + printf '%s\n' "Usage: version OPTION COMMAND + +OPTION + none for now + +COMMAND + n, new + Create a new revision if something changed + + i, init + Make the current directory a version directory by creating + the \"$DIR\" directory. + + s, status + Print modification status of current directory + + m, merge DIR + Update the status of the current project and of DIR + comparing them in both ways. Then, proceed to file + copies to have both directories with the same versions. +" +} + + +info() +{ + local color="$1" message="$2" + + printf '%s: \033[1;3%sm%s\033[0m\n' "${0##*/}" "$color" "$message" 1>&2 +} + + +die() +{ + info 1 "$1" + exit 1 +} + + +# +# Go to the root directory of a project if any, or return error. +# +go_to_root() +{ + # go to root directory of project + while [ ! -d "$DIR" ] + do + [ "$(pwd)" = '/' ] && return 1 # error + cd .. + done + + return 0 # success +} + + +# +# Create a new revision if something changed, then return success. +# +new_version() +{ + local current="$(mktemp)" date="$(date +'%0Y-%0m-%0d-%0H-%0M-%0S')" + + # generate the md5sums + find . -type f ! -path "./$DIR/*" -exec md5sum {} \; > "$current" + + local md5="$(md5sum "$current" | cut -c 1-32)" + local last="$(ls "$DIR" | sort | tail -n 1)" + + if [ -z "${last%%*-$md5}" ] + then + rm "$current" + die "nothing changed since \"$last\"" + else + info 7 "new revision $md5" + mv "$current" "$DIR/$date-$md5" + fi + + return 0 +} + + +# +# Create a new revision of the project. +# +init() +{ + mkdir -p "$DIR" +} + +# +# Compare current and foreign trees, pull the changes to both, trying to +# merge correctly the difference. +# +merge() +{ + cd "$1" + + new_version dir | { + read -r md5 current + + + } + + local revisions="$( + { + ls "$DIR" + ls "$dir/$DIR" + } | sort + )" + local common="$(printf '%s\n' "$revisions" | uniq -d -f 1 | tail -n 1)" + + printf '%s\n' "$revisions" | tac | sed "/$common/ q" | tac +} + + +# +# Display changes since latest revision +# +status() +{ + local latest="$(ls "$DIR" | tail -n 1)" + + # list all different files between current state and latest state + find . -type f ! -path "./$DIR/*" -exec md5sum {} \; | + cat - "$DIR/$latest" | + sort -k 2 | + uniq -u | + uniq -f 1 | + while read -r md5 path + do + if [ -f "$path" ] && cut -c 35- "$DIR/$latest" | + grep -x -F "$path" > /dev/null + then + info 3 "~ $path" + elif [ -f "$path" ] + then + info 2 "+ $path" + else + info 1 "- $path" + fi + done +} + + +main() +{ + case "$1" in + n | new ) + if go_to_root + then + new_version + else + die "no \"$DIR\" found in tree" + fi + ;; + i | init ) + if (go_to_root) + then + die "already one \"$DIR\" in tree" + else + init + fi + ;; + s | status ) + if go_to_root + then + status + else + die "no \"$DIR\" found in tree" + fi + ;; + m | merge ) + if [ -d "$2" ] + then + if go_to_root + then + merge "$2" + else + die "no \"$DIR\" found in tree" + fi + else + die "\"$2\" not a directory" + fi + ;; + '' | * ) + usage + ;; + esac +} + + +main $@ diff --git a/build/iomenu b/build/iomenu @@ -1,3 +1,3 @@ # Input/Output interactive menu and completion engine. -tar=http://github.com/josuah/iomenu/archive/master.tar.gz +tar=http://repo.or.cz/iomenu.git/snapshot/b2909af8d0a15cda42fcb577be4f9aba54f0c3b7.tar.gz diff --git a/build/libtermkey b/build/libtermkey @@ -0,0 +1,10 @@ +# Processing of keyboard entry from terminal-based programs + +tar=http://www.leonerd.org.uk/code/libtermkey/libtermkey-0.18.tar.gz + +build() +{ + make PREFIX="$PREFIX" install + + ln -s "$LOCAL/lib/libtermkey.so.1.12.0" "$LOCAL/lib/libtermkey.so.1" +} diff --git a/build/lpeg b/build/lpeg @@ -0,0 +1,8 @@ +# Parsing Expression Grammars For Lua + +tar=http://www.inf.puc-rio.br/~roberto/lpeg/lpeg-1.0.0.tar.gz + +build() +{ + make "$(uname -s | tr [[:upper:]] [[:lower:]])" +} diff --git a/build/vis b/build/vis @@ -0,0 +1,10 @@ +# a highly efficient vim like text editor + +tar=http://github.com/martanne/vis/archive/master.tar.gz + +build() +{ + ./configure --prefix="$PREFIX" CFLAGS="-I$LOCAL/include" + + make install +} diff --git a/shell/environment b/shell/environment @@ -26,10 +26,18 @@ export DVTM_EDITOR="$PAGER" # DIRECTORIES #------------------------------------------------------------------------------- -export PROGRAMS="$HOME/Programs" -export CONFIG="$HOME/Config" export MAIL="$HOME/Mail/INBOX" export ENV="$HOME/.profile" + + +# CONFIG PACKAGE MANAGER +#------------------------------------------------------------------------------- + + +# DIRECTORIES + +export PROGRAMS="$HOME/Programs" +export CONFIG="$HOME/Config" export LOCAL="$HOME/.local" export XDG_DATA_HOME="$HOME/.local/share" export XDG_CONFIG_HOME="$HOME/.config" @@ -37,7 +45,6 @@ export XDG_CACHE_HOME="$HOME/.cache" # PATHS -#------------------------------------------------------------------------------- export PATH="$LOCAL/bin/$dir:$PATH" export PATH="$LOCAL/bin:$CONFIG/bin:$PATH" diff --git a/vis/.config/visrc.lua b/vis/.config/visrc.lua @@ -0,0 +1,15 @@ +-- load standard vis module, providing parts of the Lua API +require('vis') + +vis.events.start = function() + -- Your global configuration options e.g. + -- vis:command('map! normal j gj') +end + +vis.events.win_open = function(win) + -- enable syntax highlighting for known file types + vis.filetype_detect(win) + + -- Your per window configuration options e.g. + -- vis:command('set number') +end