From b82bc64a0e48637fff514d222f3107575aa71c7a Mon Sep 17 00:00:00 2001 From: Mario Rodas Date: Sun, 14 Oct 2018 08:38:26 -0500 Subject: [PATCH 1/3] bash: do not evaluate /etc/bashrc on non-interactive shells --- modules/programs/bash/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/programs/bash/default.nix b/modules/programs/bash/default.nix index 0e116ae5..542b1e2e 100644 --- a/modules/programs/bash/default.nix +++ b/modules/programs/bash/default.nix @@ -52,6 +52,9 @@ in # /etc/bashrc: DO NOT EDIT -- this file has been generated automatically. # This file is read for interactive shells. + # If not running interactively, don't do anything + [[ $- != *i* ]] && return + # Make bash check its window size after a process completes shopt -s checkwinsize From dff88ee954049f174e78f062c55a7a2a98d4db19 Mon Sep 17 00:00:00 2001 From: Mario Rodas Date: Sun, 14 Oct 2018 08:39:36 -0500 Subject: [PATCH 2/3] bash: do not evaluate completions on dumb terminals --- modules/programs/bash/default.nix | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/programs/bash/default.nix b/modules/programs/bash/default.nix index 542b1e2e..1dd818d0 100644 --- a/modules/programs/bash/default.nix +++ b/modules/programs/bash/default.nix @@ -75,17 +75,19 @@ in ${cfg.interactiveShellInit} ${optionalString cfg.enableCompletion '' - source "${pkgs.bash-completion}/etc/profile.d/bash_completion.sh" + if [ "$TERM" != "dumb" ]; then + source "${pkgs.bash-completion}/etc/profile.d/bash_completion.sh" - nullglobStatus=$(shopt -p nullglob) - shopt -s nullglob - for p in $NIX_PROFILES; do - for m in "$p/etc/bash_completion.d/"* "$p/share/bash-completion/completions/"*; do - source $m + nullglobStatus=$(shopt -p nullglob) + shopt -s nullglob + for p in $NIX_PROFILES; do + for m in "$p/etc/bash_completion.d/"* "$p/share/bash-completion/completions/"*; do + source $m + done done - done - eval "$nullglobStatus" - unset nullglobStatus p m + eval "$nullglobStatus" + unset nullglobStatus p m + fi ''} # Read system-wide modifications. From 1a786eb08879d66ac67c3c584f05f3d9c2567c2b Mon Sep 17 00:00:00 2001 From: Mario Rodas Date: Tue, 16 Oct 2018 19:37:12 -0500 Subject: [PATCH 3/3] bash: place bashrc early non-interactive return below system setup Setting PATH and environment setup is required in non-interactive shells --- modules/programs/bash/default.nix | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/programs/bash/default.nix b/modules/programs/bash/default.nix index 1dd818d0..ea5afe26 100644 --- a/modules/programs/bash/default.nix +++ b/modules/programs/bash/default.nix @@ -52,12 +52,6 @@ in # /etc/bashrc: DO NOT EDIT -- this file has been generated automatically. # This file is read for interactive shells. - # If not running interactively, don't do anything - [[ $- != *i* ]] && return - - # Make bash check its window size after a process completes - shopt -s checkwinsize - [ -r "/etc/bashrc_$TERM_PROGRAM" ] && . "/etc/bashrc_$TERM_PROGRAM" # Only execute this file once per shell. @@ -69,6 +63,13 @@ in export PATH=${config.environment.systemPath} ${config.system.build.setEnvironment.text} + + # Return early if not running interactively, but after basic nix setup. + [[ $- != *i* ]] && return + + # Make bash check its window size after a process completes + shopt -s checkwinsize + ${config.system.build.setAliases.text} ${config.environment.interactiveShellInit}