Skip to content

Instantly share code, notes, and snippets.

@danielecook
Created November 2, 2019 20:29
Show Gist options
  • Save danielecook/f809a85050b82700999a5172cd852d60 to your computer and use it in GitHub Desktop.
Save danielecook/f809a85050b82700999a5172cd852d60 to your computer and use it in GitHub Desktop.
ls snapshots
function ls_snapshot {
if [[ -z $1 ]]; then
n_backup=1
else
n_backup=${1}
fi;
search=""
original_path=$(pwd -P)
>&2 echo -e "\e[1m${original_path}\e[21m"
path=$(pwd -P)
while [[ ${path} != ".snapshots" && $path != "/" ]];
do
s=`fd --threads 1 --full-path "$path" --absolute-path --max-depth 1 --type d --hidden "$path" --exec basename | grep '.snapshots' | wc -l`
if [ $s -gt 0 ]; then
search=${path}
path=".snapshots"
base="${original_path/${search}/}"
snapshot_dir=`ls -1 ${search}/.snapshots/ | awk -v n=${n_backup} "{if(NR==n)print}"`
>&2 echo -e "${search}/.snapshots/\e[34m${snapshot_dir}\033[0m${base}/"
ls ${search}/.snapshots/${snapshot_dir}${base}/
else
path="$(readlink -f "$path"/..)"
echo ${path}
fi;
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment