Skip to content

Commit c4cfe13

Browse files
committed
enh: parse ~/ correctly
Signed-off-by: wxiwnd <[email protected]>
1 parent d4e841f commit c4cfe13

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

scripts/bash_pinyin_completion

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ _pinyin_completion() {
4444

4545
local cur="${COMP_WORDS[COMP_CWORD]}"
4646

47+
# Detect "~/"
48+
local homeStart
49+
if [ "${cur:0:2}" = "~/" ]; then
50+
homeStart=true
51+
else
52+
homeStart=false
53+
fi
54+
4755
# ignore empty
4856
[ -z "$cur" ] && return
4957

@@ -120,8 +128,14 @@ _pinyin_completion() {
120128
done
121129
COMPREPLY=( "${unique_compreply[@]}" )
122130

123-
# # fix space postfix
124-
# if ((${#COMPREPLY[@]} == 1)) && [[ ${COMPREPLY[0]} != */ ]]; then
125-
# compopt -o nospace 2>/dev/null
126-
# fi
131+
if [[ "$homeStart" == true ]]; then
132+
local home="$HOME"
133+
for i in "${!COMPREPLY[@]}"; do
134+
case "${COMPREPLY[$i]}" in
135+
"$home"/*)
136+
COMPREPLY[$i]="~${COMPREPLY[$i]#"$home"}"
137+
;;
138+
esac
139+
done
140+
fi
127141
}

0 commit comments

Comments
 (0)