Skip to content

ENH: Parse HOME(~/) correctly #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions scripts/bash_pinyin_completion
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,21 @@ _comp_expand_glob() {
}

_pinyin_completion() {
# Check COMP_WORDS existence
if [ ${#COMP_WORDS[@]} -eq 0 ] || [ -z "${COMP_CWORD+x}" ]; then
return
fi

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

# Detect "~/"
local homeStart
if [ "${cur:0:2}" = "~/" ]; then
homeStart=true
else
homeStart=false
fi

# ignore empty
[ -z "$cur" ] && return

Expand Down Expand Up @@ -115,8 +128,14 @@ _pinyin_completion() {
done
COMPREPLY=( "${unique_compreply[@]}" )

# # fix space postfix
# if ((${#COMPREPLY[@]} == 1)) && [[ ${COMPREPLY[0]} != */ ]]; then
# compopt -o nospace 2>/dev/null
# fi
if [[ "$homeStart" == true ]]; then
local home="$HOME"
for i in "${!COMPREPLY[@]}"; do
case "${COMPREPLY[$i]}" in
"$home"/*)
COMPREPLY[$i]="~${COMPREPLY[$i]#"$home"}"
;;
esac
done
fi
}