Nix : Add tmpshell.

This commit is contained in:
Dmitry Voronin 2024-01-28 21:27:27 +03:00
parent 0ced40b4f0
commit 8b8efad6a6
3 changed files with 14 additions and 8 deletions

View file

@ -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 <PACKAGES>
function shell() {
# Usage: nix_tmpshell <PACKAGES>
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

View file

@ -121,3 +121,8 @@ function _contains() {
function _is_tmux() {
[[ "${TERM_PROGRAM}" = "tmux" ]]
}
# Check if root.
function _is_root() {
[[ "${UID}" = 0 ]]
}

View file

@ -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 <PACKAGES>`|Spawn nix-shell with specified packages.
`nix_tmpshell <PACKAGES>`|Spawn nix-shell with specified packages.
## Notify.