In addition to CLI I use it from emacs dired-mode too:
(defun my-dired-detox ()
(interactive)
(dired-do-shell-command "detox" nil (dired-get-marked-files))
(revert-buffer))
I bind it to "_" in dired-mode.By the way: what's your beef with en dashes? I mean, if it was "everything should be 'HYPHEN-MINUS' (U+002D)", then fine, but why specifically en dashes and not em dashes?
Of all the changes in that list, removing the character that doesn't appear on a standard keyboard seems like the least controversial...
It's up there with those damn angled quotes.
Whether people or processes, something is likely to introduce the character at some point.
find . -depth -name '* *' | while IFS= read -r f ; do mv -i "$f" "$(dirname "$f")/$(basename "$f"|tr ' ' _)" ; done normalize_names() {
rename "s/-/_/g" *
detox -s lower *
}
in my .bashrc.I've thrown some edge cases at it, and it handles it super well. It deals with consecutive "_", remove leading garbage, normalize unicode, and even prevents naming conflicts by opting out early.
Thanks you.
I have:
Movie Bla (2020)
Movie Bla (2020).mp4
But also: Movie_Bla_(2020)
Movie_Bla_(2020).mp4
Movie_Bla_(2020).srt
Would not like to lose files like the the srt.(Also—that entire function is super inefficient and could be replaced with a single invocation of "rename".)
# 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.)