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

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)