- Minor cleanup

- Change shebangs to use 'env' in prep for NixOS (and others)
- `agenda` now has a symlink to the underlying tree structure named ".tree"
- `binbox` has more checking, being prepped for automatic export of symlinks.
- `cdz` now symlinks to the archive directory using "<archive name>.tmp". This is less confusing than a randomized extraction folder, and adds the benefit of being in the FS-tree of the original archive.
- daisy.source changes:
> Added basic debug mode.
> `ched` can now set global (all of the shell) editor or local (lackadaisical utils only) editor.
> The encoding/decoding functions have been expanded and improved. Extra checking, permissions are stored as well, `daisy_dec` can handle stdin.
- Added new functions to manage lackadaisical config: daisy_backup (runs `bak` on config files), daisy_clear (removes config files), and daisy_restore (restores config files archived using bak).
- All functions/tools prefixed with 'daisy_' are now also available prefixed with 'ld_' instead
- Added a new utility, `clip`. This utility keeps a local variable that can be set if given args and get if no args are supplied. Basically a simple clipboard local to the ptty. Supports stdin.
This commit is contained in:
Sam Hardeman 2026-01-25 18:23:05 +01:00
parent 021e4d3b44
commit 160a7763b7
13 changed files with 480 additions and 269 deletions

88
binbox
View file

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# binbox: Creates a multi-binary script that self-contains the input scripts.
# Symlinking to the resulting binary with the name of one of the original scripts will trigger
# said script. The idea is similar to `busybox`.
@ -11,6 +11,7 @@ args=$@
function help()
{
echo "$LD_BIN is a utility that allows you to generate busybox-style combined binaries."
echo "It only supports shell scripts compatible with \`bash\`."
echo "To access the original functionality of an input binary, you can either use a symlink or"
echo "call the function like so: 'combi-bin input-bin <input-bin args>."
echo ""
@ -55,32 +56,51 @@ i=0
b=0
s=0
p=0
while [ $i -lt $# ]; do
case "${args[$i]}" in
-i)
((i++))
while [ $i -lt $# ] && [[ ! "${args[$i]}" =~ ^- ]]; do
inputs+=("${args[$i]}")
file="${args[$i]}"
((i++))
((b++))
if [[ -e "$file" ]]; then
inputs+=("$file")
((b++))
else
echo "WARNING: Missing input binary: \"$file\"."
echo "Module will NOT be available!"
fi
done
continue
;;
-s)
((i++))
while [ $i -lt $# ] && [[ ! "${args[$i]}" =~ ^- ]]; do
sources+=("${args[$i]}")
file="${args[$i]}"
((i++))
((s++))
if [[ -e "$file" ]]; then
sources+=("$file")
((s++))
else
echo "WARNING: Missing input source: \"$file\"."
echo "File will NOT be sourced!"
fi
done
continue
;;
-p)
((i++))
while [ $i -lt $# ] && [[ ! "${args[$i]}" =~ ^- ]]; do
includes+=("${args[$i]}")
file="${args[$i]}"
((i++))
((p++))
if [[ -e "$file" ]]; then
includes+=("$file")
((p++))
else
echo "WARNING: Missing input include: \"$file\"."
echo "File will NOT be included!"
fi
done
continue
;;
@ -97,11 +117,6 @@ echo "Include files: ${includes[*]}"
echo "Source files: ${sources[*]}"
echo "Output binary: $output"
if [ "$b" -eq 0 ]; then
echo "Missing input binaries!"
exit 1
fi
if [[ "$output" == "" ]]; then
echo "Missing output file!"
exit 1
@ -112,11 +127,16 @@ function add()
echo "$@" >> "$output"
}
function add_nn()
{
echo -n "$@" >> "$output"
}
rm -rf "$output"
# Now to construct the binary
# >>> Section 1, includes
add "#!/bin/bash"
add "#!/usr/bin/env bash"
add "# Multi-call binary generated by LACKADAISICAL binbox"
add "# $output information:"
add "# Contained modules: ${inputs[*]}"
@ -135,6 +155,7 @@ for f in "${includes[@]}"; do
add "$(cat "$f")"
done
add "readarray -t all_funcs < <(declare -F | awk '{print \$3}')"
# >>> Section 2: Modules
for f in "${inputs[@]}"; do
@ -146,25 +167,52 @@ for f in "${inputs[@]}"; do
done
# >>> Section 3: Module selection
add ""
add "################################################################################"
add "# END OF INCLUDED MODULES ######################################################"
add "################################################################################"
add ""
add "# Array of modules as well as array of functions."
# Add a static list of modules with a no-newline add
add_nn "modules=("
for f in "${inputs[@]}"; do
add_nn "\"$f\" "
done
add ")"
add 'mapfile -t funcs < <(printf "%s\n" "${all_funcs[@]}" "${modules[@]}" "${modules[@]}" | sort | uniq -u)'
add ""
add "# Check the export switches (-m and -f)"
add ""
add "symed=1"
add "binself=\$(basename \$0)"
add "boxfile=\"$output\""
add "boxfile=\"$(basename $output)\""
add ""
add "if [[ \$binself == \$boxfile ]]; then"
add " symed=0"
add " if [[ \$# -eq 0 ]]; then"
add " echo 'Available modules:'"
for f in "${inputs[@]}"; do
add " echo '$f'"
done
add " echo '$(basename $output): Multi-call binary generated by lackadaisical binbox.'"
add " echo 'Use switch \"-m\" to generate symlinks of modules in the current directory,'"
add " echo 'or use switch \"-f\" to generate symlinks of all available functions.'"
add " echo ''"
add " echo 'Exported modules:'"
add " for mod in \"\${modules[@]}\"; do"
add " echo \"- \$mod\""
add " done"
add " echo ''"
add " echo 'Other functions:'"
add " for func in \"\${funcs[@]}\"; do"
add " echo \"- \$func\""
add " done"
add " exit 0"
add " fi"
add "fi"
add ""
add "if [[ \$symed -eq 0 ]]; then"
add " eval \$@"
add " exit \$?"
add "fi"
add ""
add "if [[ \$symed -eq 1 ]]; then"
add " eval \$(basename \$0) \$@"
add "fi"