diff --git a/nixos/shell.nix b/nixos/shell.nix index e60ac6b..7751aa6 100644 --- a/nixos/shell.nix +++ b/nixos/shell.nix @@ -43,6 +43,31 @@ command "$VISUAL" "''${args[@]}" fi } + _set_secret_and_run() { + if [[ $# -lt 2 ]]; then + echo "Usage: _set_secret_and_run [args...]" + return 1 + fi + + local secret_file="$1" + local var_name="$2" + shift 2 + + if [[ ! -f "$secret_file" ]]; then + echo "Error: Secret file '$secret_file' not found." + return 1 + fi + + echo "Setting $var_name to secret value from $secret_file" + local old_value="''${(P)var_name}" + local secret_value=$(<"$secret_file") + export $var_name="$secret_value" + + echo "Running command: $@" + command "$@" + export $var_name="$old_value" + } + if (( $+commands[kitten] )); then alias "ssh"="kitten ssh" @@ -87,6 +112,9 @@ e = "edit"; c = "clear"; sudo = "sudo "; + bun = "_set_secret_and_run /run/secrets/npm NPM_CONFIG_TOKEN bun"; + bunx = "_set_secret_and_run /run/secrets/npm NPM_CONFIG_TOKEN bunx"; + publish = "_set_secret_and_run /run/secrets/npm NPM_CONFIG_TOKEN bun publish --access public"; s = "sudo"; };