News for hackers. Stuff that matters.
Re:I'm “still afraid to use spaces in file names” years old by nybble41 on Thursday November 11, 2021 @01:44PM (#29191431)
That's the most beautiful part! After running this script there are no more conflicts, because it just silently overwrites all but one version of the "cleaned" filename.

(Also—that entire function is super inefficient and could be replaced with a single invocation of "rename".)

Re:I'm “still afraid to use spaces in file names” years old by mtift on Thursday November 11, 2021 @06:28PM (#29194592)
Totally inefficient. But for me it's readable and practical. This is mostly just a convenience function for me to help store files in a format I like rather than something I need optimized. If it ever started to feel slow, sure I could optimize. But for now, when I still occasionally download a file that has some weird character and I just prefer to add another line to my function.
Re:I'm “still afraid to use spaces in file names” years old by nybble41 on Friday November 12, 2021 @06:04PM (#29205531)
Without changing the design too much, you could rearrange it like so to avoid renaming multiple times and still have the option to just "add another line":

  # Rename all files in a directory
  rn() {
    rename \
      -e "s/ /-/g" \
      -e "s/_/-/g" \
      -e "s/–/-/g" \
      -e "s/://g" \
      -e "s/\(//g" \
      -e "s/\)//g" \
      -e "s/\[//g" \
      -e "s/\]//g" \
      -e 's/"//g' \
      -e "s/'//g" \
      -e "s/,//g" \
      -e "y/A-Z/a-z/" \
      -e "s/---/--/g" \
      -e "s/-‎--/--/g" \
      *
  }
Though I would at least take advantage of character classes to reduce the number of substitutions:

  # Rename all files in a directory
  rn() {
    rename \
      -e 's/[ _—]/-/g' \
      -e 's/[:\(\)\[\]",]//g' \
      -e "s/'//g" \
      -e 'y/A-Z/a-z/' \
      -e 's/--+/--/g' \
      *
  }
(I'm using the `rename` command provided by the `rename` Debian package, a.k.a `file-rename`. The options may vary if you're using a different version.)