$ sgpt -s "The command 'sp current' outputs
> Album Tea For The Tillerman (Remastered 2020)
> AlbumArtist Yusuf / Cat Stevens
> Artist Yusuf / Cat Stevens
> Title Wild World
> I want just 'Wild World by Yusuf/Cat Stevens'"
sp current | awk -F' +' '/Title/{title=$2} /Artist/{artist=$2} END{print title " by " artist}'
[E]xecute, [D]escribe, [A]bort: A
E
Wild World by Yusuf / Cat Stevens
Looking back at it, the awk command it uses is actually pretty clean.
It should use ^Title and ^Artist, otherwise something with "Artist" or "Title" will give wonky results.
More importantly, you can get the same results by just one or two dbus-send commands instead of using that "sp" script + something to clean it up.
The sp-metadata function uses tons of processes to clean the output[1], and sp-current launches a few more. If you're doing this in a loop for your WM status display this sort of stuff really adds up. Even on modern systems launching processes isn't free and relatively slow, and launching >20 of them every few seconds is going to use non-trivial amounts of CPU and will needlessly drain your battery.
I don't really know what that dbus command outputs, but I bet that with you might go a long way with "dbus-send ... | grep -o ..." or something.
So in general I'd say this is a classic case of "you're not even using the right solution, and no amount of GPT is going to help".
Shell scripting is the perfect use case for ChatGPT. Simple enough that AI can handle it, annoying enough that I don't really want to do it myself, and something I do rarely enough that I don't really know any of the commands deeply.
Out of curiosity I asked bog-standard web ChatGPT (4) if it could do the job in awk, took it five times to get it right. Whatever prompt shell-gpt is using, it works.