Welcome to Vifm Q&A, where you can ask questions about Vifm usage. Registration is optional, anonymous posts are moderated. GitHub or Google logins are enabled.

Santize directory names?

0 votes
asked Jan 14, 2016 in vifm by octos

May I suggest adding a sanitation command that would replace all spaces and various OS's reserved characters from file names and directory names?

Relevant: https://kb.acronis.com/content/39790

2 Answers

0 votes
answered Jan 14, 2016 by xaizek

Not sure if there is a need for that, :tr should be able to do the job. Something like:

tr/ ?<>\\:*|"/_

but I hit unnoticed bug while testing it (thanks for that!), so the command should be like this in current version:

tr/ ?<>\\:*|"/__________

You can define a command:

command! sanitize :tr/ ?<>\\:*|"/__________
commented Jan 14, 2016 by aleksejrs

xaizek, what happens when renaming in a text editor a file name that contains a line break?

commented Jan 14, 2016 by xaizek

It won't work. Displaying such names is not really nice too. Luckily, it's very rare case, because it's also the one which is hard to handle in various situations.

0 votes
answered Jan 14, 2016 by aleksejrs

That kind of a tool can be useful,
especially when copying between file systems (like copying to FAT or NTFS on GNU/Linux), and the name would have to be corrupted anyway.
but as can be seen from your acronis.com link, what to replace is OS-, user- and file-dependent. Maybe if it shows a menu where you can customize your defaults?

Some GNU/Linux examples:

  • “-” in the beginning of a name is a must to get rid of, because they are dangerous with sloppy command lines.
  • I guess / < > and line breaks must not be in file names.
  • “:” is not a problem, except with multimedia software like FFmpeg, unless you simply prepend “file:” in its command.
  • Spaces are not always a problem, but are inconvenient and can break poorly-written scripts or command lines. Same with quotation marks (and asterisks) and parentheses (likely to be in names of pages and their directories saved by a Web browser). They must not be removed by default.
  • “|” also comes from Web browsers. Not sure there is any other use for it in file names.
  • Double spaces can be removed for polish.
If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here won't be considered as spam, but this is not a perfect place for it.