mirror of
https://github.com/nix-community/home-manager
synced 2024-11-14 15:19:45 +01:00
62eb7ebeba
Added utilities to generate export statements and definitions for zsh scripts. Currently, there is only lib.shell which generates export statements in bash syntax. However, this does not allow to generate export statements for zsh arrays (syntax: NAME=(elem1 elem2 ...) ), which would be the natural representation of lists in the nix language.
28 lines
1.1 KiB
Nix
28 lines
1.1 KiB
Nix
{ lib }:
|
|
|
|
rec {
|
|
# Produces a Zsh shell like value
|
|
toZshValue = v: if builtins.isBool v then
|
|
if v then "true" else "false"
|
|
else if builtins.isString v then
|
|
"\"${v}\""
|
|
else if builtins.isList v then
|
|
"(${lib.concatStringsSep " " (map toZshValue v)})"
|
|
else "\"${toString v}\"";
|
|
|
|
# Produces a Zsh shell like definition statement
|
|
define = n: v: "${n}=${toZshValue v}";
|
|
|
|
# Given an attribute set containing shell variable names and their
|
|
# assignments, this function produces a string containing a definition
|
|
# statement for each set entry.
|
|
defineAll = vars: lib.concatStringsSep "\n" (lib.mapAttrsToList define vars);
|
|
|
|
# Produces a Zsh shell like export statement
|
|
export = n: v: "export ${define n v}";
|
|
|
|
# Given an attribute set containing shell variable names and their
|
|
# assignments, this function produces a string containing an export
|
|
# statement for each set entry.
|
|
exportAll = vars: lib.concatStringsSep "\n" (lib.mapAttrsToList export vars);
|
|
}
|