Expanded and fixed "daisy arg", adding a way to set args and shift.

This commit is contained in:
Lea 2026-06-09 15:50:14 +02:00
parent 60cc207011
commit 7f9eb230f6
3 changed files with 37 additions and 3 deletions

View file

@ -241,11 +241,20 @@ 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.
See Usage for how to use in commands, and Setting for manipulation.
Usage: $(daisy arg <index>)
$(daisy arg @)
Setting: daisy arg <index> <value>
daisy arg @ <value>
daisy arg shift
Example: ls -l "My Folder"
cd "$(daisy arg 2)" # Changes directory to "My Folder"
Example: daisy arg 1 /home/user; daisy arg 2 /; daisy arg 3 /backup
echo $(daisy arg @) # "/home/user / /backup"
daisy arg 2 /home/user2
echo $(daisy arg @) # /home/user /home/user2 /backup
fdupes $(daisy arg @) | duperemove --fdupes
················································································
< daisy reload >

View file

@ -421,12 +421,36 @@ daisy ()
;;
arg)
local index=$2
local new_val=$3
if [[ "$index" == "@" ]]; then
echo "${DAISY_LAST_ARGS[@]:1}"
if [[ -n "$new_val" ]]; then
shift 2
export DAISY_LAST_ARGS=("${DAISY_LAST_ARGS[0]}" "$@")
else
echo "${DAISY_LAST_ARGS[@]:1}"
fi
elif [[ "$index" == "shift" ]]; then
local count=${new_val:-1}
if [[ "$count" =~ ^[0-9]+$ ]] && [[ ${#DAISY_LAST_ARGS[@]} -gt $count ]]; then
DAISY_LAST_ARGS=("${DAISY_LAST_ARGS[0]}" "${DAISY_LAST_ARGS[@]:$((count + 1))}")
export DAISY_LAST_ARGS
else
echo "Invalid shift count or too many shifts."
return 1
fi
elif [[ "$index" =~ ^[0-9]+$ ]]; then
if [[ -n "$ZSH_VERSION" ]]; then echo "${DAISY_LAST_ARGS[$((index+1))]}"; else echo "${DAISY_LAST_ARGS[$index]}"; fi
if [[ -n "$new_val" ]]; then
if [[ -n "$ZSH_VERSION" ]]; then
DAISY_LAST_ARGS[$((index+1))]="$new_val"
else
DAISY_LAST_ARGS[$index]="$new_val"
fi
export DAISY_LAST_ARGS
else
if [[ -n "$ZSH_VERSION" ]]; then echo "${DAISY_LAST_ARGS[$((index+1))]}"; else echo "${DAISY_LAST_ARGS[$index]}"; fi
fi
else
echo "Usage: daisy arg <index|@>"
echo "Usage: daisy arg <index|@|shift> [new_value|count]"
return 1
fi
;;

View file

@ -341,6 +341,7 @@ _daisy_intercept_args() {
[[ "$last_cmd" == daisy* ]] && return
[[ "$last_cmd" == ld_* ]] && return
[[ "$last_cmd" == daisy_* ]] && return
[[ "$last_cmd" == *"daisy arg"* ]] && return
local -a tmp_args
if [[ -n "$ZSH_VERSION" ]]; then
tmp_args=(${(z)last_cmd})