From 60ee47d269463573b19caedcc9612d98ff8bc3dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Tue, 11 Jul 2023 14:36:07 +0200 Subject: [PATCH] renew archive-functions and aliases * new function lsarchive and treearchive * goarchive is now function not alias with more features --- aliases | 5 ++++- functions.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/aliases b/aliases index bd220a0..ae3803b 100644 --- a/aliases +++ b/aliases @@ -63,7 +63,10 @@ alias gopublic='[ -e $(xdg-user-dir PUBLICSHARE) ] && cd $(xdg-user-dir PUBLICSH alias gotempl='[ -e $(xdg-user-dir TEMPLATES) ] && cd $(xdg-user-dir TEMPLATES)' alias govideo='[ -e $(xdg-user-dir VIDEOS) ] && cd $(xdg-user-dir VIDEOS)' alias gowork='[ -e $(xdg-user-dir WORK) ] && cd $(xdg-user-dir WORK)' -alias goarchive='[ -e $(xdg-user-dir ARCHIVE) ] && cd $(xdg-user-dir ARCHIVE)' +# goarchive is now in functions.sh +# alias goarchive='[ -e $(xdg-user-dir ARCHIVE) ] && cd $(xdg-user-dir ARCHIVE)' +alias lsarchive='[ -e "$(xdg-user-dir ARCHIVE)" ] && ls -l "$(xdg-user-dir ARCHIVE)"' +alias treearchive='[ -e "$(xdg-user-dir ARCHIVE)" ] && tree "$(xdg-user-dir ARCHIVE)"' # some special locations alias godebian='cd ~/debian' diff --git a/functions.sh b/functions.sh index 38f0ef7..d3b09eb 100755 --- a/functions.sh +++ b/functions.sh @@ -1337,6 +1337,43 @@ EOF } +goarchive () { + shopt -s extglob + if [ ${#:-0} -gt 0 ] + then + case "$1" in + -h) + cat << EOF + Usage: goarchive + goarchive [0-9][0-9]* + goarchive [YYYY-MM-DD] + + if used without argument, change to $(xdg-user-dir ARCHIVE) + if argument is an positive integer, go number of snapshots back (see a list of possible snapshots) + if argument is [YYYY-MM-DD], go to snapshot from date + +EOF + ;; + + +([0-9]) ) + ardir="$(xdg-user-dir ARCHIVE)/$(ls $(xdg-user-dir ARCHIVE) |tail -n${1:-1}|head -n1)" + cat << EOF +last few archives: +$(ls $(xdg-user-dir ARCHIVE) | \ +tail -n $(( ${1:-1} * 2 )) | \ +while read i;do if [ "${i}" = "$(basename ${ardir})" ]; then printf " * %s <- chosen\n" "$i"; else printf " %s\n" "$i";fi;done) +EOF + ;; + *) + ardir="$(xdg-user-dir ARCHIVE)/${1}" + ;; + esac + [ -e ${ardir} ] && cd ${ardir} + else + [ -e "$(xdg-user-dir ARCHIVE)" ] && cd "$(xdg-user-dir ARCHIVE)" + fi +} + #EOF