preprocessor for .gitignore file (used by git) for RegEx support and more





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







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+)/**)[rn]/g, 'n!$2n$1n');
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









share|improve this question























  • I'd caution against this. Regular expressions are vastly more powerful than shell globs. Many straightforward expressions simply cannot be phrased as a shell glob. Some can, but will need to be expanded from one regular expression to millions of alternative shell globs, each of which would need to be stored.

    – Christoph Sommer
    Mar 26 at 1:43













  • yes it can not be the target, all regex phrased as a shell glob. yes, its not possible. but an approximation, a good compromise was possible as AHK script variant (released on githup). Useful only for the few that I can express in regEx in one line, but with Glob requires several. Shorter, more manageable, easier to edit. Of course, you can continue to simply write glob in it. These can be distinguished quite well. For example, a simple rule: no contain ``, then it's glob (I almost did it that way).

    – SL5net
    Mar 26 at 18:44




















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+)/**)[rn]/g, 'n!$2n$1n');
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









share|improve this question























  • I'd caution against this. Regular expressions are vastly more powerful than shell globs. Many straightforward expressions simply cannot be phrased as a shell glob. Some can, but will need to be expanded from one regular expression to millions of alternative shell globs, each of which would need to be stored.

    – Christoph Sommer
    Mar 26 at 1:43













  • yes it can not be the target, all regex phrased as a shell glob. yes, its not possible. but an approximation, a good compromise was possible as AHK script variant (released on githup). Useful only for the few that I can express in regEx in one line, but with Glob requires several. Shorter, more manageable, easier to edit. Of course, you can continue to simply write glob in it. These can be distinguished quite well. For example, a simple rule: no contain ``, then it's glob (I almost did it that way).

    – SL5net
    Mar 26 at 18:44
















0












0








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+)/**)[rn]/g, 'n!$2n$1n');
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









share|improve this question














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+)/**)[rn]/g, 'n!$2n$1n');
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






git regex autohotkey






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 11 at 10:39









SL5netSL5net

1114




1114













  • I'd caution against this. Regular expressions are vastly more powerful than shell globs. Many straightforward expressions simply cannot be phrased as a shell glob. Some can, but will need to be expanded from one regular expression to millions of alternative shell globs, each of which would need to be stored.

    – Christoph Sommer
    Mar 26 at 1:43













  • yes it can not be the target, all regex phrased as a shell glob. yes, its not possible. but an approximation, a good compromise was possible as AHK script variant (released on githup). Useful only for the few that I can express in regEx in one line, but with Glob requires several. Shorter, more manageable, easier to edit. Of course, you can continue to simply write glob in it. These can be distinguished quite well. For example, a simple rule: no contain ``, then it's glob (I almost did it that way).

    – SL5net
    Mar 26 at 18:44





















  • I'd caution against this. Regular expressions are vastly more powerful than shell globs. Many straightforward expressions simply cannot be phrased as a shell glob. Some can, but will need to be expanded from one regular expression to millions of alternative shell globs, each of which would need to be stored.

    – Christoph Sommer
    Mar 26 at 1:43













  • yes it can not be the target, all regex phrased as a shell glob. yes, its not possible. but an approximation, a good compromise was possible as AHK script variant (released on githup). Useful only for the few that I can express in regEx in one line, but with Glob requires several. Shorter, more manageable, easier to edit. Of course, you can continue to simply write glob in it. These can be distinguished quite well. For example, a simple rule: no contain ``, then it's glob (I almost did it that way).

    – SL5net
    Mar 26 at 18:44



















I'd caution against this. Regular expressions are vastly more powerful than shell globs. Many straightforward expressions simply cannot be phrased as a shell glob. Some can, but will need to be expanded from one regular expression to millions of alternative shell globs, each of which would need to be stored.

– Christoph Sommer
Mar 26 at 1:43







I'd caution against this. Regular expressions are vastly more powerful than shell globs. Many straightforward expressions simply cannot be phrased as a shell glob. Some can, but will need to be expanded from one regular expression to millions of alternative shell globs, each of which would need to be stored.

– Christoph Sommer
Mar 26 at 1:43















yes it can not be the target, all regex phrased as a shell glob. yes, its not possible. but an approximation, a good compromise was possible as AHK script variant (released on githup). Useful only for the few that I can express in regEx in one line, but with Glob requires several. Shorter, more manageable, easier to edit. Of course, you can continue to simply write glob in it. These can be distinguished quite well. For example, a simple rule: no contain ``, then it's glob (I almost did it that way).

– SL5net
Mar 26 at 18:44







yes it can not be the target, all regex phrased as a shell glob. yes, its not possible. but an approximation, a good compromise was possible as AHK script variant (released on githup). Useful only for the few that I can express in regEx in one line, but with Glob requires several. Shorter, more manageable, easier to edit. Of course, you can continue to simply write glob in it. These can be distinguished quite well. For example, a simple rule: no contain ``, then it's glob (I almost did it that way).

– SL5net
Mar 26 at 18:44












0






active

oldest

votes












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1413049%2fpreprocessor-for-gitignore-file-used-by-git-for-regex-support-and-more%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1413049%2fpreprocessor-for-gitignore-file-used-by-git-for-regex-support-and-more%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How do I know what Microsoft account the skydrive app is syncing to?

When does type information flow backwards in C++?

Grease: Live!