How can I add aliases? #214
-
Hi, I want to do something similar to the following in devshell with flake's devShells. I also use pkgs.mkShell {
# ...
shellHook = ''
alias hi='echo hi'
'';
} At first I thought pkgs.devshell.mkShell {
devshell = {
# ...
startup.shell-hook.text = ''
alias hi='echo hi'
'';
};
commands = [
# ...
];
} Next I tried |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Because direnv targets many different types of shells and handles reverting the changes when switching projects, it can only handle environment variables. This unfortunately means that things like bash aliases and function definitions are being lost. Most of the time aliases are being used as a shorthand to a longer program name. In that case, you can use the commands to generate a wrapper script: pkgs.devshell.mkShell {
commands = [
{ name = "tf"; category = "ops"; help = "terraform alias"; command = ''${tf}/bin/terraform "$@"''; }
];
} |
Beta Was this translation helpful? Give feedback.
-
I see. Thanks for your answer! |
Beta Was this translation helpful? Give feedback.
-
Bummer. The devshell command doesn't work for aliasing node with a loader and with tracing that you expect other programs invoking node to use. |
Beta Was this translation helpful? Give feedback.
-
For DSF I have alias 'alias' 🤣 module {pkgs, config, lib, ...}:
let
cfg = config.alias;
isntSH = line: builtins.match "#!/.+" line == null;
stripCo = line: builtins.replaceStrings ["# " "#"] ["" ""] line;
lines = value: lib.splitString "\n" value;
toAlias = name: value: {
name = name;
command = value;
help = with builtins; stripCo (head (filter isntSH (lines value)));
};
aliasses = builtins.attrValues (builtins.mapAttrs toAlias cfg);
in {
options.alias = lib.mkOption {
default = {};
description = "bash script to create an alias";
type = lib.types.attrsOf lib.types.string;
example.hello = "echo hello";
example.world = ''
#!/usr/bin/env python
print("world")
'';
};
config.commands = aliasses;
} Then to set a new alias do this something like this: {
alias.hi="echo hi";
} [alias]
hi = "echo hi" The icing on the cake, create command with nushell to have a nice ux (--help, static typed args), builtin yaml, toml, json, etc |
Beta Was this translation helpful? Give feedback.
Because direnv targets many different types of shells and handles reverting the changes when switching projects, it can only handle environment variables. This unfortunately means that things like bash aliases and function definitions are being lost.
Most of the time aliases are being used as a shorthand to a longer program name. In that case, you can use the commands to generate a wrapper script: