renew archive-functions and aliases

* new function lsarchive and treearchive
* goarchive is now function not alias with more features
This commit is contained in:
Jakobus Schürz 2023-07-11 14:36:07 +02:00
parent e0adff87b8
commit 60ee47d269
2 changed files with 41 additions and 1 deletions

View file

@ -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'

View file

@ -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