Skip to content

Instantly share code, notes, and snippets.

@lionello
Created February 27, 2018 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lionello/e5c045f9406a1dd9b0a17e0516aa95ab to your computer and use it in GitHub Desktop.
Save lionello/e5c045f9406a1dd9b0a17e0516aa95ab to your computer and use it in GitHub Desktop.
NodeJS script to import a 1password tab-delimited TXT file into 'pass'
#!/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