From: Ian Kelling Date: Tue, 19 Nov 2024 16:42:53 +0000 (-0500) Subject: minor fixes, new funcs, delete duplicate func X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=4fef7c00b5cd1408701c5a8a1f74a3b0a79fff64;p=distro-setup minor fixes, new funcs, delete duplicate func --- diff --git a/brc b/brc index 9ba1512..e668afd 100644 --- a/brc +++ b/brc @@ -4210,6 +4210,11 @@ fe() { # succeeds, add it to ${f[@]}; # # The first arg that is an existing file starts the FILES args, or an arg "-". +# +# example shortening: +# for f in *; do t -x $a && sk $a; done +# becomes +# fm t -x *; fe sk fm() { local file end_arg=false in_files=false local -a files cmd @@ -4242,10 +4247,6 @@ fm() { fi done } -# example shortening: -# for f in *; do t -x $a && sk $a; done -# becomes -# fm t -x *; fe sk # execute on executables @@ -4389,8 +4390,44 @@ ep() { done } +# test shortcut t() { test "$@"; } +# cd to directory of FILE +# +# usage: cf FILE_OR_DIR +# +cf() { + local dest + dest="$1" + if [[ ! -d $dest ]]; then + dest="${dest%/*}" + fi + c "$dest" +} + + +# Run without pipe & slightly less typing: command | grep +# +# usage: cgr GR_ARGS... ,. COMMAND... +cgr() { + local arg in_cmd=false + local -a cmd grep + for arg; do + if [[ $arg == ,. ]]; then + in_cmd=true + shift + continue + fi + if $in_cmd; then + cmd+=("$arg") + else + grep+=("$arg") + fi + shift + done + "${cmd[@]}" | gr "${grep[@]}" +} # * stuff that makes sense to be at the end diff --git a/brc2 b/brc2 index d3230ff..d7b2624 100644 --- a/brc2 +++ b/brc2 @@ -3063,45 +3063,6 @@ mns() { # mount namespace m sudm -E /usr/bin/nsenter --mount=/root/mount_namespaces/$ns "$@" } -# systemd namespace + mount namespace -sdmn() { - local ns unit user tmpf pre_check pid alt_user=false - local -a final_args - user=$USER - while [[ $1 ]]; do - case $1 in - -u) - alt_user=true - user="$2" - shift 2 - ;; - -p) - pre_check="$2" - shift 2 - ;; - *) - break - ;; - esac - done - - ns=$1 - unit=$2 - shift 2 - pid=$(servicepid $unit) - env-tmpf "$@" - if $alt_user; then - final_args=("$@") - else - final_args=(bash -c ". $tmpf") - fi - if [[ $pre_check ]]; then - sudm $pre_check - else - m sudm nsenter -t $pid -n -m mns-setup $ns - fi - m sudm nsenter -t $pid -n --mount=/root/mount_namespaces/$ns sudo -u $user -i "${final_args[@]}" -} mnsd() { # mount namespace + systemd network namespace local ns unit user tmpf pre_check pid alt_user=false @@ -3142,7 +3103,7 @@ mnsd() { # mount namespace + systemd network namespace m sudm nsenter -t $pid -n -m mns-setup $ns fi fi - m sudo nsenter -t $pid -n --mount=/root/mount_namespaces/$ns sudo -u $user -i "${final_args[@]}" + m sudm nsenter -t $pid -n --mount=/root/mount_namespaces/$ns sudo -u $user -i "${final_args[@]}" } diff --git a/distro-end b/distro-end index 0cb9679..1d6a963 100755 --- a/distro-end +++ b/distro-end @@ -1702,7 +1702,7 @@ sudo gpasswd -a $USER lpadmin # based on ubuntu wiki m /a/bin/buildscripts/go # only needed for rg. cargo takes up 11 gigs, filled up the disk on je. m /a/bin/buildscripts/rust -m /a/bin/buildscripts/misc +m /a/bin/buildscripts/textern #m /a/bin/buildscripts/pithosfly #m /a/bin/buildscripts/alacritty