This commit is contained in:
Shelvacu
2025-05-09 15:06:50 -07:00
committed by Shelvacu on fw
parent f2d8b5b39b
commit 37b3d883d2
2 changed files with 20 additions and 20 deletions

View File

@@ -56,7 +56,7 @@ let
echo "complete -F $completion_function_name ${name}" >> $completion_file
'';
ms_text = with_sudo: ''
minmax_args 1 3
minmax_args $# 1 3
host="$1"
session_name="''${2:-main}"
set -x
@@ -70,11 +70,14 @@ in
(script "ms" (ms_text false))
(script "mss" (ms_text true))
(script "msl" ''
exact_args 1
exact_args $# 1
host="$1"
echo 'echo "user:"; screen -ls; echo; echo "root:"; sudo screen -ls' | ssh -T "$host"
'')
(script "rmln" ''
if [[ $# == 0 ]]; then
echo "warn: no arguments passed to rmln" >&2
fi
for arg in "$@"; do
if [[ "$arg" != "-*" ]] && [[ ! -L "$arg" ]]; then
die "$arg is not a symlink"
@@ -84,7 +87,7 @@ in
'')
(script "nr" ''
# nix run nixpkgs#<thing> -- <args>
min_args 1
min_args $# 1
installable="$1"
shift
if [[ "$installable" != *'#'* ]]; then
@@ -94,7 +97,7 @@ in
'')
(script "nb" ''
# nix build nixpkgs#<thing> <args>
min_args 1
min_args $# 1
installable="$1"
shift
if [[ "$installable" != *'#'* ]]; then
@@ -104,6 +107,7 @@ in
'')
(script "ns" ''
# nix shell nixpkgs#<thing>
min_args $# 1
new_args=( )
for arg in "$@"; do
if [[ "$arg" != *'#'* ]] && [[ "$arg" != -* ]]; then
@@ -121,6 +125,7 @@ in
(simple "jcu" [journalctl "--pager-end" "-u"])
(script "list-auto-roots" ''
auto_roots="/nix/var/nix/gcroots/auto"
exact_args $# 0
echo "List of auto-added nix gcroots, excluding system profiles:"
echo
for fn in "$auto_roots/"*; do
@@ -140,7 +145,7 @@ in
];
vacu.shell.functions = {
nd = ''
min_args 1
min_args $# 1
declare -a args=("$@")
lastarg="''${args[-1]}"
if [[ "$lastarg" == "-"* ]]; then
@@ -158,7 +163,7 @@ in
nt = ''pushd "$(mktemp -d "$@")"'';
};
vacu.textChecks."vacu-shell-functions-nd" = ''
eval "$(cat ${lib.escapeShellArg pkgs.shellvaculib.file})"
source ${lib.escapeShellArg pkgs.shellvaculib.file}
function nd() {
${config.vacu.shell.functions.nd}
}
@@ -173,7 +178,7 @@ in
[[ "$PWD" == "$start/b/c" ]]
'';
vacu.textChecks."vacu-shell-functions-nt" = ''
eval "$(cat ${lib.escapeShellArg pkgs.shellvaculib.file})"
source ${lib.escapeShellArg pkgs.shellvaculib.file}
function nt() {
${config.vacu.shell.functions.nt}
}

View File

@@ -63,35 +63,30 @@ _shellvaculib_min_andor_max_args_impl() {
fi
}
_shellvaculib_minmax_args_impl() {
minmax_args() {
if [[ $# != 3 ]]; then
throw_skip 1 "expected 2 args to minmax_args, got $(( $# - 1 ))"
throw_skip 1 "expected 3 args to minmax_args, got $#"
fi
_shellvaculib_min_andor_max_args_impl "$1" "$2" "$3"
}
_shellvaculib_min_args_impl() {
min_args() {
if [[ $# != 2 ]]; then
throw_skip 1 "expected 1 arg to min_args, got $(( $# - 1 ))"
throw_skip 1 "expected 2 args to min_args, got $#"
fi
_shellvaculib_min_andor_max_args_impl "$1" "$2" "$_shellvaculib_max_args"
}
_shellvaculib_max_args_impl() {
max_args() {
if [[ $# != 2 ]]; then
throw_skip 1 "expected 1 arg to max_args, got $(( $# - 1 ))"
throw_skip 1 "expected 2 args to max_args, got $#"
fi
_shellvaculib_min_andor_max_args_impl "$1" 0 "$2"
}
_shellvaculib_exact_args_impl() {
exact_args() {
if [[ $# != 2 ]]; then
throw_skip 1 "expected 1 arg to exact_args, got $(( $# - 1 ))"
throw_skip 1 "expected 2 args to exact_args, got $#"
fi
_shellvaculib_min_andor_max_args_impl "$1" "$2" "$2"
}
alias minmax_args='_shellvaculib_minmax_args_impl $#'
alias min_args='_shellvaculib_min_args_impl $#'
alias max_args='_shellvaculib_max_args_impl $#'
alias exact_args='_shellvaculib_exact_args_impl $#'