|
|
|
|
|
by jitl
537 days ago
|
|
As I said, I know bash, I've been writing bash for 20 years. I often ask Cursor to write code because it's literally faster to type "cmd-k, ensure exactly two params are passed, 1st one is a dir, 2nd is a file, enter" then it is to type the code myself. It's like I'm programming with natural language rather than whatever programming language. Like a high level programming language, I decide what the program should do, and AI figures out how to do it. It's analogous to writing bash instead of c. I could write my scripts in c for MAXIMUM PERFORMANCE, but I don't because it's less convenient. I could write this snippet of bash myself, but I don't for same reason. Re: macros: Cursor works this way as a shortcut for all manner of boring code in any programming language and for this kind of thing is very trustworthy. Using it leaves me more mental energy to spend on other things. Macros (I think I call this "snippets"?) are only worth it for frequently repeated tasks. This is what that prompt produces. Besides putting the count check first, it's what I would have written myself: if [[ $# -ne 2 ]]; then
echo "Error: Exactly 2 arguments required" >&2
return 1
fi
if [[ ! -d "$1" ]]; then
echo "Error: First argument must be a directory" >&2
return 1
fi
if [[ ! -f "$2" ]]; then
echo "Error: Second argument must be a file" >&2
return 1
fi
|
|
I'm not trying to argue that it can't solve the issue, I'm just trying to say there's not a big difference between the number of characters in the solution to the number of characters in the question.
I believe you that you've been writing scripts for 20 years but at the same time with that experience you're probably aware of people with that much experience that still don't know how to write functions. I constantly see people do things right out of bash pitfalls ¯\_(ツ)_/¯