From 447ed0fbcb5be449e977d8c094e52e2172f600d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Wed, 31 Mar 2021 20:08:24 +0200 Subject: [PATCH] bash: improve initialisation (#1850) Resolves #1843. Allows aliases to be expanded in initExtra, and adds a visible bashrcExtra option for commands that should be run in ~/.bashrc even by non-interactive shells. --- modules/programs/bash.nix | 44 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/modules/programs/bash.nix b/modules/programs/bash.nix index 60d1358d3..bcaab88e9 100644 --- a/modules/programs/bash.nix +++ b/modules/programs/bash.nix @@ -111,17 +111,6 @@ in ''; }; - bashrcExtra = mkOption { - # Hide for now, may want to rename in the future. - visible = false; - default = ""; - type = types.lines; - description = '' - Extra commands that should be added to - ~/.bashrc. - ''; - }; - initExtra = mkOption { default = ""; type = types.lines; @@ -131,6 +120,15 @@ in ''; }; + bashrcExtra = mkOption { + default = ""; + type = types.lines; + description = '' + Extra commands that should be placed in ~/.bashrc. + Note that these commands will be run even in non-interactive shells. + ''; + }; + logoutExtra = mkOption { default = ""; type = types.lines; @@ -171,19 +169,6 @@ in } )); in mkIf cfg.enable { - programs.bash.bashrcExtra = '' - # Commands that should be applied only for interactive shells. - if [[ $- == *i* ]]; then - ${historyControlStr} - - ${shoptsStr} - - ${aliasesStr} - - ${cfg.initExtra} - fi - ''; - home.file.".bash_profile".text = '' # -*- mode: sh -*- @@ -208,6 +193,17 @@ in # -*- mode: sh -*- ${cfg.bashrcExtra} + + # Commands that should be applied only for interactive shells. + [[ $- == *i* ]] || return + + ${historyControlStr} + + ${shoptsStr} + + ${aliasesStr} + + ${cfg.initExtra} ''; home.file.".bash_logout" = mkIf (cfg.logoutExtra != "") {