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

hcloud: Add autocomplete support for bash and zsh #46001

Merged
merged 1 commit into from Sep 10, 2018

Conversation

uskudnik
Copy link
Contributor

@uskudnik uskudnik commented Sep 3, 2018

Motivation for this change

Currently one would need to manually run the command to generate
completion and insert it into .bashrc/.zshrc to get the
autocompletion to work. This patch will automatically generate
both docs and save them to correct position so it should continue
to work even if user changes the shell at a later stage.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

I don't personally use zsh so I didn't test that but I found the correct path in restic/default.nix so I think we should be fine. If anyone has any issues please let me know and I'll remove zsh support (better yet, much obliged if you do use zsh and can verify it works as expected 😊 ).

$bin/share/zsh/vendor-completions

$bin/bin/hcloud completion bash > "$bin/etc/bash_completion.d/hcloud"
$bin/bin/hcloud completion zsh > "$bin/share/zsh/vendor-completions/hcloud"
Copy link
Member

Choose a reason for hiding this comment

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

Did not work for me with zsh, I had to use

source <(hcloud completion zsh)

instead.

Also this variant did not work for me: https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/hcloud#n49

Copy link
Member

Choose a reason for hiding this comment

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

maybe the file needs to be _hcloud ? (that's the pattern I have previously seen).

Copy link
Member

Choose a reason for hiding this comment

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

No, this was not the problem.

Currently one would need to manually run the command to generate
completion and insert it into `.bashrc`/`.zshrc` to get the
autocompletion to work. This patch will automatically generate
both docs and save them to correct position so it should continue
to work even if user changes the shell at a later stage.
@uskudnik uskudnik force-pushed the add-hcloud-autocomplete-support branch from 5c20ca6 to d23c357 Compare September 5, 2018 00:38
@uskudnik
Copy link
Contributor Author

uskudnik commented Sep 5, 2018

@teto @Mic92 So, I'm no zsh/zsh-completion expert but I made a bit of investigation and per my understanding there are two things in play: first is the underscore - per my understanding, we need to mark it with underscore so that zsh recognizes it as a widget:

those beginning ‘_’ are called by the completion code. The shell functions of this set, which implement completion behaviour and may be bound to keystrokes, are referred to as ‘widgets’. These proliferate as new completions are required.

At least I couldn't find an explanation for filenames explicitly.

The second is that hcloud's zsh completions are missing a definition:

When compinit is run, it searches all such files accessible via fpath/FPATH and reads the first line of each of them. This line should contain one of the tags described below. Files whose first line does not start with one of these tags are not considered to be part of the completion system and will not be treated specially.

Anyway, should work now 🙂

I'll be submitting a patch upstream but it might be a while before it it gets submitted so I propose we amend the file ourselves for the time being. I'll also submit a patch for restic since it doesn't seem to work for me either until I rename it to _restic.

uskudnik added a commit to uskudnik/nixpkgs that referenced this pull request Sep 5, 2018
zsh requires for files to be prepended with underscore to be
recognized as widgets, see [1] for more details.

[1] NixOS#46001 (comment)
@uskudnik uskudnik mentioned this pull request Sep 5, 2018
9 tasks
Mic92 pushed a commit that referenced this pull request Sep 5, 2018
zsh requires for files to be prepended with underscore to be
recognized as widgets, see [1] for more details.

[1] #46001 (comment)

(cherry picked from commit e9fe3a3)
@uskudnik
Copy link
Contributor Author

uskudnik commented Sep 9, 2018

@Mic92 Since you've merged the #46080, do you have any outstanding reservation regarding this one?

@Mic92 Mic92 merged commit d5e854b into NixOS:master Sep 10, 2018
@Mic92
Copy link
Member

Mic92 commented Sep 10, 2018

backport:

[detached HEAD 0be6045] hcloud: Add autocomplete support for bash and zsh
Author: Urban Skudnik urban.skudnik@gmail.com
Date: Mon Sep 3 17:21:43 2018 +0200
1 file changed, 13 insertions(+)

@uskudnik uskudnik deleted the add-hcloud-autocomplete-support branch September 16, 2018 21:21
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.

None yet

4 participants