[Nix-dev] comments on -r 31148 "zshprofile to load /etc/profile while emulating bash"

Marc Weber marco-oweber at gmx.de
Sat Mar 3 16:34:58 CET 2012


Excerpts from Lluís Batlle i Rossell's message of Sat Mar 03 10:24:44 +0100 2012:
> Can't this be achieved by an appropiate use of
> SYSTEM_ETC_PROFILE_HAS_BEEN_SOURCED ? We have this since long for that problem.
Then I'm outdated.

Well for git and the like I always use completion (zsh) and never had
trouble.

If people remove that one additional line from .bashrc no nixos specific
completion setup will take place.

You also need this code for nixpkgs (utilities for merging shell code
items to a script):
http://mawercer.de/~marc/multi-shell-code-2.patch
(I haven't tested this version, if there are bugs they should be easy to
fix, I just copied the diff but may have missed small details)

> Of course, I don't use zsh, and zsh users may know better whether the patch
> helps them. If it does not break my bash and does not give me headaches for the
> completion, for me it's fine. I've not read the patch though.

Let me explain in short what the patch does:

script = ''
  if [ -n "$ZSH_VERSION" ]; then
    // this is zsh
  fi

  if [ -n "$BASH_VERSION" ]; then
    // this is bash
  fi

  # for both:
  export becaues_we_all="are lazy and this worsk in most shells you can share code"
'';

get's written as:

script = [
  {
    bash = ''
      this is bash
    '';
    zsh = ''
      this is zsh
    '';
  }
  ''
    # for both:
    export becaues_we_all="are lazy and this worsk in most shells you can share code"
  ''
];

You can access both versions this way then:

  script.bash
  script.zsh


Why this design? 
- It scales: You can add support for fish etc.
- You can be lazy and use the same code for both unless somebody puts
  more efforts in
- it assumes that there exists some code which should be used only for
  bash/zsh/your-favorite-other-shell

BASH
====
Your .bashrc looks like this by default:

  # What admins think is best for you
  source /etc/bash-user-system-default.sh

  # setup completion for interactive shells (like admins like):
  if [ -n "$PS1" ]; then
    source /etc/bash-setup-completion.sh
  fi

So you can remove and opt-out easily - yet provide useful commands for
accounts nobody cares about. 

Because the code is sourced instead of being copied
to directories you can update it later by nixos-rebuild

For ZSH for some reason I don't have the completion step.

Marc Weber


More information about the nix-dev mailing list