Merge pull request #44441 from mnacamura/shell-aliases

environment.shellAliases: change default behavior
This commit is contained in:
Silvan Mosberger 2018-10-13 17:46:11 +02:00 committed by GitHub
commit d4f2f4c79d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 24 deletions

View File

@ -108,14 +108,14 @@ in
}; };
environment.shellAliases = mkOption { environment.shellAliases = mkOption {
default = {}; example = { l = null; ll = "ls -l"; };
example = { ll = "ls -l"; };
description = '' description = ''
An attribute set that maps aliases (the top level attribute names in An attribute set that maps aliases (the top level attribute names in
this option) to command strings or directly to build outputs. The this option) to command strings or directly to build outputs. The
aliases are added to all users' shells. aliases are added to all users' shells.
Aliases mapped to <code>null</code> are ignored.
''; '';
type = types.attrs; # types.attrsOf types.stringOrPath; type = with types; attrsOf (nullOr (either str path));
}; };
environment.binsh = mkOption { environment.binsh = mkOption {
@ -157,6 +157,12 @@ in
# terminal instead of logging out of X11). # terminal instead of logging out of X11).
environment.variables = config.environment.sessionVariables; environment.variables = config.environment.sessionVariables;
environment.shellAliases = mapAttrs (name: mkDefault) {
ls = "ls --color=tty";
ll = "ls -l";
l = "ls -alh";
};
environment.etc."shells".text = environment.etc."shells".text =
'' ''
${concatStringsSep "\n" (map utils.toShellPath cfg.shells)} ${concatStringsSep "\n" (map utils.toShellPath cfg.shells)}

View File

@ -33,7 +33,8 @@ let
''; '';
bashAliases = concatStringsSep "\n" ( bashAliases = concatStringsSep "\n" (
mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") cfg.shellAliases mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}")
(filterAttrs (k: v: !isNull v) cfg.shellAliases)
); );
in in
@ -59,12 +60,12 @@ in
*/ */
shellAliases = mkOption { shellAliases = mkOption {
default = config.environment.shellAliases; default = {};
description = '' description = ''
Set of aliases for bash shell. See <option>environment.shellAliases</option> Set of aliases for bash shell, which overrides <option>environment.shellAliases</option>.
for an option format description. See <option>environment.shellAliases</option> for an option format description.
''; '';
type = types.attrs; # types.attrsOf types.stringOrPath; type = with types; attrsOf (nullOr (either str path));
}; };
shellInit = mkOption { shellInit = mkOption {
@ -125,6 +126,8 @@ in
programs.bash = { programs.bash = {
shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases;
shellInit = '' shellInit = ''
if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]; then if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]; then
. ${config.system.build.setEnvironment} . ${config.system.build.setEnvironment}

View File

@ -9,7 +9,8 @@ let
cfg = config.programs.fish; cfg = config.programs.fish;
fishAliases = concatStringsSep "\n" ( fishAliases = concatStringsSep "\n" (
mapAttrsFlatten (k: v: "alias ${k} ${escapeShellArg v}") cfg.shellAliases mapAttrsFlatten (k: v: "alias ${k} ${escapeShellArg v}")
(filterAttrs (k: v: !isNull v) cfg.shellAliases)
); );
in in
@ -53,12 +54,12 @@ in
}; };
shellAliases = mkOption { shellAliases = mkOption {
default = config.environment.shellAliases; default = {};
description = '' description = ''
Set of aliases for fish shell. See <option>environment.shellAliases</option> Set of aliases for fish shell, which overrides <option>environment.shellAliases</option>.
for an option format description. See <option>environment.shellAliases</option> for an option format description.
''; '';
type = types.attrs; type = with types; attrsOf (nullOr (either str path));
}; };
shellInit = mkOption { shellInit = mkOption {
@ -99,6 +100,8 @@ in
config = mkIf cfg.enable { config = mkIf cfg.enable {
programs.fish.shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases;
environment.etc."fish/foreign-env/shellInit".text = cfge.shellInit; environment.etc."fish/foreign-env/shellInit".text = cfge.shellInit;
environment.etc."fish/foreign-env/loginShellInit".text = cfge.loginShellInit; environment.etc."fish/foreign-env/loginShellInit".text = cfge.loginShellInit;
environment.etc."fish/foreign-env/interactiveShellInit".text = cfge.interactiveShellInit; environment.etc."fish/foreign-env/interactiveShellInit".text = cfge.interactiveShellInit;

View File

@ -8,12 +8,6 @@ with lib;
config = { config = {
environment.shellAliases =
{ ls = "ls --color=tty";
ll = "ls -l";
l = "ls -alh";
};
environment.shellInit = environment.shellInit =
'' ''
# Set up the per-user profile. # Set up the per-user profile.

View File

@ -11,7 +11,8 @@ let
cfg = config.programs.zsh; cfg = config.programs.zsh;
zshAliases = concatStringsSep "\n" ( zshAliases = concatStringsSep "\n" (
mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") cfg.shellAliases mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}")
(filterAttrs (k: v: !isNull v) cfg.shellAliases)
); );
in in
@ -34,13 +35,12 @@ in
}; };
shellAliases = mkOption { shellAliases = mkOption {
default = config.environment.shellAliases; default = {};
description = '' description = ''
Set of aliases for zsh shell. Overrides the default value taken from Set of aliases for zsh shell, which overrides <option>environment.shellAliases</option>.
<option>environment.shellAliases</option>.
See <option>environment.shellAliases</option> for an option format description. See <option>environment.shellAliases</option> for an option format description.
''; '';
type = types.attrs; # types.attrsOf types.stringOrPath; type = with types; attrsOf (nullOr (either str path));
}; };
shellInit = mkOption { shellInit = mkOption {
@ -106,6 +106,8 @@ in
config = mkIf cfg.enable { config = mkIf cfg.enable {
programs.zsh.shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases;
environment.etc."zshenv".text = environment.etc."zshenv".text =
'' ''
# /etc/zshenv: DO NOT EDIT -- this file has been generated automatically. # /etc/zshenv: DO NOT EDIT -- this file has been generated automatically.