From 8b8efad6a60afc81bf4a6e3e728a90a990bf0385 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Sun, 28 Jan 2024 21:27:27 +0300 Subject: [PATCH] Nix : Add tmpshell. --- .config/bash/module/Nix.sh | 15 ++++++++------- .config/bash/module/Util.sh | 5 +++++ .doc/Bash.md | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.config/bash/module/Nix.sh b/.config/bash/module/Nix.sh index b5948b7..407a551 100644 --- a/.config/bash/module/Nix.sh +++ b/.config/bash/module/Nix.sh @@ -60,7 +60,7 @@ function nix_upgrade() { # Free up root space. function nix_clean() { nix-collect-garbage -d - [[ "${UID}" = 0 ]] && nix-store --gc + _is_root && nix-store --gc } # Spawn shell with specified nix environment. `Main` is default. @@ -71,20 +71,21 @@ function nix_shell() { nix_shell="${name}" nix-shell ~/.config/linux/shell/"${name^}".nix } -alias mkshell="nix_shell" +alias shell="nix_shell" # Spawn nix-shell with specified packages. -# Usage: shell -function shell() { +# Usage: nix_tmpshell +function nix_tmpshell() { local pkgs="${*}" if [[ "${pkgs}" = "" ]]; then - help shell + help nix_tmpshell return 2 fi - nix-shell -p "${pkgs}" + nix_shell="tmp" nix-shell -p "${pkgs}" } +alias tmpshell="nix_tmpshell" # Autocomplete with available hosts. function _comp_hosts() { @@ -103,4 +104,4 @@ function _comp_shells() { } complete -F _comp_hosts nix_update nix_upgrade -complete -F _comp_shells nix_shell mkshell +complete -F _comp_shells nix_shell shell diff --git a/.config/bash/module/Util.sh b/.config/bash/module/Util.sh index 4910879..3b8bea7 100644 --- a/.config/bash/module/Util.sh +++ b/.config/bash/module/Util.sh @@ -121,3 +121,8 @@ function _contains() { function _is_tmux() { [[ "${TERM_PROGRAM}" = "tmux" ]] } + +# Check if root. +function _is_root() { + [[ "${UID}" = 0 ]] +} diff --git a/.doc/Bash.md b/.doc/Bash.md index 921ee53..85e6b97 100644 --- a/.doc/Bash.md +++ b/.doc/Bash.md @@ -280,7 +280,7 @@ Command|Description `nix_upgrade [HOSTNAME]`|Upgrade system. Applies after reboot. Optionally force the hostname. `nix_clean`|Free up root space. `nix_shell [NAME]`|Spawn shell with specified nix environment. `Main` is default. -`shell `|Spawn nix-shell with specified packages. +`nix_tmpshell `|Spawn nix-shell with specified packages. ## Notify.