Created
February 27, 2018 16:22
-
-
Save lionello/e5c045f9406a1dd9b0a17e0516aa95ab to your computer and use it in GitHub Desktop.
NodeJS script to import a 1password tab-delimited TXT file into 'pass'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const FS = require('fs') | |
const URL = require('url') | |
const Child_process = require('child_process') | |
const all = FS.readFileSync('pww.txt', {encoding:'utf8'}) | |
const regex = /\n(?:"([^"]*)")?\t"([^"]*)"\t"([^"]*)"\t"([^"]*)"\t"([^"]*)"\t(?:"([^"]*)")?/mg | |
while (true) { | |
const match = regex.exec(all) | |
if (!match) break | |
const [_,Notes,Password,Title,Type,url,Username] = match | |
var host = URL.parse(url).host || Title | |
if (host.indexOf(Title) > 0) | |
host = Title | |
host = host.replace(/^www\./i,'') | |
const user = Username ? '/'+Username : '' | |
const passname = host+user | |
console.log(passname, Password) | |
const output = Child_process.spawnSync('pass',['insert','-m',passname], {input:Password, encoding:'utf8'}) | |
console.error(output.output[2]) | |
if (Notes) { | |
const output2 = Child_process.spawnSync('pass',['insert','-m','Notes/'+passname], {input:Notes, encoding:'utf8'}) | |
console.error(output2.output[2]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment