#conventions #filenames #naming #cross-platform #pascal-case #format #snake-case

app fmtna

一个命令行应用程序,根据选定的命名规范格式化文件名

2 个稳定版本

1.0.2 2024 年 7 月 12 日
1.0.1 2024 年 7 月 7 日

#504 in 命令行工具

GPL-3.0 许可证

97KB
2.5K SLoC

fmtna

一个命令行应用程序,根据选定的命名规范格式化文件名。

这是为那些希望使他们的文件名尽可能一致的人设计的。

支持的命名规范包括

  • snake_case
  • kebab-case
  • camelCase
  • PascalCase
  • lowercase
  • UPPERCASE

它应该是跨平台的,但仅在 Linux (特别是 Linux Mint 21.2) 和 Windows 11 上进行了测试。

内容

安装

从发行页面下载可执行文件

先决条件

请参阅 https://github.com/yanns1/fmtna/releases

从 crates.io 下载 fmtna

先决条件

  • 您需要安装 Rust (特别是 cargo)。

在终端中运行 cargo install fmtna

从源代码构建

先决条件

  • 您需要安装 Rust (特别是 cargo)。
  • 您需要安装 Git。

克隆此仓库,并从仓库根目录运行 ./install.sh (您可能需要为脚本提供可执行权限)。 install.sh 使用 cargo 构建项目,然后在 ~/.local/bin/fmtna 下创建一个符号链接,指向生成的可执行文件。

使用方法

所有内容都在 fmtna --help 中解释。

Format filenames according to a chosen naming convention.

For each file/path (of any kind) given as argument, change the filename
(i.e. the base of the path) according to the naming convention selected.

WARNING! This program is dangerous.
Changing filenames is error prone and may cause undesired overwrites
or consequences (some files are expected to have the name they have
and not something else!).
fmtna's solves these problems by:
    1. Asking you what to do when conflicts happen (the program
       wants to change a path to an already existing path).
    2. Backing up the filename changes and allowing you to revert
       the changes partially or completely.
    3. Giving you ways to exclude some filenames from formatting.
Still, fmtna can't stop you from shooting yourself in the foot.
It can go as far as corrupting your system.

Usage: fmtna [OPTIONS] [FILES]...
       fmtna <COMMAND>

Commands:
  exclude  Exclude filenames matching the given patterns when formatting.
  revert   Revert filename changes.
  help     Print this message or the help of the given subcommand(s)

Arguments:
  [FILES]...
          A list of files (of any kind) for which to format the name.
          
          If no file is given, nothing will happen and the program will exit gracefully.

Options:
  -n, --naming-convention <NAMING_CONVENTION>
          The naming convention to use.
          
          The default is "snake_case".
          If one is specified in the config file, it will be used instead.
          
          [possible values: camelCase, kebab-case, snake_case, PascalCase, lower, UPPER]

  -r, --recursive
          Recursively format filenames within directories.
          
          For arguments that are directories, the default is to treat them like
          any other file, that is format their names.
          By using this flag, every file (directories included) within each of
          the directories will be formatted as well.

      --keep-dots
          Don't treat dots as separators, let them as is.
          
          A separator is a character indicating a break between words.
          The characters "_", "-", "." and spaces are considered separators
          and may change according to the chosen naming convention, unless
          this flag is used.

      --keep-special-chars
          Keep special characters.
          
          By special characters we mean characters that are neither alphanumeric
          nor separators ("_", "-", "." and spaces).
          If not set, special characters are removed with the exception of some
          accented letters that are replaced by their non-accented variants.

      --keep-unicode
          Keep Unicode (more precisely, non-ASCII) characters.
          
          When not set, unicode characters to their closest ASCII counterparts
          using https://crates.io/crates/unidecode.

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

待办事项

  • 更多测试
  • 用户定义的命名规范?让用户编写自己的 Rust 模块,将其包含在 fmtna 中(构建脚本可能是最佳选择)然后重新编译。

依赖关系

~9–23MB
~319K SLoC