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

Completion support in nix-shell #26031

Closed
copumpkin opened this issue May 23, 2017 · 8 comments
Closed

Completion support in nix-shell #26031

copumpkin opened this issue May 23, 2017 · 8 comments
Labels
2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: user experience

Comments

@copumpkin
Copy link
Member

We do have nice completion support for nix-env-installed programs, but as someone who primarily uses nix-shell, I'm sad to not get completions, even though man pages and other niceties work. Does anyone know what it would take to make completions work?

@matthewbauer
Copy link
Member

matthewbauer commented May 23, 2017

Just to clarify, you want completion for commands within nix-shell not for nix-shell itself? (because there definitely is at least ZSH support for completion of nix-* commands.

I wonder if we could have an output called something like "completion" that would use paths /share/bash-completion/completions and /share/zsh/site-functions? Obviously it wouldn't be a huge win for closure sizes, but would make things a little cleaner.

I have this in my .bashrc that should work:

# Check whether we're running a version of Bash that has support for
# programmable completion. If we do, enable all modules installed in
# the system (and user profile).
if shopt -q progcomp &>/dev/null; then
    . "@bash-completion@/etc/profile.d/bash_completion.sh"
    nullglobStatus=$(shopt -p nullglob)
    shopt -s nullglob
    for m in "@out@/etc/bash_completion.d/"* "@out@/share/bash-completion/completions/"*; do
        . $m
    done
    eval "$nullglobStatus"
    unset nullglobStatus p m
fi

You should be able to use that in nix-shell I think (replacing @out@ with the environment and @bash-completion@ with wherever pkgs.bash-completion is).

The problem is it's Bash-only. ZSH is alot easier:

# Tell zsh how to find installed completions
fpath+=(@out@/share/zsh/site-functions @out@/share/zsh/$ZSH_VERSION/functions)

If you want those to work "by default" I think they would need to be in nix-profile: https://github.com/NixOS/nix/blob/fb2dd3210072a03526e881cd2547cf4c2df4ba52/scripts/nix-profile.sh.in#L84. Of course the .profile is supposed to be for all

@roberth
Copy link
Member

roberth commented Nov 4, 2018

for p in ${buildInputs}; do XDG_DATA_DIRS="$XDG_DATA_DIRS:$p/share"; done

This does the trick and uses the lazy loading method of adding bash completions.
You can even run it when the nix-shell is already up, so it's quite flexible.

I suppose we could add this as a default shell hook in stdenv, or possibly in stdenv itself. I can imagine that in rare cases, build scripts use this variable, so it would fix those. I suppose it should be nativeBuildInputs in that case though...

On more thing is that we should probably check the existence of $p/share before adding it. And p should be a local variable.

Perhaps someone who's more familiar with the cross compiling stuff can chip in?

@stale
Copy link

stale bot commented Jun 3, 2020

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 3, 2020
@gomain
Copy link
Contributor

gomain commented Jul 15, 2020

important to me :)

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 15, 2020
@stale
Copy link

stale bot commented Jan 11, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 11, 2021
@roberth
Copy link
Member

roberth commented Jan 11, 2021

Almost done. I've added support for file based shells in #103501. Remember to use nativeBuildInputs.

Will write a Nix pr for the nix-shell command line.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 11, 2021
@stale
Copy link

stale bot commented Jul 11, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 11, 2021
@roberth
Copy link
Member

roberth commented Jul 11, 2021

Nixpkgs supports completion for nativeBuildInputs in shell.nix files. nix-shell -p completions can not be implemented properly in Nixpkgs itself, so here's issue NixOS/nix#4254 and a PR that solves it NixOS/nix#4452.

If completions don't work for you, it's more effective to open a new issue.

@roberth roberth closed this as completed Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: user experience
Projects
None yet
Development

No branches or pull requests

4 participants