Added "daisy arg", a hooking tool that allows you to re-use arguments from previous commands.

This commit is contained in:
Lea 2026-06-09 13:17:56 +02:00
parent 0859ba819b
commit 60cc207011
3 changed files with 70 additions and 24 deletions

View file

@ -235,6 +235,19 @@ Edits ld.source and re-sources it, similarly to shrc. Append "-e" to edit
Append "-d" to edit "daisy.command.source".
················································································
< daisy arg >
················································································
This tool intercepts the arguments of the last command executed in your shell.
You can retrieve specific arguments by index (starting at 1) or all arguments
at once using "@". The command itself (index 0) is excluded from "@".
Arguments containing spaces are correctly preserved.
Usage: $(daisy arg <index>)
$(daisy arg @)
Example: ls -l "My Folder"
cd "$(daisy arg 2)" # Changes directory to "My Folder"
················································································
< daisy reload >
················································································
Re-sources ld.source. Essentially `ldrc` without editing.

View file

@ -419,6 +419,18 @@ daisy ()
return 1
fi
;;
arg)
local index=$2
if [[ "$index" == "@" ]]; then
echo "${DAISY_LAST_ARGS[@]:1}"
elif [[ "$index" =~ ^[0-9]+$ ]]; then
if [[ -n "$ZSH_VERSION" ]]; then echo "${DAISY_LAST_ARGS[$((index+1))]}"; else echo "${DAISY_LAST_ARGS[$index]}"; fi
else
echo "Usage: daisy arg <index|@>"
return 1
fi
;;
reload)
LD_INTERNAL=0 source "$LD_SOURCE_FILE"
;;

View file

@ -91,30 +91,6 @@ ld_dbg cat $LD_ESOURCEFILE
ld_dbg cat $LD_SHORTFILE
# Source everything in the config folder
function _ld.source_configs
{
while IFS= read -r -d '' f; do
source "$f"
done < <(find "$LD_CONFIG_FOLDER" -name "*.src" -type f -print0)
}
# Installation into PATH
if [[ ! $PATH == *"$LD_FOLDER"* ]];
then
export PATH="$PATH:$LD_FOLDER"
fi
# Set up the basic alias for `shrc`
# Do not set these up if LD_INTERNAL=1 is set, or infinite recursion could
# occur!
if [[ ! -v LD_INTERNAL ]];
then
alias shrc=". shrc"
fi
###############################################################################
# FUNCTIONS and ALIASES #######################################################
###############################################################################
function multicd
{
@ -350,6 +326,51 @@ _daisy_def_alias combine
_daisy_def_alias help
_daisy_def_alias list
_daisy_def_alias check
_daisy_def_alias arg
# --- Argument Interception Hook ---
_daisy_intercept_args() {
local last_cmd
if [[ -n "$ZSH_VERSION" ]]; then
last_cmd=$(fc -ln -1 | sed "s/^[[:space:]]*//")
else
last_cmd=$(fc -ln -1 2>/dev/null | sed "s/^[[:space:]]*//")
fi
[[ -z "$last_cmd" ]] && return
[[ "$last_cmd" == daisy* ]] && return
[[ "$last_cmd" == ld_* ]] && return
[[ "$last_cmd" == daisy_* ]] && return
local -a tmp_args
if [[ -n "$ZSH_VERSION" ]]; then
tmp_args=(${(z)last_cmd})
else
eval "tmp_args=($last_cmd)" 2>/dev/null
fi
if [[ ${#tmp_args[@]} -gt 0 ]]; then
export DAISY_LAST_ARGS=("${tmp_args[@]}")
fi
}
if [[ -n "$ZSH_VERSION" ]]; then
if [[ ! "$precmd_functions" == *_daisy_intercept_args* ]]; then
precmd_functions+=(_daisy_intercept_args)
fi
else
if [[ "$PROMPT_COMMAND" != *_daisy_intercept_args* ]]; then
if [[ -z "$PROMPT_COMMAND" ]]; then
PROMPT_COMMAND="_daisy_intercept_args"
else
PROMPT_COMMAND="_daisy_intercept_args; $PROMPT_COMMAND"
fi
fi
fi
function _ld.source_configs
{
while IFS= read -r -d "" f; do
source "$f"
done < <(find "$LD_CONFIG_FOLDER" -name "*.src" -type f -print0)
}
_ld.source_configs