aboutsummaryrefslogtreecommitdiff
path: root/bin/cd-archive
diff options
context:
space:
mode:
authorjakobst1n <jakob.stendahl@outlook.com>2024-03-24 18:25:38 +0100
committerjakobst1n <jakob.stendahl@outlook.com>2024-03-24 18:25:38 +0100
commit92fa101ed2c831033ecb5d8517eed11f34e343fb (patch)
tree620c68eb40144428fc52f7420df645085f5f47d4 /bin/cd-archive
parent41ee5aa3d76673460818f9855c77809a18d63057 (diff)
downloaddotfiles-92fa101ed2c831033ecb5d8517eed11f34e343fb.tar.gz
dotfiles-92fa101ed2c831033ecb5d8517eed11f34e343fb.zip
Add utility for quickly getting to places in the archive
Diffstat (limited to 'bin/cd-archive')
-rwxr-xr-xbin/cd-archive27
1 files changed, 27 insertions, 0 deletions
diff --git a/bin/cd-archive b/bin/cd-archive
new file mode 100755
index 0000000..ff152bd
--- /dev/null
+++ b/bin/cd-archive
@@ -0,0 +1,27 @@
+#!/bin/bash
+ARCHIVE="${HOME}/Nextcloud"
+
+D1=$(find "${ARCHIVE}" -maxdepth 1 -type d -regextype posix-extended -regex "${ARCHIVE}/[0-9]-.*")
+D2=$(find "${ARCHIVE}" -maxdepth 2 -type d -regextype posix-extended -regex "${ARCHIVE}/[0-9]+-[^/]+/[0-9]{3}-.*")
+D3=$(find "${ARCHIVE}" -maxdepth 3 -type d -regextype posix-extended -regex "${ARCHIVE}/[0-9]+-[^/]+/[0-9]{3}-[^/]+/[0-9]{3}\.[0-9]{2}-.*")
+D4=$(find "${ARCHIVE}" -maxdepth 4 -type d -regextype posix-extended -regex "${ARCHIVE}/[0-9]+-[^/]+/[0-9]{3}-[^/]+/[0-9]{3}\.[0-9]{2}-[^/]+/[0-9]{3}\.[0-9]{2}\.[a-zA-Z]+-.*")
+
+if [ ! -z "$1" ]; then
+ if [ "${#1}" = "1" ]; then
+ target=$(printf "${D1}" | grep "$1")
+ elif [ "${#1}" = "3" ]; then
+ target=$(printf "${D2}" | grep "$1")
+ elif [ "${#1}" = "6" ]; then
+ target=$(printf "${D3}" | grep "$1")
+ elif [ "${#1}" = "9" ]; then
+ target=$(printf "${D4}" | grep "$1")
+ fi
+fi
+
+if [ -z "$target" ]; then
+ target=$(printf "${D1}\n${D2}\n${D3}\n${D4}" | fzf)
+fi
+
+if [ ! -z "$target" ]; then
+ cd "$target"
+fi