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

zsh: add completion.path #1456

Closed
wants to merge 1 commit into from

Conversation

06kellyjac
Copy link
Contributor

Description

Let users set a different location to dump the zcompdump file.
Having .zcompdump in my zsh config dir was getting annoying.

TODO:

  • This is currently a breaking change.
    • I could implement it as another option alongside the old enableCompletion?
    • or is there some method of aliasing enableCompletion to the new completion.enable?
  • Is this a clean method of adding the mkdir -p ... & -d ${cfg.completion.path}?
    • I tried doing a couple optionalStrings but it didn't look too good.
    • Open to any styling/structure advice.

Checklist

  • Change is backwards compatible.

  • Code formatted with ./format.

    • zsh.nix isn't included but I tried to keep it formatted similar to the rest of the file.
  • Code tested through nix-shell --pure tests -A run.all.

    • All OK. Ended with bash: PREEXEC_READY: unbound variable though...
  • Test cases updated/added. See example.

    • No existing completion related tests
  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

Allow for overriding the zcompdump file location to somewhere outside of
zdotdir.
@berbiche
Copy link
Member

berbiche commented Aug 26, 2020

I'm not sure how rycee handles renamed options, but I know Nix has mkRenamedOptionModule.

On another note, do you happen to know how compinit -d differs from zstyle ':completion:*' cache-path "${config.xdg.cacheHome}/zsh/completion-cache"?
I use the last one in my configuration.

@06kellyjac
Copy link
Contributor Author

06kellyjac commented Aug 26, 2020

@berbiche thanks for the reply

On another note, do you happen to know how compinit -d differs from zstyle ':completion:*' cache-path "${config.xdg.cacheHome}/zsh/completion-cache"?
I use the last one in my configuration.

I also use this setting. No idea if it does much but it's one of those I've picked up when looking for speed improvements.
My zstyle ':completion:*' ... cache file looks like the following:

modules=( ${(Q)"${(z)$(<<\EO:modules

EO:modules
)}"} )
modaliases=( ${(Q)"${(z)$(<<\EO:modaliases

EO:modaliases
)}"} )

That's the whole thing apparently.

my .zcompdump file is:
...... marking a chunk removed to keep it short

#files: 2869	version: 5.8

_comps=(
'-' '_precommand'
'-*-' '_bootctl'
'.' '_source'
'5g' '_go'
'5l' '_go'
'6g' '_go'
'6l' '_go'
'8g' '_go'
'8l' '_go'
'a2dismod' '_a2utils'
'a2dissite' '_a2utils'
......
'zypper' '_zypper'
)

_services=(
'bzcat' 'bunzip2'
......
'zf_chown' 'chown'
)

_patcomps=(
'*/(init|rc[0-9S]#).d/*' '_init_d'
)

_postpatcomps=(
'c++-*' '_gcc'
'g++-*' '_gcc'
......
'yodl(|2*)' '_yodl'
'zf*' '_zftp'
)

_compautos=(
'_call_program' '+X'
)

zle -C _bash_complete-word .complete-word _bash_completions
zle -C _bash_list-choices .list-choices _bash_completions
zle -C _complete_debug .complete-word _complete_debug
zle -C _complete_help .complete-word _complete_help
zle -C _complete_tag .complete-word _complete_tag
zle -C _correct_filename .complete-word _correct_filename
zle -C _correct_word .complete-word _correct_word
zle -C _expand_alias .complete-word _expand_alias
zle -C _expand_word .complete-word _expand_word
zle -C _history-complete-newer .complete-word _history_complete_word
zle -C _history-complete-older .complete-word _history_complete_word
zle -C _list_expansions .list-choices _expand_word
zle -C _most_recent_file .complete-word _most_recent_file
zle -C _next_tags .list-choices _next_tags
zle -C _read_comp .complete-word _read_comp
bindkey '^X^R' _read_comp
bindkey '^X?' _complete_debug
bindkey '^XC' _correct_filename
bindkey '^Xa' _expand_alias
bindkey '^Xc' _correct_word
bindkey '^Xd' _list_expansions
bindkey '^Xe' _expand_word
bindkey '^Xh' _complete_help
bindkey '^Xm' _most_recent_file
bindkey '^Xn' _next_tags
bindkey '^Xt' _complete_tag
bindkey '^X~' _bash_list-choices
bindkey '^[,' _history-complete-newer
bindkey '^[/' _history-complete-older
bindkey '^[~' _bash_complete-word

autoload -Uz _a2ps _a2utils _aap _abcde _absolute_command_paths \
            _ack _acpi _acpitool _acroread _adb \
            _add-zle-hook-widget _add-zsh-hook _alias _aliases _all_labels \
            ......
            _zsocket _zstyle _ztodo _zypper _fast-theme
autoload -Uz +X _call_program

typeset -gUa _comp_assocs
_comp_assocs=( '' )

So it's pretty different 😅
wc -l tells me it's 2472 lines long.
I've looked around for some compinit docs but I didn't find much. This was the most in-depth http://zsh.sourceforge.net/Doc/Release/Completion-System.html

Edit: That "zsh: 20 Completion System" page also mentions zstyle ':completion:*' options & says cache-path is useless without use-cache on which I also have so I'm surprised it's so empty

# ${config.xdg.cacheHome} being home-manager
ZSH_CACHE="${config.xdg.cacheHome}/zsh"
mkdir -p "$ZSH_CACHE"
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' use-cache on
COMP_CACHE_FILE="$ZSH_CACHE/zcompcache"
zstyle ':completion:*' cache-path $COMP_CACHE_FILE

@berbiche
Copy link
Member

Ehh I never bothered to check if the zcompdump was written in the right place. As it turns out the file was being created in my $ZDOTDIR all along.

@teto
Copy link
Collaborator

teto commented Sep 5, 2020

sadly zsh doesn't follow xdg standard, would setting ZDOTDIR be enough for your usecase @06kellyjac ?

@06kellyjac
Copy link
Contributor Author

sadly zsh doesn't follow xdg standard

I'm not sure I understand why that means I shouldn't change compinit's output location

would setting ZDOTDIR be enough for your usecase?

Sadly not. Setting ZDOTDIR just dumps the zcompdump file in there instead of home. But i want to change it to go to the xdg cache since it is a cache file.
If anything it would be better staying in HOME than the xdg config dir as that should only contain config, HOME is free real-estate.

This changing compinit's output location is pretty common & what I used to do before I was using home-manager for my zsh config, but theres no way to do this with the current module setup.

https://wiki.archlinux.org/index.php/XDG_Base_Directory

The zsh entry in "hardcoded" goes over what you can change to make zsh a bit more respectful of xdg

@teto
Copy link
Collaborator

teto commented Sep 5, 2020

you could try the mkRenamedOptionModule indeed. I think this could even be enabled by default.

@berbiche
Copy link
Member

berbiche commented Sep 6, 2020

mkRenamedOptionModule won't work in submodules until NixOS/nixpkgs#97023 is merged.

@stale
Copy link

stale bot commented Apr 28, 2021

Thank you for your contribution! I marked this pull request as stale due to inactivity. If this remains inactive for another 7 days, I will close this PR. Please read the relevant sections below before commenting.

If you are the original author of the PR

  • GitHub sometimes doesn't notify people who commented / reviewed a PR previously, when you (force) push commits. If you have addressed the reviews you can officially ask for a review from those who commented to you or anyone else.
  • If it is unfinished but you plan to finish it, please mark it as a draft.
  • If you don't expect to work on it any time soon, please consider closing it with a short comment encouraging someone else to pick up your work.
  • To get things rolling again, rebase the PR against the target branch and address valid comments.

If you are not the original author of the issue

  • If you want to pick up the work on this PR, please create a new PR and indicate that it supercedes and closes this PR.

@stale stale bot added the status: stale label Apr 28, 2021
@06kellyjac
Copy link
Contributor Author

I'll try and fix this up now the other PR is merged

@stale stale bot removed the status: stale label Apr 29, 2021
@stale
Copy link

stale bot commented Jul 28, 2021

Thank you for your contribution! I marked this pull request as stale due to inactivity. If this remains inactive for another 7 days, I will close this PR. Please read the relevant sections below before commenting.

If you are the original author of the PR

  • GitHub sometimes doesn't notify people who commented / reviewed a PR previously, when you (force) push commits. If you have addressed the reviews you can officially ask for a review from those who commented to you or anyone else.
  • If it is unfinished but you plan to finish it, please mark it as a draft.
  • If you don't expect to work on it any time soon, please consider closing it with a short comment encouraging someone else to pick up your work.
  • To get things rolling again, rebase the PR against the target branch and address valid comments.

If you are not the original author of the issue

  • If you want to pick up the work on this PR, please create a new PR and indicate that it supercedes and closes this PR.

@stale stale bot added the status: stale label Jul 28, 2021
@stale stale bot closed this Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants