@lukasbach/scripts

deduplicate-gitignore

Removes duplicate entries in a gitignore file

Usage

npx @lukasbach/scripts deduplicate-gitignore

You can call the script directly if you have installed it globally:

npm i -g @lukasbach/scripts
ldo deduplicate-gitignore

Options

  • --file, -f: Where is the gitignore file?
  • -v, --verbose: Verbose logging

You can also omit options, and will be asked for them interactively.

Add --yes to skip all confirmations.

Script source

View Source on GitHub

/** Removes duplicate entries in a gitignore file */

const gitignoreFile = await ask.path("file,f", "Where is the gitignore file?", ".gitignore", [".gitignore"]);

const gitignore = await fs.readFile(gitignoreFile, "utf-8");
const lines = gitignore.split("\n");
const uniqueLines = lines.filter((line, index) => lines.indexOf(line) === index || line.trim() === "");
await fs.writeFile(gitignoreFile, uniqueLines.join("\n"));