Skip to content

Commit 6132de6

Browse files
committed
Add confirmation prompt to cmd() function that executes commands after user approval
1 parent d737a28 commit 6132de6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

.zshrc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,16 @@ cmd() {
452452
fi
453453
local cmd=$(llm -x -s "We are on the command line for a system identified as \`$(uname -a)\`. Show me a command line comand for the following in a code block. Be brief and concise." "$*")
454454
echo -e "\n\x1b[32m$cmd\x1b[0m\n"
455-
echo -n "$cmd" | pbcopy
455+
456+
# Ask for confirmation (default to yes)
457+
echo -n "Run this command? [Y/n] "
458+
read -r response
459+
# If response is empty (just pressed enter) or starts with y/Y, run the command
460+
if [[ -z "$response" || "$response" =~ ^[Yy] ]]; then
461+
eval "$cmd"
462+
else
463+
echo "Command not executed."
464+
fi
456465
}
457466

458467
# Generate passwords

0 commit comments

Comments
 (0)