Skip to content

Add alias expand to support alias command#481

Merged
hyschive merged 4 commits intogamer-project:mainfrom
xuanweishan:fix_autocomplete_alias
Feb 12, 2026
Merged

Add alias expand to support alias command#481
hyschive merged 4 commits intogamer-project:mainfrom
xuanweishan:fix_autocomplete_alias

Conversation

@xuanweishan
Copy link
Contributor

Bug fix #424

Description

This pull request fix #424. Make user able to use autocomplete with python alias setting

Changes

  1. Add a local variable alias_expanded in /tool/config/config_autocomplete.sh with definition:
    alias_expanded=$(alias -- "${COMP_WORDS[0]}" 2>/dev/null | sed -E "s/^alias ${COMP_WORDS[0]}='([^']+)'/\1/")
  2. Add a condition for assigning variable configure_command
    • If alias_expanded is not empty: configure_command=${alias_expanded} ${COMP_WORDS[1]}
    • If alias_expanded is empty: configure_command=${COMP_WORDS[0] ${COMP_WORDS[1]}}

Tests

  • ./configure [tab] [tab]
  • python configure [tab] [tab] (w/ alias setting: `alias python="python3")
  • python3 configure [tab] [tab]

Copy link
Member

@technic960183 technic960183 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 out ELBDM HYDRO PAR_ONLY
  • python configure.py --model=H[tab] -> complete to --model=HYDRO
    And the same combination for python3, ./configure.py, and with alias python="'/home/ymhsu/under\"grad'\''s research/python'" for a path with under"grad's research.
    I hope this solution has enough completeness.

@xuanweishan
Copy link
Contributor Author

@technic960183
Thanks for the great suggestion. I've apply your suggestion in latest commit.

Copy link
Member

@technic960183 technic960183 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@hyschive hyschive merged commit 5ca5f9b into gamer-project:main Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Autocomplete alias command

3 participants