Skip to content
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

main: Add highlighting for hashed directories with autocd and cdablevars #931

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zaidhaan
Copy link

See #930 (or at least just #930 (comment)).

What this PR does:

  • If a hashed directory foo exists and the path it resolves to also exists, it will highlight it as a hashed-command
    image

What this PR does not do:

  • Does not highlight after further Tab-complete expansion of the hashed directory, even though it should be valid
    image
    image

If this feels like enough to be a PR on its own, then you could merge. If it feels incomplete, but on the right path, someone else could offer guidance and I'll see if I can complete it or they could pick it up themselves, or if it's completely wrong then it could just be closed.

@phy1729
Copy link
Member

phy1729 commented Jul 23, 2023

I think we can take the CDABLE_VARS documentation fairly literally

          If the argument to a cd command (or an implied cd with the
          AUTO_CD option set) is not a directory, and does not begin with
          a slash, try to expand the expression as if it were preceded by
          a `~' (see the section `Filename Expansion').

and just call _zsh_highlight_main_highlighter_expand_path again, but prefixed with a tilde. Something like

    elif (( autocd && cdablevars )) && [[ ${1[1]} != / ]]; then
      _zsh_highlight_main_highlighter_expand_path "~$1"
      if [[ -d $REPLY && -x $REPLY ]]; then
        REPLY=autodirectory
        return 0
      fi

That covers the case where the path continues and the case where a username is provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants