Minor order of operations changes and var name consistency (lower-case)

This commit is contained in:
Sam Hardeman 2025-09-23 02:20:12 +02:00
parent 03303c9e36
commit 434a50987e
9 changed files with 236 additions and 208 deletions

20
calm
View file

@ -11,31 +11,31 @@
DAISY_INTERNAL=1 DAISY_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source . $(dirname $(realpath $0))/daisy.source
PIDS=$@ pids=$@
errorFn() errorFn()
{ {
echo calm: Invalid operation or no such PID/process \(\"$(echo "$PIDS" | tr '\n' ' ' | cut -c -20)...\"\) echo calm: Invalid operation or no such PID/process \(\"$(echo "$pids" | tr '\n' ' ' | cut -c -20)...\"\)
exit exit
} }
for pid in $PIDS for pid in $pids
do do
# Process to PID in elegant way # Process to PID in elegant way
NEWPIDS=$(pidof "$pid") newpids=$(pidof "$pid")
if [ "$NEWPIDS" ] if [ "$newpids" ]
then then
BINNY=$pid binary=$pid
pid=$NEWPIDS pid=$newpids
else else
NEWBINS=$pid newbins=$pid
BINNY=$(ps -p "$pid" -o comm= 2>/dev/null ) binary=$(ps -p "$pid" -o comm= 2>/dev/null )
if [ $? != 0 ] if [ $? != 0 ]
then then
errorFn errorFn
fi fi
fi fi
echo Calming down $pid \("$BINNY"\)... echo Calming down $pid \("$binary"\)...
sudo renice -n 0 -p $pid; sudo renice -n 0 -p $pid;
done done

4
cdz
View file

@ -48,8 +48,8 @@ israr=$?
# TAR archives come in many forms, if none of our tests say it's tar # TAR archives come in many forms, if none of our tests say it's tar
# ...but it looks like tar and barks like tar, let's take the shot. # ...but it looks like tar and barks like tar, let's take the shot.
# Seems to work fairly well for the record. # Seems to work fairly well for the record.
RES=$(echo "$target" | grep ".tar") res=$(echo "$target" | grep ".tar")
if [[ $RES != "" ]]; if [[ $res != "" ]];
then then
istar=0 istar=0
fi fi

View file

@ -16,105 +16,6 @@ then
export DAISY_BIN=$(basename $0) export DAISY_BIN=$(basename $0)
fi fi
# Intro function
function daisy_help()
{
OLD_IFS="$IFS"
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: Reduce a process niceness to 0."
echo -e " - cdz: 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: Uses your standard CLI editor to create/modify a"
echo -e " file and make it executable."
echo -e " - filewait: 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: 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: A simple utility. It effectively uses chown -R"
echo -e " user:user on its target. Root permissions required!"
echo -e " - short: 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: 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: A basic function that swaps two files by content."
echo -e " Useful for restoring backups."
echo -e " - what: 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: 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: 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: A simple alias for ls -lah."
echo -e " - lsn: A simple alias for ls -lah --sort=time --reverse."
echo -e " - lss: A simple alias for ls -lah --sort=size --reverse."
echo -e " - editbin: An alias for editx $\(which <x>\). Saves on typing."
echo -e " - ched: 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: Use fzf to find a file and then cd to its location."
echo -e " - ldrc: Edits this file and sources it, similarly to shrc."
echo -e " - daisy_init: Alias for directly sourcing this file from any"
echo -e " LACKADAISICAL binary. You may use this yourself."
echo -e " - daisy_cbin: Contains the name of the current LACKADAISICAL"
echo -e " binary being run."
echo -e " -*daisy_enc: 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: 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: Converts daisy_base64_data blocks back to the form"
echo -e " it was in originally."
echo -e " - *_multi: 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"
}
# 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
@ -123,6 +24,19 @@ then
ARG="${BASH_SOURCE[0]}" ARG="${BASH_SOURCE[0]}"
fi fi
# Check for dependencies
function daisy_dependency_check()
{
command -v $1 1>/dev/null 2>/dev/null;
res=$?
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)
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
@ -135,32 +49,21 @@ 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"
echo "export EDITOR=$EDITOR" > "$DAISY_CONFIG_FOLDER/editor.src"
daisy_help daisy_help
NEW_INSTALL=1 NEW_INSTALL=1
fi fi
# Source everything in the config folder
for f in "$DAISY_CONFIG_FOLDER"/*; do
[ -f "$file" ] && source "$f"
done
# Installation into PATH # Installation into PATH
if [[ ! $PATH == *"$DAISY_FOLDER"* ]]; if [[ ! $PATH == *"$DAISY_FOLDER"* ]];
then then
export PATH="$PATH:$DAISY_FOLDER" export PATH="$PATH:$DAISY_FOLDER"
[[ NEW_INSTALL -eq 1 ]] && echo -e "Lackadaisical binaries have been added to your PATH variable."
fi fi
# Load override from config (default is $EDITOR - so no change is made)
_EDITOR=$(cat "$DAISY_CONFIG_FOLDER"/editor.src | grep "EDITOR=" | sed 's/export EDITOR=//g')
NEED_CHED=0
if [[ -z $EDITOR ]];
then
NEED_CHED=1
fi
# Never call if we're in internal mode
if [[ $DAISY_INTERNAL -eq 1 ]];
then
NEED_CHED=0
fi
# Set up the basic alias for `shrc` # 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 DAISY_INTERNAL=1 is set, or infinite recursion could
@ -210,6 +113,28 @@ function cdf()
cd $(dirname $(fzf)) cd $(dirname $(fzf))
} }
function cdp()
{
if [[ $DAISY_HAS_peco != 1 || $DAISY_HAS_tree != 1 ]];
then
echo "This alias requires the utility 'peco' 'tree'. Please install them."
echo "Consider using 'cdf' instead."
return 1
fi
cd $(dirname $(tree -fia --noreport . | peco))
}
function editpeco
{
if [[ $DAISY_HAS_peco != 1 ]];
then
echo "This alias requires the utility 'peco'. Please install it."
return 1
fi
tree --noreport -fia . | peco --prompt "Press CTRL+C to quit - query:" --exec "xargs -o -I{} $EDITOR {}"
}
# for convenience purposes # for convenience purposes
function editbin() function editbin()
{ {
@ -226,14 +151,14 @@ function ched()
available_editors=() available_editors=()
for editor in "${editors[@]}"; for editor in "${editors[@]}";
do do
EDITOR_REAL=$(which $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
@ -245,9 +170,9 @@ function ched()
fi fi
# Present all choices # Present all choices
CHOICE=$(dialog --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[@]}" 3>&1 1>&2 2>&3) "${available_editors[@]}")
DIALOG_RET=$? DIALOG_RET=$?
if [ $DIALOG_RET -ne 0 ]; if [ $DIALOG_RET -ne 0 ];
@ -256,8 +181,8 @@ function ched()
return return
fi fi
CHOICE=$(which $CHOICE)
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_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
@ -286,7 +211,6 @@ function wait_for_editor()
function ldrc() function ldrc()
{ {
FROM_RC=0 $EDITOR "$DAISY_SOURCE_FILE" FROM_RC=0 $EDITOR "$DAISY_SOURCE_FILE"
wait_for_editor $EDITOR "$DAISY_SOURCE_FILE"
source "$DAISY_SOURCE_FILE" source "$DAISY_SOURCE_FILE"
} }
@ -352,30 +276,11 @@ alias daisy_init='source "$DAISY_SOURCE_FILE"'
############################################################################### ###############################################################################
# end of FUNCTIONS and ALIASES ################################################ # end of FUNCTIONS and ALIASES ################################################
############################################################################### ###############################################################################
if [[ $NEED_CHED -eq 1 ]];
then
# Editor is unset, pick one, set `vi` as backup
TXT1="There is no standard EDITOR environment variable defined. Choose one of the installed text editors."
TXT2="You can always change it later wih `ched`, part of the Lackadaisical suite."
ched $TXT1 $TXT2
fi
# End of user section! # End of user section!
export DAISY_AVAILABLE=1 export DAISY_AVAILABLE=1
# Start of internal section # Start of internal section
# Check for dependencies
function daisy_dependency_check()
{
command -v $1 1>/dev/null 2>/dev/null;
res=$?
echo $(($res ^ 1))
}
DAISY_HAS_fzf=$(daisy_dependency_check fzf)
DAISY_HAS_md5sum=$(daisy_dependency_check md5sum)
function daisy_quit_if_no() function daisy_quit_if_no()
{ {
has_dep=$DAISY_HAS_$1 has_dep=$DAISY_HAS_$1
@ -398,8 +303,133 @@ function daisy_quit_if_no()
[ -d "$DAISY_FOLDER" ] && export DAISY_AVAILABLE=1 [ -d "$DAISY_FOLDER" ] && export DAISY_AVAILABLE=1
# Source everything in the config folder # Help function
# We do this at the end so that we do not run into isues function daisy_help()
for file in "$DAISY_CONFIG_FOLDER"/*; do {
[ -f "$file" ] && source "$file" OLD_IFS="$IFS"
done 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"
}

4
editx
View file

@ -22,9 +22,9 @@ touch "$1"
chmod +x "$1" chmod +x "$1"
$EDITOR "$1" $EDITOR "$1"
wait $! wait $!
SIZE=$(du "$1" | cut -f 1) size=$(du "$1" | cut -f 1)
if [[ $SIZE -eq 0 && $exists -ne 0 ]]; if [[ $size -eq 0 && $exists -ne 0 ]];
then then
rm -rf "$1" rm -rf "$1"
fi fi

View file

@ -4,9 +4,9 @@
DAISY_INTERNAL=1 DAISY_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source . $(dirname $(realpath $0))/daisy.source
FILE=$@ file=$@
while [ ! -f "$FILE" ] while [ ! -f "$file" ]
do do
sleep 0.1 sleep 0.1
done done
echo $FILE echo $file

35
newday
View file

@ -17,39 +17,38 @@
DAISY_INTERNAL=1 DAISY_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source . $(dirname $(realpath $0))/daisy.source
BINSELF=$(basename $0) dir_name=ByDate
DIR_NAME=ByDate root_dir=$HOME/$dir_name
ROOT_DIR=$HOME/$DIR_NAME today_sym=$HOME/Today
TODAY_SYM=$HOME/Today
# Present day # Present day
TODAY=$(date -I) today=$(date -I)
YEAR=$(echo $TODAY | awk -F"-" '{print $1}') year=$(echo $today | awk -F"-" '{print $1}')
MONTH=$(echo $TODAY | awk -F"-" '{print $2}') month=$(echo $today | awk -F"-" '{print $2}')
DAY=$(echo $TODAY | awk -F"-" '{print $3}') day=$(echo $today | awk -F"-" '{print $3}')
set -e set -e
function errorFn() function errorFn()
{ {
ERROR=$? error=$?
if [[ $ERROR -gt 0 ]]; if [[ $error -gt 0 ]];
then then
echo "$BINSELF error ($ERROR): " echo "$DAISY_BIN error ($error): "
perl -E 'say $!=shift' $ERROR perl -E 'say $!=shift' $error
fi fi
exit $ERROR exit $error
} }
# Error handling # Error handling
trap errorFn ERR trap errorFn ERR
# First we clear out empty folders, and remove the symlink if it exists # First we clear out empty folders, and remove the symlink if it exists
test -e "$ROOT_DIR" && find "$ROOT_DIR" -maxdepth 3 -type d -empty -print | xargs rm -rf test -e "$root_dir" && find "$root_dir" -maxdepth 3 -type d -empty -print | xargs rm -rf
test -L "$TODAY_SYM" && rm -rf "$TODAY_SYM" test -L "$today_sym" && rm -rf "$today_sym"
# Now we can set up today's directory # Now we can set up today's directory
mkdir -p "$ROOT_DIR/$YEAR/$MONTH/$DAY" mkdir -p "$root_dir/$year/$month/$day"
cd $ROOT_DIR cd $root_dir
ln -s "./$DIR_NAME/$YEAR/$MONTH/$DAY" "$TODAY_SYM" ln -s "./$dir_name/$year/$month/$day" "$today_sym"
exitcode=@? exitcode=@?

2
short
View file

@ -17,6 +17,6 @@
DAISY_INTERNAL=1 DAISY_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source . $(dirname $(realpath $0))/daisy.source
SHORT_FILE="$DAISY_CONFIG_FOLDER/.shortcuts" short_config_dir="$DAISY_CONFIG_FOLDER/.shortcuts"

23
shrc
View file

@ -21,27 +21,26 @@ function md5_opt()
if [[ $FROM_RC -eq 1 ]]; then if [[ $FROM_RC -eq 1 ]]; then
alias shrc=". shrc" alias shrc=". shrc"
else else
BASENAME=$(basename $SHELL) shellname=$(basename $SHELL)
RC_NAME="."$BASENAME"rc" rc_name="."$shellname"rc"
RC_PATH="$HOME/$RC_NAME" rc_path="$HOME/$rc_name"
# Optional MD5 checks # Optional MD5 checks
HAS_CHANGED=1 has_changed=1
SUM1=$(md5_opt "$RC_PATH") sum1=$(md5_opt "$rc_path")
SUM2=
# This sets a default if the variable does not exist. # This sets a default if the variable does not exist.
EDITOR=${EDITOR:-$(ched)} EDITOR=${EDITOR:-$(ched)}
$EDITOR "$RC_PATH" $EDITOR "$rc_path"
wait_for_editor $EDITOR "$RC_PATH" wait_for_editor $EDITOR "$rc_path"
SUM2=$(md5_opt "$RC_PATH") sum2=$(md5_opt "$rc_path")
if [[ $DAISY_HAS_md5sum -eq 1 && "$SUM1" == "$SUM2" ]]; if [[ $daisy_has_md5sum -eq 1 && "$sum1" == "$sum2" ]];
then then
echo "The RC-file $RC_NAME has not changed on disk. Not sourcing." echo "The RC-file $rc_name has not changed on disk. Not sourcing."
return return
fi fi
source "$RC_PATH" source "$rc_path"
fi fi

28
sw
View file

@ -1,23 +1,23 @@
#!/bin/sh #!/bin/sh
# It just swaps two files # It just swaps two files
export DAISY_INTERNAL=1 export DAISY_INTERNAL1
. $(dirname $(realpath $0))/daisy.source . $(dirname $(realpath $0))/daisy.source
FILE1=$1 file1=$1
FILE2=$2 file2=$2
function helpFn() function helpFn()
{ {
ERROR=$? error=$?
if [[ $ERROR -gt 0 ]]; if [[ $error -gt 0 ]];
then then
ERROR_TEXT=$(perl -E 'say $!=shift' $ERROR) error_text=$(perl -E 'say $!=shift' $error)
echo "$DAISY_BIN error ($ERROR): $ERROR_TEXT" echo "$DAISY_BIN error ($error): $error_text"
fi fi
echo "Usage: $DAISY_BIN <file1> <file2>" echo "Usage: $DAISY_BIN <file1> <file2>"
echo Swap two files in a filesystem. echo Swap two files in a filesystem.
exit $ERROR exit $error
} }
if [[ $@ == *"--help"* ]]; if [[ $@ == *"--help"* ]];
@ -36,14 +36,14 @@ trap helpFn ERR
# We want to swap two files # We want to swap two files
# Easy, but let's be safe about it # Easy, but let's be safe about it
ls "$FILE1" >/dev/null ls "$file1" >/dev/null
ls "$FILE2" >/dev/null ls "$file2" >/dev/null
# Files should exist, now we move # Files should exist, now we move
mv "$FILE1" "$FILE1.sw" mv "$file1" "$file1.sw"
mv "$FILE2" "$FILE2.sw" mv "$file2" "$file2.sw"
# We got our moved copies, now we simply rename # We got our moved copies, now we simply rename
mv "$FILE1.sw" "$FILE2" mv "$file1.sw" "$file2"
mv "$FILE2.sw" "$FILE1" mv "$file2.sw" "$file1"