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

View file

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

8
what
View file

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