From 2f97304833e5a1348306adc914f33441e169836a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 30 Jan 2013 14:05:53 +0100 Subject: [PATCH] =?UTF-8?q?Add=20an=20option=20=E2=80=98environment.intera?= =?UTF-8?q?ctiveShellInit=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is like ‘environment.shellInit’, but only for interactive shells. --- modules/programs/bash/bash.nix | 48 +++++++++++++++++++++++---------- modules/programs/bash/bashrc.sh | 7 +---- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/modules/programs/bash/bash.nix b/modules/programs/bash/bash.nix index a4afb733fa7f..4f227ad1a27e 100644 --- a/modules/programs/bash/bash.nix +++ b/modules/programs/bash/bash.nix @@ -7,7 +7,9 @@ with pkgs.lib; let - initBashCompletion = optionalString config.environment.enableBashCompletion '' + cfg = config.environment; + + initBashCompletion = optionalString cfg.enableBashCompletion '' # 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). @@ -26,7 +28,7 @@ let ''; shellAliases = concatStringsSep "\n" ( - mapAttrsFlatten (k: v: "alias ${k}='${v}'") config.environment.shellAliases + mapAttrsFlatten (k: v: "alias ${k}='${v}'") cfg.shellAliases ); options = { @@ -41,24 +43,33 @@ let PS1="\[\033]2;\h:\u:\w\007\]$PS1" fi ''; - description = " - Script used to initialized shell prompt. - "; + description = '' + Shell script code used to initialise the shell prompt. + ''; type = with pkgs.lib.types; string; }; environment.shellInit = mkOption { default = ""; example = ''export PATH=/godi/bin/:$PATH''; - description = " - Script used to initialized user shell environments. - "; + description = '' + Shell script code called during login shell initialisation. + ''; + type = with pkgs.lib.types; string; + }; + + environment.interactiveShellInit = mkOption { + default = ""; + example = ''export PATH=/godi/bin/:$PATH''; + description = '' + Shell script code called during interactive shell initialisation. + ''; type = with pkgs.lib.types; string; }; environment.enableBashCompletion = mkOption { default = false; - description = "Enable bash-completion for all interactive shells."; + description = "Enable Bash completion for all interactive shells."; type = with pkgs.lib.types; bool; }; @@ -86,7 +97,7 @@ in source = pkgs.substituteAll { src = ./profile.sh; wrapperDir = config.security.wrapperDir; - shellInit = config.environment.shellInit; + inherit (cfg) shellInit; }; target = "profile"; } @@ -96,8 +107,7 @@ in # configured properly. source = pkgs.substituteAll { src = ./bashrc.sh; - inherit (config.environment) promptInit; - inherit initBashCompletion shellAliases; + inherit (cfg) interactiveShellInit; }; target = "bashrc"; } @@ -115,6 +125,16 @@ in which = "type -P"; }; + environment.interactiveShellInit = + '' + # Check the window size after every command. + shopt -s checkwinsize + + ${cfg.promptInit} + ${initBashCompletion} + ${shellAliases} + ''; + system.build.binsh = pkgs.bashInteractive; system.activationScripts.binsh = stringAfter [ "stdio" ] @@ -122,9 +142,9 @@ in # Create the required /bin/sh symlink; otherwise lots of things # (notably the system() function) won't work. mkdir -m 0755 -p /bin - ln -sfn "${config.environment.binsh}" /bin/.sh.tmp + ln -sfn "${cfg.binsh}" /bin/.sh.tmp mv /bin/.sh.tmp /bin/sh # atomically replace /bin/sh ''; - environment.pathsToLink = optional config.environment.enableBashCompletion "/etc/bash_completion.d"; + environment.pathsToLink = optional cfg.enableBashCompletion "/etc/bash_completion.d"; } diff --git a/modules/programs/bash/bashrc.sh b/modules/programs/bash/bashrc.sh index 4615004d47cc..b7c139416c04 100644 --- a/modules/programs/bash/bashrc.sh +++ b/modules/programs/bash/bashrc.sh @@ -16,9 +16,4 @@ fi # We are not always an interactive shell. if [ -z "$PS1" ]; then return; fi -# Check the window size after every command. -shopt -s checkwinsize - -@promptInit@ -@initBashCompletion@ -@shellAliases@ +@interactiveShellInit@