#file #text-file #write-file #string #line #command-line #append

app indeed

将行追加到文件,无需shell垃圾

5个版本 (破坏性更新)

0.5.0 2024年7月16日
0.4.0 2024年3月27日
0.3.0 2023年12月10日
0.2.0 2023年12月10日
0.1.0 2023年12月9日

189文本处理

每月40次下载

MIT 许可证

8KB
80

Indeed

Indeed,这些字符串在文件中

这个程序让你抽象出一个非常简单的动作:将行追加到文件中。

这个程序最初是为了执行一个更复杂的动作,即使用--unique/-u标志,只有在行不在文件中时才追加行。

例如,如果文件asdf包含以下文本

one
two
three

你可以执行indeed -u asdf two six使文件包含

one
two
three
six

由于two已经在文件中(单独一行),因此没有添加,但six被添加,因为它不在。

程序进行精确匹配,而不是子串匹配。示例

one
twofer
three
indeed -u asdf two
one
twofer
three
two

只有在至少需要添加一个字符串时才会写入文件。如果指定的所有字符串都已存在于文件中,则返回非零退出码,不带错误消息。

没有错误消息,因为即使没有添加任何内容,你仍然确保了某些字符串存在于文件中,基本上意味着成功。非零退出码与&&一起使用时很有用。

请注意,所有最终的新行都会被修剪(如果有文件写入),所以你不必担心它们,就像你通常必须那样。如果你想要一个最终的新行,请使用--newline / -n选项。

这个程序的存在是因为确保东西被.gitignore是多么令人讨厌

使用indeed,你现在可以执行indeed -u .gitignore target/以确保target/被git忽略,而不可能引入.gitignore文件中的重复行。

您甚至不需要预先创建所谓的.gitignore文件,因为indeed如果路径不存在,将会创建它。

甚至不需要在.gitignore文件所在的目录中,因为您只需indeed -u my-project/.gitignore target/

用法

Appends lines of text to a file on their own lines.
A write to the file is only done if at least one of the specified strings needs to be added.
Final newlines are trimmed in that case.
Or the last one is kept, with the `-n` / `--newline` option.
The file (along with its parent directories) is created if it doesn't exist

Usage: indeed [OPTIONS] <PATH> [STRINGS]...

Arguments:
  <PATH>
  [STRINGS]...

Options:
  -u, --unique   Only append a line if it's not already in the file.
                 This check happens separately for each line.
                 The matching is exact, not substring.
                 If all of the specified strings are already in the
                 file, a non-zero exitcode is returned with no error message
  -n, --newline  Add a newline at the end of the file, if any writes to the file needed to happen
  -h, --help     Print help
  -V, --version  Print version

安装

cargo install indeed

也支持cargo-binstallcargo-quickinstall

卸载

cargo uninstall indeed

依赖项

~3–14MB
~147K SLoC