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

@ -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
;;