diff options
-rw-r--r-- | Common/bashrc.m4 | 3 | ||||
-rw-r--r-- | auto_completion/cd-archive | 32 |
2 files changed, 35 insertions, 0 deletions
diff --git a/Common/bashrc.m4 b/Common/bashrc.m4 index 9f378d9..6b5b65e 100644 --- a/Common/bashrc.m4 +++ b/Common/bashrc.m4 @@ -150,3 +150,6 @@ source "$SSH_DIR/ssh-agent.env" > /dev/null m4_ifelse(DT_DISTRO, `fedora', m4_dnl source /usr/share/fzf/shell/key-bindings.bash )m4_dnl + +# Autocompletion +source DT_DOTFILES_DIR/auto_completion/cd-archive diff --git a/auto_completion/cd-archive b/auto_completion/cd-archive new file mode 100644 index 0000000..9540362 --- /dev/null +++ b/auto_completion/cd-archive @@ -0,0 +1,32 @@ +#!/bin/bash +ARCHIVE="${HOME}/Nextcloud" + +comp() { + find "${ARCHIVE}" -maxdepth $2 -type d -regextype posix-extended -regex "$1" +} + +_cda() { + if [ ! -z "$2" ]; then + local cur + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ "${#2}" = "1" ]; then + D1=$(comp "${ARCHIVE}/[0-9]-.*" 1) + target=$(printf "${D1}" | grep "$2" | xargs basename) + elif [ "${#2}" = "3" ]; then + D2=$(comp "${ARCHIVE}/[0-9]+-[^/]+/[0-9]{3}-.*" 2) + target=$(printf "${D2}" | grep "$2" | xargs basename) + elif [ "${#2}" = "6" ]; then + D3=$(comp "${ARCHIVE}/[0-9]+-[^/]+/[0-9]{3}-[^/]+/[0-9]{3}\.[0-9]{2}-.*" 3) + target=$(printf "${D3}" | grep "$2" | xargs basename) + elif [ "${#2}" = "9" ]; then + D4=$(comp "${ARCHIVE}/[0-9]+-[^/]+/[0-9]{3}-[^/]+/[0-9]{3}\.[0-9]{2}-[^/]+/[0-9]{3}\.[0-9]{2}\.[a-zA-Z]+-.*" 4) + target=$(printf "${D4}" | grep "$2" | xargs basename) + fi + echo "$target" + COMPREPLY=($(compgen -W "${target}" $cur)) + fi +} + +complete -F _cda cda |