From 8f42ecd8eecd848ac5a1efdff9d7db15cc89422f Mon Sep 17 00:00:00 2001
From: Peter Stephenson
Date: Wed, 27 Jan 2021 11:16:55 +0000
Subject: 47873: Improve completion within dynamic directory names
---
Completion/Base/Core/_main_complete | 14 ++++++++++++--
Completion/Zsh/Context/_subscript | 4 +++-
2 files changed, 15 insertions(+), 3 deletions(-)
(limited to 'Completion')
diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete
index 6b2cf2bcf..663f7557a 100644
--- a/Completion/Base/Core/_main_complete
+++ b/Completion/Base/Core/_main_complete
@@ -94,8 +94,18 @@ if [[ -z "$compstate[quote]" ]]; then
if [[ -o equals ]] && compset -P 1 '='; then
compstate[context]=equal
elif [[ "$PREFIX" != */* && "$PREFIX[1]" = '~' ]]; then
- compset -p 1
- compstate[context]=tilde
+ if [[ "$PREFIX" = '~['[^\]]# ]]; then
+ # Inside ~[...] should be treated as a subscript.
+ compset -p 2
+ # To be consistent, we ignore all but the contents of the square
+ # brackets.
+ compset -S '\]*'
+ compstate[context]=subscript
+ [[ -n $_comps[-subscript-] ]] && $_comps[-subscript-] && return
+ else
+ compset -p 1
+ compstate[context]=tilde
+ fi
fi
fi
diff --git a/Completion/Zsh/Context/_subscript b/Completion/Zsh/Context/_subscript
index 0c9a89ad5..0d9632864 100644
--- a/Completion/Zsh/Context/_subscript
+++ b/Completion/Zsh/Context/_subscript
@@ -1,6 +1,8 @@
#compdef -subscript-
-local expl ind osuf=']' flags sep
+local expl ind osuf flags sep
+
+[[ $ISUFFIX = *\]* ]] || osuf=\]
if [[ "$1" = -q ]]; then
compquote osuf
--
cgit v1.2.3-70-g09d2