Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added shell completions

  • Loading branch information...
commit f866a251c867fba0ef3fcc0f3e9b8f234f412020 1 parent e47d961
@elentok authored
Showing with 36 additions and 5 deletions.
  1. +19 −5 bin/dns
  2. +17 −0 completions/_dns
View
24 bin/dns
@@ -1,5 +1,6 @@
#!/usr/bin/env coffee
+path = require 'path'
nomnom = require 'nomnom'
clc = require 'cli-color'
MacDnsSwitcher = require '../lib/mac_dns_switcher'
@@ -29,13 +30,27 @@ nomnom.option 'profile',
position: 0
help: 'the name of the dns profile'
+nomnom.option 'completions',
+ flag: true
+ help: "shows the completion code to add to .zshrc"
+ callback: ->
+ dir = path.resolve(path.join(__dirname, '..', 'completions'))
+ console.log "fpath=(#{dir} $fpath)"
+ console.log "compinit"
options = nomnom.parse()
switcher = new MacDnsSwitcher(network_service: options.device)
+showStatus = ->
+ console.log clc.blue('DNS Servers:')
+ console.log switcher.getDnsServers()
+ console.log clc.blue('DNS Search Domains:')
+ console.log switcher.getSearchDomains()
+
if options.reset
console.log clc.green('Resetting...')
switcher.activate({})
+ showStatus()
else if options.profile
profile = Profile.findByName(options.profile)
@@ -44,10 +59,9 @@ else if options.profile
switcher.activate(profile)
else
console.log clc.red("Invalid profile '#{options.profile}'")
+ showStatus()
-unless options.list
- console.log clc.blue('DNS Servers:')
- console.log switcher.getDnsServers()
- console.log clc.blue('DNS Search Domains:')
- console.log switcher.getSearchDomains()
+else
+ unless options.completions or options.list
+ showStatus()
View
17 completions/_dns
@@ -0,0 +1,17 @@
+#compdef dns
+
+_dns() {
+ local curcontext="$curcontext" state line
+ typeset -A opt_args
+
+ _arguments \
+ '1: :->command'
+
+ case $state in
+ command)
+ _arguments "1:Args:(`dns --list` --completions -l --list -r --reset -d --device)"
+ ;;
+ esac
+}
+
+_dns "$@"
Please sign in to comment.
Something went wrong with that request. Please try again.