sshconf-upsert

0.0.1 • Public • Published

sshconf-upsert

Upsert hosts into your ~/.ssh/config file(s).

Installation

$ npm install sshconf-upsert

Usage

require('sshconf-upsert')(contents, hosts, callback)

var upsert = require('sshconf-upsert')
  , fs = require('fs')
 
var config = fs.readFileSync(process.env.HOME + '/.ssh/config', 'utf8')
 
upsert(config, [{
  Host: 'second',
  HostName: 'google.com'
}, {
  Host: 'third',
  HostName: '192.167.2.16'
}], function(err, upserted) {
  fs.writeFileSync(process.env.HOME + '/.ssh/config', upserted)
})

Essentially, sshconf-upsert takes a config string and an array of hosts, returning an updated version. Existing entries will be modified, and missing ones added to the end. The above script should take this:

Host first
  HostName 192.168.2.1
 
# comments and formatting
# are preserved
 
Host second
  HostName 192.168.2.4

And turn it into this:

Host first
  HostName 192.168.2.1
 
# comments and formatting
# are preserved
 
Host second
  HostName google.com
 
Host third
  HostName 192.168.2.16

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.1
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.1
    2

Package Sidebar

Install

npm i sshconf-upsert

Weekly Downloads

2

Version

0.0.1

License

MIT

Last publish

Collaborators

  • hughsk