Sunday, May 17, 2020

node/shell mashup to get stuff done

Once upon a time I used Perl for everything - shell-script type stuff as well as Web CGI.

For a while PHP became a similar go to for everything- it's a little unusual to do shell-script stuff in it, but it's pretty handy.

Now, I've grown some comfortable with JS/ECMAScript for handling arrays and filtering and what not I'd like to use it, but I'm a little lazy about looking up the syntax for the actual file operations - so I treat it as a text manipulation exercise, and go back and forth copy and pasting with a terminal window.

For example, for a big PDF conversion, I did an `ls` in Terminal (sometimes piping it to cat to make sure it was a single column, and then pasted that as a big quote in a .js file:

const raw = `some file.pdf
someo therfile.pdf
yet another_file.pdf`;

then something like

let c = 1;
const origs = raw.split('\n');
for (orig of origs) {
    console.log(`mv 'orig/${orig}' convert/${c}.pdf`);
    c++;
}

running that in node gives me a list of shell operations I can review and tweak if needed, and then copy and paste and run.

It ain't pretty but one off tasks don't have to be :-D

No comments:

Post a Comment