0

After a lengthy search without results, I plan to create a preprocessor for the ".gitignore" file.

  1. .gitignore does not support regEx, but glob. I would like to be able to use regEx, or both (regEx and glob).
  2. .gitignore supports for a whitelist for a subFolder (including files) !subFolder/** two lines (!subFolder and !subFolder/**). I want to use only !SubFolder/, which is easy to understand.

Therfore i think it's time to start writing a little preprocessor for gitignore files. Any help is welcome!

Which language should I use for this? I started with the script language - Autohotkey and node.js. Is there perhaps a similar preprocessor somewhere? With Autohotkey I find it currently easier and faster to create. Node.js may be more useful in the long term. I also tried using Kotline to generate NodeJS-Script (but unfortunately got error messages). Tried start with this example: hello_node.zip 94 (188 KB)

Prototypes:

index.js:

#!/usr/bin/env node
const fs = require('fs')
try {
  const data = fs.readFileSync('.gitignore', 'utf8')
  var newString = data.replace(/\n(\!(\w+)\/\*\*)[\r\n]/g, '\n!$2\n$1\n');
  console.log(newString)
} catch (err) {
  console.error(err)
}

package.json:

{
  "name": "snippet",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "bin": {
   "gitignore": "./index.js"
 }
}

Autohotkey (works only in WinOS):

#SingleInstance,Force
Loop,9999
{
    FileReadLine, thisLine , .gitignore, %A_Index%
    if ErrorLevel
        break

    newString .= RegExReplace(thisLine,"^(\!(\w+)\/\*\*)$", "!$2`n$1") "`n"
}
MsgBox, '%newString%' = newString `n`n (line:%A_LineNumber%) `n`n`n The end of the file has been reached or there was a problem
Reload

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.