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

app indeed

Append lines to a file with no shell bullshit

4 releases (breaking)

0.4.0 Mar 27, 2024
0.3.0 Dec 10, 2023
0.2.0 Dec 10, 2023
0.1.0 Dec 9, 2023

#3 in #append

Download history 29/week @ 2024-02-25 3/week @ 2024-03-03 2/week @ 2024-03-10 117/week @ 2024-03-24 27/week @ 2024-03-31 1/week @ 2024-04-07

146 downloads per month

MIT license

8KB
71 lines

Indeed

Indeed, those strings are in the file

This program lets you abstract away a very simple action: append lines to a file.

A more complex action, that this program is initially made for is expressed with the --unique/-u flag, that only appends each line if it isn't already in the file.

For example, if file asdf contains this text:

one
two
three

You can execute indeed -u asdf two six to make the file contain:

one
two
three
six

Since two is already in the file on its own on a line, it didn't get added, but six did because it wasn't.

The program does an exact match, rather than a substring match. Example:

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

A write to the file is only done if at least one string needs to be added. If all specified strings are already in the file, a non-zero exitcode will be returned, with no error message.

There's no error message because even if nothing got added, you still ensured certain strings are in the file, essentially meaning a success. The non-zero exit code is useful with chaining shell commands with &&.

Mind that all final newlines get trimmed (if there's a write to the file), so you won't have to worry about them as you would have to otherwise.

This program exists because of how annoying it is to make sure things are .gitignored

With indeed, you can now do indeed -u .gitignore target/ to make sure target/ is git ignored, without possibly introducing a duplicate line in the .gitignore file.

You don't even have to preemtively create said .gitignore file, because indeed will create the provided path if it doesn't exist.

Hell, you don't even need to be in the same directory as the .gitignore file, because you could just indeed -u my-project/.gitignore target/

Usage

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.
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.
  -h, --help     Print help
  -V, --version  Print version

Install

cargo install indeed

cargo-binstall and cargo-quickinstall are also supported

Uninstall

cargo uninstall indeed

Dependencies

~3–14MB
~160K SLoC