Expanded and fixed "daisy arg", adding a way to set args and shift.
This commit is contained in:
parent
60cc207011
commit
7f9eb230f6
3 changed files with 37 additions and 3 deletions
|
|
@ -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
|
You can retrieve specific arguments by index (starting at 1) or all arguments
|
||||||
at once using "@". The command itself (index 0) is excluded from "@".
|
at once using "@". The command itself (index 0) is excluded from "@".
|
||||||
Arguments containing spaces are correctly preserved.
|
Arguments containing spaces are correctly preserved.
|
||||||
|
See Usage for how to use in commands, and Setting for manipulation.
|
||||||
|
|
||||||
Usage: $(daisy arg <index>)
|
Usage: $(daisy arg <index>)
|
||||||
$(daisy arg @)
|
$(daisy arg @)
|
||||||
|
Setting: daisy arg <index> <value>
|
||||||
|
daisy arg @ <value>
|
||||||
|
daisy arg shift
|
||||||
Example: ls -l "My Folder"
|
Example: ls -l "My Folder"
|
||||||
cd "$(daisy arg 2)" # Changes directory to "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 >
|
< daisy reload >
|
||||||
|
|
|
||||||
|
|
@ -421,12 +421,36 @@ daisy ()
|
||||||
;;
|
;;
|
||||||
arg)
|
arg)
|
||||||
local index=$2
|
local index=$2
|
||||||
|
local new_val=$3
|
||||||
if [[ "$index" == "@" ]]; then
|
if [[ "$index" == "@" ]]; then
|
||||||
echo "${DAISY_LAST_ARGS[@]:1}"
|
if [[ -n "$new_val" ]]; then
|
||||||
elif [[ "$index" =~ ^[0-9]+$ ]]; then
|
shift 2
|
||||||
if [[ -n "$ZSH_VERSION" ]]; then echo "${DAISY_LAST_ARGS[$((index+1))]}"; else echo "${DAISY_LAST_ARGS[$index]}"; fi
|
export DAISY_LAST_ARGS=("${DAISY_LAST_ARGS[0]}" "$@")
|
||||||
else
|
else
|
||||||
echo "Usage: daisy arg <index|@>"
|
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 "$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|@|shift> [new_value|count]"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
|
|
@ -341,6 +341,7 @@ _daisy_intercept_args() {
|
||||||
[[ "$last_cmd" == daisy* ]] && return
|
[[ "$last_cmd" == daisy* ]] && return
|
||||||
[[ "$last_cmd" == ld_* ]] && return
|
[[ "$last_cmd" == ld_* ]] && return
|
||||||
[[ "$last_cmd" == daisy_* ]] && return
|
[[ "$last_cmd" == daisy_* ]] && return
|
||||||
|
[[ "$last_cmd" == *"daisy arg"* ]] && return
|
||||||
local -a tmp_args
|
local -a tmp_args
|
||||||
if [[ -n "$ZSH_VERSION" ]]; then
|
if [[ -n "$ZSH_VERSION" ]]; then
|
||||||
tmp_args=(${(z)last_cmd})
|
tmp_args=(${(z)last_cmd})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue