Skip to content

Instantly share code, notes, and snippets.

@Rulexec
Created January 23, 2024 08:19
Show Gist options
  • Save Rulexec/92629b80e43b53bc2c237204b430c348 to your computer and use it in GitHub Desktop.
Save Rulexec/92629b80e43b53bc2c237204b430c348 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const child_process = require('child_process');
const texts = process.argv.slice(2);
(async () => {
const commandsDef = texts.map((text, index) => {
const isFirst = index === 0;
const isLast = index === texts.length - 1;
return {
command: isFirst ? 'rg' : 'xargs',
args: [...(isFirst ? [] : ['rg']), '-g', '!node_modules/', '-lF', text],
isFirst,
isLast,
};
});
let prevChild;
commandsDef.forEach(({command, args, isLast}) => {
const child = child_process.spawn(command, args, {
stdio: [
prevChild ? prevChild.stdout : 'ignore',
isLast ? 'inherit' : 'pipe',
'inherit',
],
});
prevChild = child;
});
})().catch((error) => {
console.error(error);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment