ChatGPT4o for BASH one-liners

It's a magic!😳

Apple and OpenAI recently made a deal, and now I can open ChatGPT window with Alt+Space on MacOS but still limited without a paid subscription. But still, it is a lot better than me in writing magical BASH commands, and the source of all evil–the regular expression.

I wanted to automatically update the list of journals in the resume.json file for this web page from the directories in my review folder. For this I need to find directories from the folder except for ones starting with _, select only the last names from the full path, then sort them ignoring cases, then replace a line break with a string of a comma and a space, then replace a place-holder <ADD_HERE> in a temporary file resume-addhere.json with this string, then save everything as a new resume.json after making a backup of the old resume.json file.

So, this all can be done by this magic one-liner🪄:

sed "s/\"<ADD_HERE>\": \"\"/\"summary\": \"`find ${MY_FOLDER_WHERE_I_PUT_MY_REVIEWS} -depth 1 -type d ! -name '_*' | awk -F/ '{print $NF}' | sort -f | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/, /g'`\"/g" resume-addhere.json > resume.json 

And it worked!:satisfied:

(But actually the ChatGPT took me a while since it hallucinated a bit about the sed command and was quite stubborn about it, then came up with a seemingly unnecessarily long option phrase…:see_no_evil:)

UPDATED on 2024-09-16: I’ve got more stories on this now! This script worked fine on the local computer, but it doesn’t build and deploy the website on the remote🙃. So I learned more about how to find error messages from the deployment process built in the workflows; and learned that all JSON files in the directory should be valid. So I made the place-holder a valid element: "<ADD_HERE>": "". The hard lesson was that I must obey the JSON format, all the time…