Minor fixes as well as clean-up surrounding internal functions.

This commit is contained in:
Sam Hardeman 2025-12-13 04:16:43 +01:00
parent 405c1e7244
commit e3a2efdb43
12 changed files with 218 additions and 134 deletions

View file

@ -84,15 +84,15 @@ These are the included binaries and utilities:
a copy with a .bak suffix. Unbak reverses the process
by using sw and removes the backup.
- lsa:
A simple alias for ls -lah.
A simple alias for `ls -lah`.
- lsn:
A simple alias for ls -lah --sort=time --reverse.
A simple alias for `ls -lah --sort=time --reverse`.
- lss:
A simple alias for ls -lah --sort=size --reverse.
A simple alias for `ls -lah --sort=size --reverse`.
- editbin:
An alias for editx $\(which <x>\). Saves on typing.
An alias for `editx $\(which <x>\)`. Saves on typing.
- editpeco:
This function uses peco+tree like 'cdp', but opens
This function uses peco+tree like `cdp`, but opens
your editor on the selected file(s). After you exit
your editor(s), you are returned to peco where you left
off.
@ -103,37 +103,56 @@ These are the included binaries and utilities:
- cdf:
Use fzf to find a file and then cd to its location.
- cdp:
Similar to 'cdf' but uses tree+peco for the query.
Similar to `cdf` but uses tree+peco for the query.
- ldrc:
Edits daisy.source and re-sources it, similarly to shrc.
- daisy_init:
Alias for directly sourcing this file from any
LACKADAISICAL binary. You may use this yourself.
- daisy_reload:
Re-sources daisy.source. Essentially `ldrc` without
editing.
- grab:
Alias for "awk '{print $x}'", where x is a number.
E.g. "echo 'a b c' | grab 2" returns 'b'.
Alias for `awk '{print $x}'`, where x is a number.
E.g. `echo 'a b c' | grab 2` returns 'b'.
- daisy_cbin:
Contains the name of the current LACKADAISICAL
binary being run.
- daisy_enc:
Converts a file/stdin to a base64 block that can be
decoded by passing the output(s) to daisy_dec.
decoded by passing the output(s) to `daisy_dec`.
The output of `daisy_enc` can be concatenated with the
output of another encoded file to create a multi-file
base64 archive similar to `daisy_enc_multi`
- daisy_enc_multi:
A version of daisy_enc that encodes multiple
files and outputs daisy_base64_data blocks to a file
or stdout.
A version of `daisy_enc` that encodes multiple
files and outputs `daisy_base64_data` blocks to a file
or stdout. These outputs can be concatenated as well.
- daisy_dec:
Converts daisy_base64_data blocks back to the form
Converts `daisy_base64_data` blocks back to the form
it was in originally.
- daisy_dec_multi:
A version of daisy_dec that runs on multiple input
blocks that are either stored in a file or stdin.
- daisy_alias/daisy_unalias:
- daisy_alias:
This utility sets persistent user aliases stored in
.daisy_aliases in the lackadaisical config folder.
They will remain persistent until unaliased.
Call 'daisy_alias' without parameters to get a list.
Use 'daisy_unalias' to remove an alias.
"~/.config/lackadaisical/aliases.src".
They will remain persistent until unaliased with
daisy_unalias.
Call daisy_alias using '' instead of "".
E.g. `daisy_alias hello='echo "Hello!"' - instead of
`daisy_alias hello="echo \"Hello!\"".
This prevents an early invocation of possible nested
aliases.
Call this function without arguments to get a list of
registered aliases as well as indices for easy unaliasing
using `daisy_unalias`.
- daisy_unalias:
This utility removes an alias from those registered with
daisy_alias. It accepts either an alias name, or an index
given by calling `daisy_alias` without arguments.
In case of a mistake, a backup is made under the filename
"~/.config/lackadaisical/aliases.src.bak".
To restore this file, you can use these commands:
`unbak ~/.config/lackadaisical/aliases.src'
`daisy_reload`
- daisy_list:
List all available commands without description.
--- END OF DAISY HELP ---

10
binbox
View file

@ -3,21 +3,21 @@
# Symlinking to the resulting binary with the name of one of the original scripts will trigger
# said script. The idea is similar to `busybox`.
DAISY_INTERNAL=1
LD_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source
args=$@
function help()
{
echo "$DAISY_BIN is a utility that allows you to generate busybox-style combined binaries."
echo "$LD_BIN is a utility that allows you to generate busybox-style combined binaries."
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 ""
echo "> Usage:"
echo "Creating boxed binary: $DAISY_BIN -o <BOXED_BIN> <-s source files> <-p include files verbatim> -i INPUT_BINS ..."
echo "<X> Unpacking a boxed binary: $DAISY_BIN -e <BOXED_BIN>"
echo "View this screen: $DAISY_BIN <noargs>"
echo "Creating boxed binary: $LD_BIN -o <BOXED_BIN> <-s source files> <-p include files verbatim> -i INPUT_BINS ..."
echo "<X> Unpacking a boxed binary: $LD_BIN -e <BOXED_BIN>"
echo "View this screen: $LD_BIN <noargs>"
exit 0
}

2
calm
View file

@ -8,7 +8,7 @@
# set's NICE value to 0
# need sudo
DAISY_INTERNAL=1
LD_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source
pids=$@

4
cdz
View file

@ -1,8 +1,8 @@
#!/bin/sh
if [[ $DAISY_INTERNAL -ne 1 ]];
if [[ $LD_INTERNAL -ne 1 ]];
then
export DAISY_INTERNAL=1
export LD_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source
fi

View file

@ -9,11 +9,11 @@
# This file is also sourced in some of the scripts included within
# lackadaisical for common functionality. Some of the shared functionality is
# only included if sourced from one of the included scripts, though you are
# free to bypass this by setting env variable DAISY_INTERNAL to 1.
# free to bypass this by setting env variable LD_INTERNAL to 1.
if [[ $DAISY_INTERNAL -eq 1 ]];
if [[ $LD_INTERNAL -eq 1 ]];
then
export DAISY_BIN=$(basename $0)
export LD_BIN=$(basename $0)
fi
# Variables for use in other utilities
@ -32,47 +32,54 @@ function daisy_dependency_check
echo $(($res ^ 1))
}
DAISY_HAS_fzf=$(daisy_dependency_check fzf)
DAISY_HAS_md5sum=$(daisy_dependency_check md5sum)
DAISY_HAS_peco=$(daisy_dependency_check peco)
DAISY_HAS_tree=$(daisy_dependency_check tree)
LD_HAS_fzf=$(daisy_dependency_check fzf)
LD_HAS_md5sum=$(daisy_dependency_check md5sum)
LD_HAS_peco=$(daisy_dependency_check peco)
LD_HAS_tree=$(daisy_dependency_check tree)
export DAISY_FOLDER=$(dirname $(realpath $arg))
export DAISY_SOURCE_FILE=$(realpath $arg)
export DAISY_AVAILABLE=0
export LD_FOLDER=$(dirname $(realpath $arg))
export LD_SOURCE_FILE=$(realpath $arg)
export LD_AVAILABLE=0
# Config folder setup
export DAISY_CONFIG_FOLDER="$HOME/.config/lackadaisical"
export LD_CONFIG_FOLDER="$HOME/.config/lackadaisical"
new_install=0
if [[ ! -d "$DAISY_CONFIG_FOLDER" ]];
if [[ ! -d "$LD_CONFIG_FOLDER" ]];
then
# Create the folder with its basics
mkdir -p "$DAISY_CONFIG_FOLDER"
mkdir -p "$LD_CONFIG_FOLDER"
daisy_help
new_install=1
fi
# Functions for aliases that are added once, but always available
DAISY_ALIASFILE="$DAISY_CONFIG_FOLDER"/.daisy_aliases
touch $DAISY_ALIASFILE
# Multiple default source files
# [LEA.TODO] Turn these into arrays
LD_ALIASFILE="$LD_CONFIG_FOLDER/aliases.src"
LD_EDITORFILE="$LD_CONFIG_FOLDER/editor.src"
touch $LD_ALIASFILE
touch $LD_EDITORFILE
# Source everything in the config folder
for f in "$DAISY_CONFIG_FOLDER"; do
[ -f "$file" ] && source "$f"
done
function _daisy_source_configs
{
for f in `find "$LD_CONFIG_FOLDER" -name "*.src" -type f`;
do
source "$f"
done
}
# Installation into PATH
if [[ ! $PATH == *"$DAISY_FOLDER"* ]];
if [[ ! $PATH == *"$LD_FOLDER"* ]];
then
export PATH="$PATH:$DAISY_FOLDER"
export PATH="$PATH:$LD_FOLDER"
fi
# Set up the basic alias for `shrc`
# Do not set these up if DAISY_INTERNAL=1 is set, or infinite recursion could
# Do not set these up if LD_INTERNAL=1 is set, or infinite recursion could
# occur!
if [[ ! -v DAISY_INTERNAL ]];
if [[ ! -v LD_INTERNAL ]];
then
alias shrc=". shrc"
fi
@ -114,12 +121,17 @@ alias lss="ls -a -l -S -r -h"
# Simple version of `cdf`
function cdf
{
if [[ $LD_HAS_fzf != 1 ]];
then
echo "This alias requires the utility 'fzf'. Please install it."
return 1
fi
cd $(dirname $(fzf))
}
function cdp
{
if [[ $DAISY_HAS_peco != 1 || $DAISY_HAS_tree != 1 ]];
if [[ $LD_HAS_peco != 1 || $LD_HAS_tree != 1 ]];
then
echo "This alias requires the utilities 'peco' and 'tree'. Please install them."
echo "Consider using 'cdf' instead."
@ -130,12 +142,12 @@ function cdp
function editpeco
{
if [[ $DAISY_HAS_peco != 1 ]];
if [[ $LD_HAS_peco != 1 || $LD_HAS_tree != 1 ]];
then
echo "This alias requires the utility 'peco'. Please install it."
echo "This alias requires the utilities 'peco' and 'tree'. Please install them."
echo "Consider using 'cdf' instead."
return 1
fi
tree --noreport -fia . | peco --prompt "Press CTRL+C to quit - query:" --exec "xargs -o -I{} $EDITOR {}"
}
@ -174,7 +186,7 @@ function ched
fi
# Present all choices
choice=$(dialog --output-fd 1 --clear --title "Select Text Editor (Recommendation: nano)" \
choice=$(dialog --output-fd 1 --clear --title "Select Text Editor" \
--menu "Choose one of the installed text editors:" 15 50 6 \
"${available_editors[@]}")
dialog_ret=$?
@ -185,12 +197,11 @@ function ched
return
fi
echo export EDITOR=$choice > "$DAISY_CONFIG_FOLDER/editor.src"
echo export DAISY_EDITOR=$choice >> "$DAISY_CONFIG_FOLDER/editor.src"
echo export DAISY_OLD_EDITOR=$EDITOR >> "$DAISY_CONFIG_FOLDER/editor.src"
echo export EDITOR=$choice > "$LD_EDITORFILE"
echo export LD_EDITOR=$choice >> "$LD_EDITORFILE"
echo export LD_OLD_EDITOR=$EDITOR >>"$LD_EDITORFILE"
# Seems silly but this is also where we should export these
source "$DAISY_CONFIG_FOLDER/editor.src"
_daisy_source_configs
}
function wait_for_editor
@ -212,44 +223,60 @@ function wait_for_editor
done
}
function daisy_reload
{
FROM_RC=0 source "$LD_SOURCE_FILE"
}
function ldrc
{
FROM_RC=0 $EDITOR "$DAISY_SOURCE_FILE"
source "$DAISY_SOURCE_FILE"
$EDITOR "$LD_SOURCE_FILE"
FROM_RC=0 source "$LD_SOURCE_FILE"
}
function daisy_enc
{
has_file=$([[ ! -z $1 ]] && file $1 1>/dev/null; echo $?)
has_file=$([[ has_file -eq 0 ]] && echo 1)
file_info="no data"
file_name="null"
if [[ has_file -eq 1 ]];
if [ -d $1 ];
then
echo -e "daisy_create_folder=$1"
else
file_info=$(file $1)
file_dir=$(dirname $1)
file_name=$(basename $1)
base64_inner=$(cat ${1:-/dev/stdin} | base64 | tr -d '\n')
# Print out our block
echo -e "daisy_folder_$file_name=$file_dir"
echo -e "daisy_data_base64_$file_name=\"$base64_inner\""
fi
base64_inner=$(cat ${1:-/dev/stdin} | base64 | tr -d '\n')
# Print out our block
echo -e "# File info: $file_info"
echo -e "daisy_data_base64_$file_name=\"$base64_inner\""
}
# Will only take input files, always outputs to stdout
function daisy_enc_multi
{
for file in "$@"; do
if [[ -f "$file" ]]; then
daisy_enc "$file"
echo # separate blocks with a newline
else
echo "daisy_enc_multi: Skipping non-file: $file"
fi
daisy_enc "$file"
done
}
function daisy_enc_folder
{
if [[ $LD_HAS_tree != 1 ]];
then
echo "This function requires the utiliy 'tree'. Please install it."
return 1
fi
dir="$1"
cd "$dir"
tree -fia --noreport . | sed 1d | while read -r item;
do
daisy_enc "$item"
done
}
function daisy_dec
{
data=$(cat ${1:-/dev/stdin} | grep -v "#" )
@ -262,16 +289,28 @@ function daisy_dec_multi
{
[[ ! -f $1 ]] && echo "daisy_dec_multi: No input file specified" && return
[[ ! -d $2 ]] && echo "daisy_dec_multi: No output directory specified" && return
declare -a vars=( $(cat $1 | grep -v "# File") )
for enc in "${vars[@]}";
do
file=$(echo -e "$enc" | cut -d "_" -f 4- | cut -d "=" -f 1)
if [[ ! "$file" == '' ]]
then
daisy_dec <(echo "$enc") > "$2"/"$file"
fi
done
folder=
while IFS= read -r line; do
if [[ "$line" == "daisy_create_folder="* ]];
then
folder=$(echo $line | cut -d "=" -f 2)
mkdir -p "$2/$folder"
fi
if [[ "$line" == "daisy_folder"* ]];
then
folder=$(echo -e $line | cut -d "=" -f 2)
continue
fi
if [[ "$line" == "daisy_data_base64"* ]];
then
file=$(echo -e $line | cut -d "_" -f 4- | cut -d "=" -f 1)
daisy_dec <(echo $line) > "$2/$folder/$file"
fi
done <<< $(cat "$1")
}
# Saves a bit on typing
@ -285,6 +324,12 @@ function daisy_unalias
{
unalias_param=$@
if [[ $unalias_param =~ '^[0-9]+$' ]]; then
selection=$(head -$unalias_param "$LD_ALIASFILE" | tail -1 | cut -d "=" -f 1 | grab 2)
daisy_unalias $selection
return
fi
if [[ -z $unalias_param ]]; then
return
fi
@ -292,8 +337,9 @@ function daisy_unalias
unalias $@ 2>/dev/null
# Remove from aliases list
newdata=$(cat $DAISY_ALIASFILE | grep -v "alias $unalias_param")
echo -e $newdata > $DAISY_ALIASFILE
newdata=$(cat "$LD_ALIASFILE" | grep -v "alias $unalias_param")
bak "$LD_ALIASFILE" 1>/dev/null
echo -e $newdata > "$LD_ALIASFILE"
}
function daisy_alias
@ -301,31 +347,38 @@ function daisy_alias
alias_param="$@"
if [[ -z $alias_param ]]; then
linenum=1
echo "Active lackadaisical alias lines:"
cat $DAISY_ALIASFILE | sed 's/alias //g'
while IFS= read -r line; do
line=$(echo "$line" | sed 's/alias / /g')
echo "$linenum: $line"
linenum=$(($linenum + 1))
done < "$LD_ALIASFILE"
return
fi
# Plain name and contents
alias_name=$(echo -e $alias_param | grep -o ".*=" | tr --delete =)
if [[ $alias_name =~ '^[0-9]+$' ]]; then
echo "An alias cannot start with a number! Exiting."
return 1
fi
# Make persistent
daisy_unalias $alias_name
echo alias ${alias_param%=*}"="\"${alias_param#*=}\" >> $DAISY_ALIASFILE
alias $alias_param
echo alias ${alias_param%=*}"="\"${alias_param#*=}\" >> $LD_ALIASFILE
source $LD_ALIASFILE
}
source $DAISY_ALIASFILE
alias daisy_init='source "$DAISY_SOURCE_FILE"'
_daisy_source_configs
###############################################################################
# end of FUNCTIONS and ALIASES ################################################
###############################################################################
# End of user section!
export DAISY_AVAILABLE=1
export LD_AVAILABLE=1
# Start of internal section
function daisy_quit_if_no
@ -343,28 +396,27 @@ function daisy_quit_if_no
if [[ $has_dep -eq 0 ]];
then
echo "$DAISY_BIN: The dependency $1 was not found! Please install it" \
echo "$LD_BIN: The dependency $1 was not found! Please install it" \
"to be able to use this utility!"
exit 1
fi
}
[ -d "$DAISY_FOLDER" ] && export DAISY_AVAILABLE=1
[ -d "$LD_FOLDER" ] && export LD_AVAILABLE=1
# Help function, courtesy of Google Gemini
function daisy_help() {
local target_tool="$1"
local file="$DAISY_FOLDER/README.md"
# 1. Extract the block between the new headers
sed -n '/--- BEGIN OF DAISY HELP ---/,/--- END OF DAISY HELP ---/{//!p;}' "$file" | \
local target_tool="$1"
local file="$LD_FOLDER/README.md"
# 1. Extract the block between the new headers
sed -n '/--- BEGIN OF DAISY HELP ---/,/--- END OF DAISY HELP ---/{//!p;}' "$file" |
if [ -z "$target_tool" ]; then
# If no argument, print the whole help text
cat
# If no argument, print the whole help text
cat
else
# 2. Parse specific tool
awk -v query="$target_tool" '
# 2. Parse specific tool
awk -v query="$target_tool" '
BEGIN { found=0; printing=0 }
# Match lines defining tools (e.g., " - calm:" or " - bak/unbak:")
@ -415,11 +467,11 @@ function daisy_help() {
# Courtesy of Google Gemini
daisy_list() {
local file="$DAISY_FOLDER/README.md"
echo "Available LACKADAISICAL commands:"
local file="$LD_FOLDER/README.md"
echo "Available LACKADAISICAL commands:"
# Extract block -> Find tool lines -> Clean formatting -> Print
sed -n '/--- BEGIN OF DAISY HELP ---/,/--- END OF DAISY HELP ---/{//!p;}' "$file" | \
# Extract block -> Find tool lines -> Clean formatting -> Print
sed -n '/--- BEGIN OF DAISY HELP ---/,/--- END OF DAISY HELP ---/{//!p;}' "$file" |
awk '
/^[[:space:]]*- / {
# Remove indentation and "- "
@ -430,3 +482,16 @@ daisy_list() {
}
' | sort
}
# Hide what we don't need
if [[ ! -v LD_INTERNAL ]];
then
unset -f _daisy_source_configs
unset -f wait_for_editor
unset -f daisy_quit_if_no
unset -f daisy_dependency_check
unset LD_HAS_fzf
unset LD_HAS_peco
unset LD_HAS_md5sum
unset LD_HAS_tree
fi

2
editx
View file

@ -2,7 +2,7 @@
# This utility pre-allocs a file and adds execution permissions. It also
# removes the resulting file if it is empty after the editor closes.
DAISY_INTERNAL=1
LD_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source
if [[ -z $1 ]];

View file

@ -1,7 +1,7 @@
#!/bin/sh
# A simple utility that waits for a file to become available, infinitely
DAISY_INTERNAL=1
LD_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source
file=$@

4
newday
View file

@ -14,7 +14,7 @@
# You can use this for a primitive form of note-taking, but aside from notes -
# you can store any data this way.
DAISY_INTERNAL=1
LD_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source
dir_name=ByDate
@ -34,7 +34,7 @@ function errorFn()
error=$?
if [[ $error -gt 0 ]];
then
echo "$DAISY_BIN error ($error): "
echo "$LD_BIN error ($error): "
perl -E 'say $!=shift' $error
fi
exit $error

6
own
View file

@ -2,14 +2,14 @@
# Simple program that changes ownership to the current
# user, recursively.
DAISY_INTERNAL=1
LD_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source
if [[ $@ == '' ]];
then
echo "$DAISY_BIN: Used to quickly take ownership of files/folders."
echo "$LD_BIN: Used to quickly take ownership of files/folders."
echo "Requires sudo. If sudo is not installed, this tool will fai."
echo "Usage: $DAISY_BIN <folders or files>"
echo "Usage: $LD_BIN <folders or files>"
echo "Means: chown -R <youruser>:<youruser> <folders or files>"
exit 2
fi

4
shrc
View file

@ -5,9 +5,9 @@
# and sources the .rc afterwards!
# Source standard setup
if [[ $DAISY_INTERNAL -ne 1 ]];
if [[ $LD_INTERNAL -ne 1 ]];
then
DAISY_INTERNAL=1 source $DAISY_SOURCE_FILE
LD_INTERNAL=1 source $LD_SOURCE_FILE
fi
function md5_opt()

6
sw
View file

@ -1,7 +1,7 @@
#!/bin/sh
# It just swaps two files
export DAISY_INTERNAL1
export LD_INTERNAL1
. $(dirname $(realpath $0))/daisy.source
file1=$1
@ -13,9 +13,9 @@ function helpFn()
if [[ $error -gt 0 ]];
then
error_text=$(perl -E 'say $!=shift' $error)
echo "$DAISY_BIN error ($error): $error_text"
echo "$LD_BIN error ($error): $error_text"
fi
echo "Usage: $DAISY_BIN <file1> <file2>"
echo "Usage: $LD_BIN <file1> <file2>"
echo Swap two files in a filesystem.
exit $error
}

2
what
View file

@ -23,7 +23,7 @@
# /usr/sbin/vsftpd
#
DAISY_INTERNAL=1
LD_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source
pwd=/