diff options
author | jakobst1n <jakob.stendahl@outlook.com> | 2024-04-12 12:11:24 +0200 |
---|---|---|
committer | jakobst1n <jakob.stendahl@outlook.com> | 2024-04-12 12:11:24 +0200 |
commit | 6f681b7db901d8377e26653ad6f0960f059c9a32 (patch) | |
tree | 396087b869850a8fca7f58e48bf8b113222fa3a6 | |
parent | d7c322109e9aa051b4c094a60a44e814211a9a3e (diff) | |
download | dotfiles-6f681b7db901d8377e26653ad6f0960f059c9a32.tar.gz dotfiles-6f681b7db901d8377e26653ad6f0960f059c9a32.zip |
things
-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 |