Add consistency to variable naming, using lowercase for non-exported variables and uppercase for expoered ine. Also made some grammar fixes and removed 'short' since it's not available yet.

This commit is contained in:
Sam Hardeman 2025-11-23 16:51:15 +01:00
parent 8f9bdfbb30
commit 405c1e7244
5 changed files with 59 additions and 80 deletions

40
binbox
View file

@ -6,7 +6,7 @@
DAISY_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source
ARGS=$@
args=$@
function help()
{
@ -26,20 +26,20 @@ if [[ $@ == '' ]]; then
fi
# Define some building blocks
CASE_P1="case $BINARY in"
CASE_PM1=" $OPTION)"
CASE_PM2=" exec $OTPION_fn"
CASE_PM3=" ;;"
CASE_CM1=" *)"
CASE_CM2=" exec help_fn"
CASE_CM3=" ;;"
CASE_P2="esac"
case_p1="case $BINARY in"
case_pm1=" $OPTION)"
case_pm2=" exec $OTPION_fn"
case_pm3=" ;;"
case_cm1=" *)"
case_cm2=" exec help_fn"
case_cm3=" ;;"
case_p2="esac"
FUNC_P1="function $OPTION_fn() {"
FUNC_P2=" exit($?)"
FUNC_P3="}"
func_p1="function $OPTION_fn() {"
func_p2=" exit($?)"
func_p3="}"
BASIC_P1="BINARY=$0"
basic_p1="BINARY=$0"
# Start parsing args
inputs=()
@ -146,11 +146,11 @@ for f in "${inputs[@]}"; do
done
# >>> Section 3: Module selection
add "SYMED=1"
add "BINSELF=\$(basename \$0)"
add "BOXFILE=\"$output\""
add "if [[ \$BINSELF == \$BOXFILE ]]; then"
add " SYMED=0"
add "symed=1"
add "binself=\$(basename \$0)"
add "boxfile=\"$output\""
add "if [[ \$binself == \$boxfile ]]; then"
add " symed=0"
add " if [[ \$# -eq 0 ]]; then"
add " echo 'Available modules:'"
for f in "${inputs[@]}"; do
@ -160,12 +160,12 @@ add " exit 0"
add " fi"
add "fi"
add "if [[ \$SYMED -eq 0 ]]; then"
add "if [[ \$symed -eq 0 ]]; then"
add " eval \$@"
add " exit \$?"
add "fi"
add "if [[ \$SYMED -eq 1 ]]; then"
add "if [[ \$symed -eq 1 ]]; then"
add " eval \$(basename \$0) \$@"
add "fi"

View file

@ -18,10 +18,10 @@ fi
# Variables for use in other utilities
# Find the right argument for our folder
ARG=$0
if [[ ! $ARG == *daisy.source* ]];
arg=$0
if [[ ! $arg == *daisy.source* ]];
then
ARG="${BASH_SOURCE[0]}"
arg="${BASH_SOURCE[0]}"
fi
# Check for dependencies
@ -37,25 +37,25 @@ DAISY_HAS_md5sum=$(daisy_dependency_check md5sum)
DAISY_HAS_peco=$(daisy_dependency_check peco)
DAISY_HAS_tree=$(daisy_dependency_check tree)
export DAISY_FOLDER=$(dirname $(realpath $ARG))
export DAISY_SOURCE_FILE=$(realpath $ARG)
export DAISY_FOLDER=$(dirname $(realpath $arg))
export DAISY_SOURCE_FILE=$(realpath $arg)
export DAISY_AVAILABLE=0
# Config folder setup
export DAISY_CONFIG_FOLDER="$HOME/.config/lackadaisical"
NEW_INSTALL=0
new_install=0
if [[ ! -d "$DAISY_CONFIG_FOLDER" ]];
then
# Create the folder with its basics
mkdir -p "$DAISY_CONFIG_FOLDER"
daisy_help
NEW_INSTALL=1
new_install=1
fi
# Functions for aliases that are added once, but always available
daisy_aliasfile="$DAISY_CONFIG_FOLDER"/.daisy_aliases
touch $daisy_aliasfile
DAISY_ALIASFILE="$DAISY_CONFIG_FOLDER"/.daisy_aliases
touch $DAISY_ALIASFILE
# Source everything in the config folder
for f in "$DAISY_CONFIG_FOLDER"; do
@ -95,7 +95,7 @@ function bak
fi
# Handle both cases
if [[ UNBAK_MODE -eq 1 ]];
if [[ $unbak_mode -eq 1 ]];
then
cp -R "$target.bak" "$target"
rm -rf "$target.bak"
@ -106,7 +106,7 @@ function bak
fi
}
alias unbak="UNBAK_MODE=1 bak"
alias unbak="unbak_mode=1 bak"
alias lsa="ls -a -l -h"
alias lsn="ls -a -l -tu -r -h"
alias lss="ls -a -l -S -r -h"
@ -121,7 +121,7 @@ function cdp
{
if [[ $DAISY_HAS_peco != 1 || $DAISY_HAS_tree != 1 ]];
then
echo "This alias requires the utility 'peco' 'tree'. Please install them."
echo "This alias requires the utilities 'peco' and 'tree'. Please install them."
echo "Consider using 'cdf' instead."
return 1
fi
@ -155,38 +155,38 @@ function ched
available_editors=()
for editor in "${editors[@]}";
do
EDITOR_REAL=$(command -v "$editor")
if command -v "$EDITOR_REAL" >/dev/null 2>&1;
editor_real=$(command -v "$editor")
if command -v "$editor_real" >/dev/null 2>&1;
then
if [[ $(realpath "$EDITOR") == "$EDITOR_REAL" ]];
if [[ $(realpath "$EDITOR") == "$editor_real" ]];
then
available_editors+=("$EDITOR_REAL" "$editor (current choice)")
available_editors+=("$editor_real" "$editor (current choice)")
else
available_editors+=("$EDITOR_REAL" "$editor")
available_editors+=("$editor_real" "$editor")
fi
fi
done
if [[ ! -z $@ ]];
then
TEXT="$@"
dialog --msgbox "$TEXT" 0 0
text="$@"
dialog --msgbox "$text" 0 0
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 (Recommendation: nano)" \
--menu "Choose one of the installed text editors:" 15 50 6 \
"${available_editors[@]}")
DIALOG_RET=$?
dialog_ret=$?
if [ $DIALOG_RET -ne 0 ];
if [ $dialog_ret -ne 0 ];
then
echo "No editor selected."
return
fi
echo export EDITOR=$CHOICE > "$DAISY_CONFIG_FOLDER/editor.src"
echo export DAISY_EDITOR=$CHOICE >> "$DAISY_CONFIG_FOLDER/editor.src"
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"
# Seems silly but this is also where we should export these
@ -203,8 +203,8 @@ function wait_for_editor
while true;
do
ALIVE=$(ps aux | grep $fname | grep $pname)
if [[ $ALIVE == "" ]]
alive=$(ps aux | grep $fname | grep $pname)
if [[ $alive == "" ]]
then
break
fi
@ -292,8 +292,8 @@ 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 $DAISY_ALIASFILE | grep -v "alias $unalias_param")
echo -e $newdata > $DAISY_ALIASFILE
}
function daisy_alias
@ -302,7 +302,7 @@ function daisy_alias
if [[ -z $alias_param ]]; then
echo "Active lackadaisical alias lines:"
cat $daisy_aliasfile | sed 's/alias //g'
cat $DAISY_ALIASFILE | sed 's/alias //g'
return
fi
@ -311,12 +311,12 @@ function daisy_alias
# Make persistent
daisy_unalias $alias_name
echo alias ${alias_param%=*}"="\"${alias_param#*=}\" >> $daisy_aliasfile
echo alias ${alias_param%=*}"="\"${alias_param#*=}\" >> $DAISY_ALIASFILE
alias $alias_param
}
source $daisy_aliasfile
source $DAISY_ALIASFILE
alias daisy_init='source "$DAISY_SOURCE_FILE"'
@ -330,11 +330,12 @@ export DAISY_AVAILABLE=1
# Start of internal section
function daisy_quit_if_no
{
has_dep=$DAISY_HAS_$1
local dep_name="daisy_has_$1"
local has_dep="${!dep_name}"
# Check first if we have checked for this dependency, if not, print a fixme!
# TODO: Remove upon release, or convert into self-modifying code.
if [[ ! -v DAISY_HAS_$1 ]];
if [[ -z "$has_dep" ]];
then
echo "FIXME: Dependency `$1` should have an env variable, checking ad-hoc"
has_dep=$(daisy_dependency_check $1)

22
short
View file

@ -1,22 +0,0 @@
#!/bin/sh
# short: Creates shortcuts that can be used anywhere.
# Can also be used as an alternative for "alias".
#
# Example usage:
# Add a shortcut: short -A dev "/home/john/Development"
# Print shortcut content: short dev -> "/home/john/Development"
# Remove shortcut: short -D dev
#
# One could use this to do things like:
# cp -R files $(short dev)
# cd $(short www)
# ssh $(short server)
#
# Uses a file named .shortcuts in $HOME
DAISY_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source
short_config_dir="$DAISY_CONFIG_FOLDER/.shortcuts"

2
shrc
View file

@ -12,7 +12,7 @@ fi
function md5_opt()
{
if [[ $DAISY_HAS_md5sum -eq 1 ]];
if [[ $daisy_has_md5sum -eq 1 ]];
then
echo $(md5sum "$1" | awk '{print $1}')
fi

8
what
View file

@ -26,7 +26,7 @@
DAISY_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source
PWD=/
ALL_BINS=$(cd / && echo $PATH | sed 's/[:]/ /g' | xargs ls -A | grep -v ":" | sort | uniq)
OUTPUT=$(printf '%s\n' "-n" $ALL_BINS | grep -i "$1")
echo "$OUTPUT"
pwd=/
all_bins=$(cd / && echo $PATH | sed 's/[:]/ /g' | xargs ls -A | grep -v ":" | sort | uniq)
output=$(printf '%s\n' "-n" $all_bins | grep -i "$1")
echo "$output"