Hacker News new | ask | show | jobs
by brundolf 480 days ago
Agreed. I've had a lot of success using ChatGPT for nontrivial bash one-liners. They're small in scope and there must be a huge amount of training data for them, I use them rarely enough that I don't remember details off the top of my head, and they're intrinsically throwaway code
1 comments

I was doing some file management last weekend and wanted a little script to remove any numbers at the start of a file name and any region values at the end. I also wanted to ensure any duplicate files were moved into a separate folder so i could remove them.

I could have written that code. I'm sure there is a program that can do exactly that for me that I could have downloaded. But one prompt, a few tests to make sure it wasnt going to nuke all my files, and within 5 minutes I was completely done with the file management. For this type of stuff it just saves time.

> I was doing some file management last weekend and wanted a little script to remove any numbers at the start of a file name and any region values at the end. I also wanted to ensure any duplicate files were moved into a separate folder so i could remove them.

> I could have written that code.

Not knowing precisely your desired result, the benefit of going through the effort of writing a script is experienced gained and deepening one's understanding of the tools involved.

For example, assume this file structure exists:

  .
  ├── 001name-eu-central1.ext
  ├── 001name-us-west.ext
  ├── 002name-eu-central1.ext
  ├── 003name-eu-central1.ext
  ├── keep
  └── research
The script logic to do what you describe could be similar to:

  for file in [0-9]*
  do
    dest="$(echo $file | sed -E -e 's/^[0-9]*//' -e 's/-(eu-central1|us-west)//')"

    if [[ -f "keep/$dest" ]]
    then
      mv "$file" "research/$file"
    else
      mv "$file" "keep/$dest"
    fi
  done

This results in:

  .
  ├── keep
  │   └── name.ext
  └── research
      ├── 001name-us-west.ext
      ├── 002name-eu-central1.ext
      └── 003name-eu-central1.ext

The net-net is that the journey is sometimes more valuable than the destination.
I get your sentiment, but I work 40+ hours a week as a swe. I write plenty of code. I don't see how writing a loop with some conditionals and regex would be beneficial. It is something that is not difficult to do, but would take time. The destination, and getting there quickly, was the only goal I was looking for.
> I get your sentiment, but I work 40+ hours a week as a swe. I write plenty of code. I don't see how writing a loop with some conditionals and regex would be beneficial.

No worries, I get it that this example might be a bit contrived and respect the demands engineers have on our time. The reason I went into such detail was to illuminate potential benefits of "exercising mental muscles" as it relates to knocking out similar solutions quicker each time they are needed.

There's probably a program in /usr/bin on your machine that does that.
Such as /usr/bin/bash!

More seriously rename (sometimes rename.ul) is built to do (some) of this task, and you may have some others depending how "featureful" your install is, but why bother for a one time task when it's not going to be more work to figure out what tool to use, what options it needs, and what parts will still need to be done after anyways?

Honestly this is just a great task for a script, even if you were going to hand write it. It'll be clearer, rely on fewer assumptions, and be more flexible if the task needs to change as you try to do it and notice something else.

I'm sure there is! What is the best way to find it? I'd likely google some type of query to find out if it exists and how I might use it.

Anything more than one query/line of text and one click is more than it would take to get a llm to write this.