From 78e4b8a7371ee23adc3aaf09d2702d9a0cfc0295 Mon Sep 17 00:00:00 2001 From: cam Date: Thu, 11 Aug 2022 18:36:49 -0500 Subject: [PATCH] complete code refactor - replace multiple grep calls with one - fix branch bug - rm useless rc file - update Makefile to use install instead of mkdir/cp - rm pointless sed call - make ls say less (and rm related awk call) --- Makefile | 10 ++++++---- v | 45 +++++++++++++++++++++++++++++++++++++++++++++ v.sh | 43 ------------------------------------------- vrc | 6 ------ 4 files changed, 51 insertions(+), 53 deletions(-) create mode 100755 v delete mode 100755 v.sh delete mode 100644 vrc diff --git a/Makefile b/Makefile index aa94db9..5e49af1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ +DESTDIR= PREFIX=/usr/local/ + install: - mkdir -p ${PREFIX}/{bin,man/man1} - cp v.sh ${PREFIX}/bin/v - cp v.1 ${PREFIX}/man/man1/ - cp vrc ${HOME}/.vrc + install -Dm755 v ${DESTDIR}${PREFIX}/bin + install -Dm644 v.1 ${DESTDIR}$(PREFIX}/man/man1 + +.PHONY install diff --git a/v b/v new file mode 100755 index 0000000..297ed30 --- /dev/null +++ b/v @@ -0,0 +1,45 @@ +#!/bin/sh +commit() +{ + ls -a | fgrep -xv -e . -e .. -e .v | xargs tar cjf "$dir/$(date +%s)" + cat >>"$dir/l" + printf '\n' >>"$dir/l" +} +rollback() +{ + [ -z "$1" ] && v=1 || v="$1" + tar xjf "$dir/$(ls -t $dir | fgrep -xv l | sed -n \"$v\"p )" +} +nuke() +{ + ls -a | fgrep -xv -e . -e .. -e .v | xargs rm -rf -- + rollback "$1" +} +branch() +{ + [ -z "$1" ] && exit 1 + mkdir -p ".v/$1" + printf '%s' "$1" >.v/b +} +merge() +{ + [ -z "$1" ] && exit 1 + tar xjf "$1" + commit +} +wipe() +{ + cd "$dir" + ls -t | fgrep -xv l | sed 1d | xargs rm -- +} +dir=".v/$(cat .v/b)" +t=$1 +shift +$(cat <<. | grep "^$t") "$@" +commit +rollback +nuke +branch +merge +wipe +. diff --git a/v.sh b/v.sh deleted file mode 100755 index fd38bd3..0000000 --- a/v.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -commit() -{ - ls -a | grep -v [.]v | grep -v ^[.]$ | grep -v ^[.][.]$ | xargs \ - tar -acf "$dir"/$(tr -dc a-z \ - >$dir/l -} -rollback() -{ - [ -z "$1" ] && v=1 || v="$1" - tar -axf "$dir"/$(ls -lt $dir |\ - awk '{print $9}' | grep -v ^l$ | sed /^$/d | sed -n "$v"p ) -} -nuke() -{ - ls -a | grep -v [.]v | grep -v ^[.]$ | grep -v ^[.][.]$ | xargs rm -rf - rollback "$1" -} -branch() -{ - [ -z "$1" ] && exit 1 - mkdir -p .v/"$1" - echo "$1" >.v/b - dir=".v/$1" -} -merge() -{ - [ -z "$1" ] && exit 1 - tar -axf "$1" - commit -} -wipe() -{ - ls -lt $dir |\ - awk '{print $9}' | grep -v ^l$ | sed /^$/d | sed 1d |\ - awk '{print "'$dir'/"$1}' | xargs rm -f -} -t=$1 -[ -z "$VCONFIG" ] && VCONFIG=$HOME/.vrc -shift -$(cat "$VCONFIG" | grep ^"$t") "$@" diff --git a/vrc b/vrc deleted file mode 100644 index bd3ba05..0000000 --- a/vrc +++ /dev/null @@ -1,6 +0,0 @@ -commit -rollback -nuke -branch -merge -wipe -- 2.11.4.GIT