Add alias expand to support alias command#481
Conversation
technic960183
left a comment
There was a problem hiding this comment.
@xuanweishan Thanks for your contribution and sorry for the late reply.
I have investigated an edge case where the expanded of the alias itself contains spaces or quotes. (e.g. alias python="'/home/ymhsu/undergrad'\''s research/python'", where there is a folder named undergrad's research in the path.)
The solution is to store the command in an array and use eval to parse the string with complex quoting (without starting a new interactive bash).
I have proposed the modifications (7 lines in total).
Besides the 4 lines in the comments, we still need to replace another 3 lines:
all_options=$(${configure_command} --autocomplete_info=all) with all_options=$(eval "${configure_command[@]}" --autocomplete_info=all)
and 2 lines similarly for sub_options=.
Tests done
With alias python="'/home/ymhsu/undergrad'\''s research/python'":
python configure.py --[tab][tab]python configure.py --m[tab][tab]-> print out--machine= --max_patch= --mhd= --model= --mpi=python configure.py --mod[tab]-> complete to--model=python configure.py --model=[tab][tab]-> print outELBDM HYDRO PAR_ONLYpython configure.py --model=H[tab]-> complete to--model=HYDRO
And the same combination forpython3,./configure.py, and withalias python="'/home/ymhsu/under\"grad'\''s research/python'"for a path withunder"grad's research.
I hope this solution has enough completeness.
|
@technic960183 |
technic960183
left a comment
There was a problem hiding this comment.
Looks Good To Me.
Sorry for the late reply.
@xuanweishan Please help me to resolve the conversations. I do not have the permissions to do that.
Bug fix #424
Description
This pull request fix #424. Make user able to use autocomplete with python
aliassettingChanges
alias_expandedin/tool/config/config_autocomplete.shwith definition:alias_expanded=$(alias -- "${COMP_WORDS[0]}" 2>/dev/null | sed -E "s/^alias ${COMP_WORDS[0]}='([^']+)'/\1/")configure_commandalias_expandedis not empty:configure_command=${alias_expanded} ${COMP_WORDS[1]}alias_expandedis empty:configure_command=${COMP_WORDS[0] ${COMP_WORDS[1]}}Tests
./configure [tab] [tab]python configure [tab] [tab](w/aliassetting: `alias python="python3")python3 configure [tab] [tab]