Refactor of README.md. Change daisy_help to source directly from READEME.md

to prevent data duplication. Made daisy_help granular (e.g. runnig "daisy_help
bak" returns solely the description of the "bak" utility.

Added the following utils/functions:
- daisy_list: Provides a list of utilities similar to daisy_help but without
the descriptions.
- daisy_(un)alias: Adds/removes user-bound aliases inside of the lackadaisical
config files.
- grab: Alias of "awk '{primt $num}".
This commit is contained in:
Sam Hardeman 2025-11-21 00:40:31 +01:00
parent 434a50987e
commit 3eeb4e2d7f
4 changed files with 274 additions and 1299 deletions

0
LICENSE Normal file → Executable file
View file

214
README.md Normal file → Executable file
View file

@ -1,94 +1,140 @@
# LACKADAISICAL ---*This project is still under heavy development!*---
*This project is still under heavy development!* # L A C K A D A I S I C A L
A collection of easy-to-understand, easy-to-use scripts, functions and aliases. Designed to be beginner-friendly but also useful!
A collection of easy-to-understand, easy-to-use scripts and functions. Designed to be beginner-friendly but also useful! ## Disclaimer
Some aspects of this project were generated by Google Gemini (in particular, daisy_help and daisy_liist). While we are generally against using LLMs for code, the added functionality of being able to get information for individual tools is useful and not considered to be vital functionality.
# How to use ## How to use
Simply open your shell's RC-file (.bashrc, .zshrc, etc) and include `source <lackadaisical-folder>/daisy.source` preferably at the bottom of the file. We recommend setting your editor before sourcing `lackadaisical`. For instance, putting `export EDITOR=/usr/bin/nano` near thec\ top of your RC-file. It may later be overridden by `lackadaisical` itself if you use (or have used) `ched`. Simply open your shell's RC-file (.bashrc, .zshrc, etc) and include `source <la
ckadaisical-folder>/daisy.source`, preferably at the bottom of the file. We recommend setting your editor before sourcing `lackadaisical`. For instance, putting `export EDITOR=/usr/bin/nano` near the top of your RC-file. It may later be overridden by `lackadaisical` itself if you use (or have used) `ched`.
You can also try out the utilities by simply sourcing the file while running your shell. It will automatically include itself into your `PATH` variable. You can also try out the utilities by simply sourcing the file while running your shell of choice. It will automatically include itself into your `PATH` variable.
# Contents At first use, `lackadaisical` will provide you with information via `daisy_help`. This information is identical to what can be read in the `Getting Started` section below.
*(taken from `daisy_help`)*
## Getting started
``` ```
=================================================================== --- BEGIN OF DAISY HELP ---
===============================================================================
Thanks for installing LACKADAISICAL!
This project aims to provide useful utilities as well as learning material.
Thanks for installing LACKADAISICAL! It is still under heavy development, not all of the things on this
This project aims to provide useful utilities as well as learning list are present/implemented. Utils marked with * are incomplete.
material.
It is still under heavy development, not all of the things on this
list are present/implemented.
=================================================================== This suite provides a number of functions, aliases and scripts.
They are all aimed at enhancing your efficiency.
This suite provides a number of functions, aliases and scripts. To uninstall LACKADAISICAL, simply remove the source line from your
They are all aimed at enhancing your efficiency. shell RC, and reload it. This does not remove the files!
You will also need to manually clear the configuration data in '<home>/.config/
lackadaisical` if you so desire.
=================================================================== To read this notice again, call the function 'daisy_help'.
===============================================================================
These are the included binaries: These are the included binaries and utilities:
- calm: Reduce a process niceness to 0. - calm:
- cdz: This utility extracts an archive to /tmp and changes Reduce a process 'niceness' to 0.
directory to it in a new shell instance. Upon exit, - cdz:
the files are wiped. This utility extracts an archive to /tmp and changes
- editx: Uses your standard CLI editor to create/modify a directory to it in a new shell instance. Upon exit,
file and make it executable. the files are wiped. If `archivemount` is present,
- filewait: This tool is given a filename of a file that does it will be used to mount the archive instead! You can
not exist yet. When the file appears on disk, the bypass this behavior by specifying an env value of;
program quits and simply returns the filename. This NO_ARCHIVEMOUNT=1. The standard script supports zip,
can be used in personal workflows. tarballs, and rar archives. We recommend relying on
- newday: A basic but powerful journaling system. Recommended archivemount` if you have it installed.
to set up via crontab. Can be used for everything - editx:
from diaries to BTRFS snapshots. Uses your standard CLI editor to create/modify a
- own: A simple utility. It effectively uses chown -R file and make it executable.
user:user on its target. Root permissions required! - filewait:
- short: This tool allows you to set up directory shortcuts. This tool is given a filename of a file that does
It enhances cd t to integrate itsef using its own not exist yet. When the file appears on disk, the
syntax. It is similar to wd. tool quits and simply returns the filename. This
- shrc: This tool allows you to edit the RC file for your can be used in personal workflows to stall a longer
shell in your preferred editor. After saving, the command that relies on the existence of said file.
file is sourced by your shell. - newday:
- sw: A basic function that swaps two files by content. A basic but powerful journaling system. Recommended
Useful for restoring backups. to be set up via crontab. Can be used for everything
- what: This is a tool similar to which and others, the key from diaries to general file storage to even BTRFS
difference is that it returns partial matches. It can snapshots.
be used to search for binaries. - own:
A simple utility. It's effectively an alias for
=================================================================== "sudo chown -R user:user" on the target dir/file.
Root permissions required!
There are aliases and functions included within this file as well: - shrc:
- bak/unbak: These small utilities make backups of files by making This tool allows you to edit the RC file for your
a copy with a .bak suffix. Unbak reverses the process shell in your preferred editor. After saving, the
using sw and removes the backup. file is sourced by your shell if modified.
- lsa: A simple alias for ls -lah. - sw:
- lsn: A simple alias for ls -lah --sort=time --reverse. A basic function that swaps two files by content.
- editbin: An alias for editx $(which <x>). Saves on typing. Useful for restoring backups.
- ched: Like chsh but for your editor (EDITOR env). A list - what:
from which you can choose an installed editor This is a tool similar to which and others, the key
(CLI or GUI) is shown. difference is that it returns partial matches. It can
- cdf: Use fzf to find a file and then cd to its location. be used to search for binaries.
- ldrc: Edits this file and source it, similarly to shrc. - binbox:
- daisy_init: Alias for directly sourcing this file from any This tool can be used to pack bash scripts into one
LACKADAISICAL binary. You may use this yourself. big megascript, much like how `busybox` works.
- daisy_cbin: Contains the name of the current LACKADAISICAL You can also make symlinks to it to invoke a specific
binary being run. script (as of writing, 11/25, symlinks do not work well).
- daisy_enc: Converts a file/stdin to a base64 block that can be - bak/unbak:
decoded by passing the output(s) to daisy_dec. These small utilities make backups of files by making
- *_multi: A version of daisy_enc that runs encodes multiple a copy with a .bak suffix. Unbak reverses the process
files and outputs daisy_base64_data blocks to a file by using sw and removes the backup.
or stdout. - lsa:
- daisy_dec: Converts daisy_base64_data blocks back to the form A simple alias for ls -lah.
it was in originally. - lsn:
- *_multi: A version of daisy_dec that runs on multiple input A simple alias for ls -lah --sort=time --reverse.
blocks that are either stored in a file or stdin. - lss:
A simple alias for ls -lah --sort=size --reverse.
=================================================================== - editbin:
An alias for editx $\(which <x>\). Saves on typing.
To uninstall LACKADAISICAL, simply remove the source line from your - editpeco:
shell RC, and reload it. This does not remove the files! This function uses peco+tree like 'cdp', but opens
your editor on the selected file(s). After you exit
To read this notice again, call the function 'daisy_help'. your editor(s), you are returned to peco where you left
off.
=================================================================== - ched:
``` Like chsh but for your editor (EDITOR env). A list
from which you can choose an installed editor
(CLI or GUI) is shown. This list is by no means complete.
- cdf:
Use fzf to find a file and then cd to its location.
- cdp:
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.
- grab:
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.
- daisy_enc_multi:
A version of daisy_enc that encodes multiple
files and outputs daisy_base64_data blocks to a file
or stdout.
- daisy_dec:
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:
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.
- daisy_list:
List all available commands without description.
--- END OF DAISY HELP ---
```

1068
daisy

File diff suppressed because it is too large Load diff

View file

@ -25,7 +25,7 @@ then
fi fi
# Check for dependencies # Check for dependencies
function daisy_dependency_check() function daisy_dependency_check
{ {
command -v $1 1>/dev/null 2>/dev/null; command -v $1 1>/dev/null 2>/dev/null;
res=$? res=$?
@ -78,7 +78,7 @@ fi
############################################################################### ###############################################################################
# bak and unbak # bak and unbak
function bak() function bak
{ {
# Input: <file> # Input: <file>
target=$1 target=$1
@ -108,12 +108,12 @@ alias lsn="ls -a -l -tu -r -h"
alias lss="ls -a -l -S -r -h" alias lss="ls -a -l -S -r -h"
# Simple version of `cdf` # Simple version of `cdf`
function cdf() function cdf
{ {
cd $(dirname $(fzf)) cd $(dirname $(fzf))
} }
function cdp() function cdp
{ {
if [[ $DAISY_HAS_peco != 1 || $DAISY_HAS_tree != 1 ]]; if [[ $DAISY_HAS_peco != 1 || $DAISY_HAS_tree != 1 ]];
then then
@ -136,13 +136,13 @@ function editpeco
} }
# for convenience purposes # for convenience purposes
function editbin() function editbin
{ {
editx $(which $1) editx $(which $1)
} }
# sets a new editor based on commony available ones, and some visual ones # sets a new editor based on commony available ones, and some visual ones
function ched() function ched
{ {
editors=("nano" "vim" "nvim" "vi" "emacs" "gedit" "kate" "mousepad" "micro" \ editors=("nano" "vim" "nvim" "vi" "emacs" "gedit" "kate" "mousepad" "micro" \
"code" "subl" "joe" "kwrite" "gnome-text-editor") "code" "subl" "joe" "kwrite" "gnome-text-editor")
@ -189,7 +189,7 @@ function ched()
source "$DAISY_CONFIG_FOLDER/editor.src" source "$DAISY_CONFIG_FOLDER/editor.src"
} }
function wait_for_editor() function wait_for_editor
{ {
pname="$1" pname="$1"
fname="$2" fname="$2"
@ -208,13 +208,13 @@ function wait_for_editor()
done done
} }
function ldrc() function ldrc
{ {
FROM_RC=0 $EDITOR "$DAISY_SOURCE_FILE" FROM_RC=0 $EDITOR "$DAISY_SOURCE_FILE"
source "$DAISY_SOURCE_FILE" source "$DAISY_SOURCE_FILE"
} }
function daisy_enc() function daisy_enc
{ {
has_file=$([[ ! -z $1 ]] && file $1 1>/dev/null; echo $?) has_file=$([[ ! -z $1 ]] && file $1 1>/dev/null; echo $?)
has_file=$([[ has_file -eq 0 ]] && echo 1) has_file=$([[ has_file -eq 0 ]] && echo 1)
@ -234,9 +234,8 @@ function daisy_enc()
} }
# Will only take input files, always outputs to stdout # Will only take input files, always outputs to stdout
function daisy_enc_multi() function daisy_enc_multi
{ {
[[ ! -d $1 ]] && echo "daisy_dec_multi: No input files specified" && return
for file in "$@"; do for file in "$@"; do
if [[ -f "$file" ]]; then if [[ -f "$file" ]]; then
daisy_enc "$file" daisy_enc "$file"
@ -247,7 +246,7 @@ function daisy_enc_multi()
done done
} }
function daisy_dec() function daisy_dec
{ {
data=$(cat ${1:-/dev/stdin} | grep -v "#" ) data=$(cat ${1:-/dev/stdin} | grep -v "#" )
echo -e "$data" | cut -d "=" -f 2- | cut -b 2- | head -c -2 | base64 -d echo -e "$data" | cut -d "=" -f 2- | cut -b 2- | head -c -2 | base64 -d
@ -255,7 +254,7 @@ function daisy_dec()
# Will only take a file and directory, sources it to find all encoded data # Will only take a file and directory, sources it to find all encoded data
# Extracts to the directory # Extracts to the directory
function daisy_dec_multi() function daisy_dec_multi
{ {
[[ ! -f $1 ]] && echo "daisy_dec_multi: No input file specified" && return [[ ! -f $1 ]] && echo "daisy_dec_multi: No input file specified" && return
[[ ! -d $2 ]] && echo "daisy_dec_multi: No output directory specified" && return [[ ! -d $2 ]] && echo "daisy_dec_multi: No output directory specified" && return
@ -266,11 +265,59 @@ function daisy_dec_multi()
if [[ ! "$file" == '' ]] if [[ ! "$file" == '' ]]
then then
daisy_dec <(echo "$enc") | tee "$2"/"$file" daisy_dec <(echo "$enc") > "$2"/"$file"
fi fi
done done
} }
# Saves a bit on typing
function grab
{
[[ -z $@ ]] && return;
awk '{print $'$1'}'
}
# Functions for aliases that are added once, but always available
daisy_aliasfile="$DAISY_CONFIG_FOLDER"/.daisy_aliases
touch $daisy_aliasfile
function daisy_unalias
{
unalias_param=$@
if [[ -z $unalias_param ]]; then
return
fi
unalias $@ 2>/dev/null
# Remove from aliases list
newdata=$(cat $daisy_aliasfile | grep -v "alias $unalias_param")
echo -e $newdata > $daisy_aliasfile
}
function daisy_alias
{
alias_param="$@"
if [[ -z $alias_param ]]; then
echo "Active lackadaisical alias lines:"
cat $daisy_aliasfile | sed 's/alias //g'
return
fi
# Plain name and contents
alias_name=$(echo -e $alias_param | grep -o ".*=" | tr --delete =)
# Make persistent
daisy_unalias $alias_name
echo alias ${alias_param%=*}"="\"${alias_param#*=}\" >> $daisy_aliasfile
alias $alias_param
}
source $daisy_aliasfile
alias daisy_init='source "$DAISY_SOURCE_FILE"' alias daisy_init='source "$DAISY_SOURCE_FILE"'
############################################################################### ###############################################################################
@ -281,7 +328,7 @@ alias daisy_init='source "$DAISY_SOURCE_FILE"'
export DAISY_AVAILABLE=1 export DAISY_AVAILABLE=1
# Start of internal section # Start of internal section
function daisy_quit_if_no() function daisy_quit_if_no
{ {
has_dep=$DAISY_HAS_$1 has_dep=$DAISY_HAS_$1
@ -303,133 +350,83 @@ function daisy_quit_if_no()
[ -d "$DAISY_FOLDER" ] && export DAISY_AVAILABLE=1 [ -d "$DAISY_FOLDER" ] && export DAISY_AVAILABLE=1
# Help function # Help function, courtesy of Google Gemini
function daisy_help() function daisy_help() {
{ local target_tool="$1"
OLD_IFS="$IFS" local file="README.md" # Updated filename
IFS=
echo -e "==================================================================="
echo -e ""
echo -e "Thanks for installing LACKADAISICAL!"
echo -e "This project aims to provide useful utilities as well as learning"
echo -e "material."
echo -e ""
echo -e "It is still under heavy development, not all of the things on this"
echo -e "list are present/implemented. Utils marked with * are incomplete."
echo -e ""
echo -e "==================================================================="
echo -e ""
echo -e "This suite provides a number of functions, aliases and scripts."
echo -e "They are all aimed at enhancing your efficiency."
echo -e ""
echo -e "==================================================================="
echo -e ""
echo -e "These are the included binaries:"
echo -e " - calm:"
echo -e " Reduce a process niceness to 0."
echo -e " - cdz:"
echo -e " This utility extracts an archive to /tmp and changes"
echo -e " directory to it in a new shell instance. Upon exit,"
echo -e " the files are wiped. If \`archivemount\` is present,"
echo -e " it will be used to mount the archive instead! You can"
echo -e " bypass this behavior by specifying an env value of;"
echo -e " NO_ARCHIVEMOUNT=1. The standard script supports zip,"
echo -e " tarballs, and rar archives. We recommend relying on"
echo -e " archivemount\` if you have it installed."
echo -e " - editx:"
echo -e " Uses your standard CLI editor to create/modify a"
echo -e " file and make it executable."
echo -e " - filewait:"
echo -e " This tool is given a filename of a file that does"
echo -e " not exist yet. When the file appears on disk, the"
echo -e " program quits and simply returns the filename. This"
echo -e " can be used in personal workflows."
echo -e " - newday:"
echo -e " A basic but powerful journaling system. Recommended"
echo -e " to set up via crontab. Can be used for everything"
echo -e " from diaries to BTRFS snapshots."
echo -e " - own:"
echo -e " A simple utility. It effectively uses chown -R"
echo -e " user:user on its target. Root permissions required!"
echo -e " - short:"
echo -e " This tool allows you to set up directory shortcuts."
echo -e " It enhances cd t to integrate itsef using its own"
echo -e " syntax. It is similar to wd."
echo -e " - shrc:"
echo -e " This tool allows you to edit the RC file for your"
echo -e " shell in your preferred editor. After saving, the"
echo -e " file is sourced by your shell."
echo -e " - sw:"
echo -e " A basic function that swaps two files by content."
echo -e " Useful for restoring backups."
echo -e " - what:"
echo -e " This is a tool similar to which and others, the key"
echo -e " difference is that it returns partial matches. It can"
echo -e " be used to search for binaries."
echo -e " -*binbox:"
echo -e " This tool can be used to pack bash scripts into one"
echo -e " big megascript, much like how \`busybox\` works."
echo -e " You can also make symlinks to it to invoke a specific"
echo -e " script (current symlinks do not work well)."
echo -e ""
echo -e "==================================================================="
echo -e ""
echo -e "There are aliases and functions included within this file as well:"
echo -e " - bak/unbak:"
echo -e " These small utilities make backups of files by making"
echo -e " a copy with a .bak suffix. Unbak reverses the process"
echo -e " using sw and removes the backup."
echo -e " - lsa:"
echo -e " A simple alias for ls -lah."
echo -e " - lsn:"
echo -e " A simple alias for ls -lah --sort=time --reverse."
echo -e " - lss:"
echo -e " A simple alias for ls -lah --sort=size --reverse."
echo -e " - editbin:"
echo -e " An alias for editx $\(which <x>\). Saves on typing."
echo -e " - editpeco:"
echo -e " This function uses peco+tree like 'cdp', but opens"
echo -e " your editor on the selected file(s). After you exit"
echo -e " your editor(s), you are returned to peco where you left"
echo -e " off."
echo -e " - ched:"
echo -e " Like chsh but for your editor (EDITOR env). A list"
echo -e " from which you can choose an installed editor"
echo -e " (CLI or GUI) is shown."
echo -e " - cdf:"
echo -e " Use fzf to find a file and then cd to its location."
echo -e " - cdp:"
echo -e " Similar to 'cdf' but uses tree+peco for the query."
echo -e " - ldrc:"
echo -e " Edits this file and sources it, similarly to shrc."
echo -e " - daisy_init:"
echo -e " Alias for directly sourcing this file from any"
echo -e " LACKADAISICAL binary. You may use this yourself."
echo -e " - daisy_cbin:"
echo -e " Contains the name of the current LACKADAISICAL"
echo -e " binary being run."
echo -e " -*daisy_enc:"
echo -e " Converts a file/stdin to a base64 block that can be"
echo -e " decoded by passing the output(s) to daisy_dec."
echo -e " - *_multi:"
echo -e " A version of daisy_enc that runs encodes multiple"
echo -e " files and outputs daisy_base64_data blocks to a file"
echo -e " or stdout."
echo -e " -*daisy_dec:"
echo -e " Converts daisy_base64_data blocks back to the form"
echo -e " it was in originally."
echo -e " - *_multi:"
echo -e " A version of daisy_dec that runs on multiple input"
echo -e " blocks that are either stored in a file or stdin."
echo -e ""
echo -e "==================================================================="
echo -e ""
echo -e "To uninstall LACKADAISICAL, simply remove the source line from your"
echo -e "shell RC, and reload it. This does not remove the files!"
echo -e ""
echo -e "To read this notice again, call the function 'daisy_help'."
echo -e ""
echo -e "==================================================================="
IFS="$OLD_IFS" # 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
else
# 2. Parse specific tool
awk -v query="$target_tool" '
BEGIN { found=0; printing=0 }
# Match lines defining tools (e.g., " - calm:" or " - bak/unbak:")
$0 ~ /^[[:space:]]*- / {
printing=0 # Stop printing previous tool
# Clean the line to get the "signature"
# " - bak/unbak:" becomes "bak/unbak"
sig = $0
sub(/^[[:space:]]*- /, "", sig)
sub(/:[[:space:]]*$/, "", sig)
# Check for exact match OR match within a slash-separated list
# This handles "bak", "unbak", and "daisy_alias"
split(sig, names, "/")
is_match = 0
if (sig == query) is_match = 1
else {
for (i in names) {
if (names[i] == query) { is_match = 1; break }
}
}
if (is_match) {
printing=1
found=1
print $0 # Print the header line (e.g., " - bak/unbak:")
next
}
}
# Print description lines if we are in a "found" block
printing {
# Stop if we hit the start of the NEXT tool
if ($0 ~ /^[[:space:]]*- /) { printing=0; next }
print
}
END {
if (found == 0) {
print "Tool '"'"'" query "'"'"' not found in README.md."
}
}
'
fi
}
# Courtesy of Google Gemini
daisy_list() {
local file="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" | \
awk '
/^[[:space:]]*- / {
# Remove indentation and "- "
sub(/^[[:space:]]*- /, "");
# Remove trailing ":"
sub(/:[[:space:]]*$/, "");
print " " $0
}
' | sort
} }