From d119871cb921915c6a62449459323ac6e0bbd0a5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 28 Jan 2022 17:14:28 -0800 Subject: [PATCH] completion/dirs --- clean_files.txt | 2 +- completion/available/dirs.completion.bash | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 7e5c3b31c7..6d9b8e7540 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -49,7 +49,7 @@ completion/available/consul.completion.bash completion/available/crystal.completion.bash completion/available/dart.completion.bash completion/available/defaults.completion.bash -#completion/available/dirs.completion.bash +completion/available/dirs.completion.bash completion/available/django.completion.bash completion/available/dmidecode.completion.bash completion/available/docker-machine.completion.bash diff --git a/completion/available/dirs.completion.bash b/completion/available/dirs.completion.bash index ba18db3241..187de36119 100644 --- a/completion/available/dirs.completion.bash +++ b/completion/available/dirs.completion.bash @@ -1,15 +1,13 @@ -#!/usr/bin/env bash -# Bash completion support for the 'dirs' plugin (commands G, R). +# shellcheck shell=bash +about-completion "Bash completion support for the 'dirs' plugin (commands G, R)." -_dirs-complete() { - local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" +function _dirs-complete() { + # parse all defined shortcuts ${BASH_IT_DIRS_BKS} + if [[ -s "${BASH_IT_DIRS_BKS:-/dev/null}" ]]; then + IFS=$'\n' read -d '' -ra COMPREPLY < <(grep -v '^#' "${BASH_IT_DIRS_BKS?}" | sed -e 's/\(.*\)=.*/\1/') + fi - # parse all defined shortcuts from ~/.dirs - if [ -r "$HOME/.dirs" ]; then - COMPREPLY=($(compgen -W "$(grep -v '^#' ~/.dirs | sed -e 's/\(.*\)=.*/\1/')" -- ${CURRENT_PROMPT}) ) - fi - - return 0 + return 0 } -complete -o default -o nospace -F _dirs-complete G R +complete -o default -o nospace -F _dirs-complete -X '!&*' G R