diff options
-rw-r--r-- | Common/bashrc.m4 | 1 | ||||
-rwxr-xr-x | bin/cd-archive | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/Common/bashrc.m4 b/Common/bashrc.m4 index a2f60b9..9f378d9 100644 --- a/Common/bashrc.m4 +++ b/Common/bashrc.m4 @@ -88,6 +88,7 @@ man() { if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi +alias cda=". $HOME/bin/cd-archive" # enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile 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 |