From 7f9eb230f632477128694c312f26ea1019247259 Mon Sep 17 00:00:00 2001 From: Lea Date: Tue, 9 Jun 2026 15:50:14 +0200 Subject: [PATCH] Expanded and fixed "daisy arg", adding a way to set args and shift. --- README.md | 9 +++++++++ daisy.command.source | 30 +++++++++++++++++++++++++++--- ld.source | 1 + 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f7b1f87..b0d1e89 100644 --- a/README.md +++ b/README.md @@ -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 ) $(daisy arg @) +Setting: daisy arg + daisy arg @ + 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 > diff --git a/daisy.command.source b/daisy.command.source index c4fc493..7080f51 100755 --- a/daisy.command.source +++ b/daisy.command.source @@ -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 " + echo "Usage: daisy arg [new_value|count]" return 1 fi ;; diff --git a/ld.source b/ld.source index 4ab1981..2729a75 100755 --- a/ld.source +++ b/ld.source @@ -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})