proxyconf 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MjA5ZjAxMmM3ZGU5MDcwMDUxODU4ZjJkNjc4ZTVmMWYwNmRhOWU1Mw==
5
- data.tar.gz: !binary |-
6
- ZjI2ZDNmOGY2NWIxMDRhM2NmODZmZWVhMjY2MTcwZGE3NGNiZDIyNg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NjA3ODEzZDAxNDhmYzQ4MGVhYmNkN2MwNjBiOGIzNDk4NTdkNjg2NzdhYjJl
10
- MjU4OWU5YWM0ZDZiMTVlN2I0N2U5NGZiN2YwNjNkNjliMTJjYjM4OWRiN2Qy
11
- NTUxMmNiOWQxYmJhODhkYjIzMDlmNWJhYWY2ZTlhNmJlMzA4MTg=
12
- data.tar.gz: !binary |-
13
- MDY1NTI2ZjNiN2EzNTY3YWY5MWNmOGY0YTQwNzA5M2FhZWZmN2ZjNzYxMmQ1
14
- MmUzNzVmODQ4N2ExNGMxNjA5NmY1M2M2YjM1OTE5Y2RiMjE2ZjYyMTFhODM5
15
- YmFhZjUzM2QzY2ZlMDUyNThjNGU1NzBkNTMyODdmOGUxNWFmMmQ=
2
+ SHA1:
3
+ metadata.gz: 600560f03316c3df570651c9a0d53b90b4a8065e
4
+ data.tar.gz: 03c148bc6da776379c9cf454d57b40f2d7e7e68c
5
+ SHA512:
6
+ metadata.gz: 569ffa06b47bacabd24edcb1d65cbcacac74c5566d1b026a71a2fbcf791ae512ff0a3243b3161ad070b60e8c5cc78667b3b598485e516e1b25f116a76d0d8f56
7
+ data.tar.gz: 17957483d63153481c9547fb363a6af73e59623c860a7c75090f03898f06d3f15e7adb1832027feb7b3d19872d5af8ff7b476083b4af26aadf8ec043d99795b4
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # proxyconf
2
2
 
3
3
  proxyconf is a proxy switcher for terminal.
4
+ proxyconf automatically switch proxy depends on System Preference by default.
4
5
 
5
6
  proxyconf currently supports Mac only.
6
7
 
8
+
7
9
  ## Installation
8
10
 
9
11
  First, install proxyconf via gem.
@@ -15,6 +17,19 @@ Second, setup using proxyconf-setup command
15
17
  $ proxyconf-setup
16
18
 
17
19
  then it creates ~/.proxyconf directory and append setting for proxyconf into your ~/.bash_profile.
20
+ You can use proxyconf command when you open new terminal, or type below to use immediately.
21
+
22
+ $ source "$HOME/.proxyconf/proxyconf"
23
+
24
+
25
+ ## Update from previous version
26
+
27
+ If you use previous version of proxyconf, follow steps below to update.
28
+
29
+ $ gem update proxyconf
30
+ $ proxyconf-setup update
31
+ $ source "$HOME/.proxyconf/proxyconf"
32
+
18
33
 
19
34
  ## Usage
20
35
 
@@ -24,6 +39,29 @@ Simply type proxyconf in your terminal.
24
39
 
25
40
  Then proxyconf exports environment variable 'http_proxy', 'https_proxy' and 'ftp_proxy' based on your system preference.
26
41
 
42
+ If you want to use other proxy, use 'add' and 'use' command.
43
+
44
+ $ proxyconf add other other.proxy.com:8080
45
+ $ proxyconf use other
46
+
47
+ 'add' command creates new proxy setting, and 'use' command exports environment variables.
48
+ You can check out proxy settings already added using 'list' and 'info' command.
49
+
50
+ $ proxyconf list
51
+ current
52
+ other
53
+ $ proxyconf info other
54
+ export http_proxy=other.proxy.com:8080
55
+ export ftp_proxy=other.proxy.com:8080
56
+ export https_proxy=other.proxy.com:8080
57
+
58
+ You can remove proxy setting using 'remove' command.
59
+
60
+ $ proxyconf remove other
61
+ $ proxyconf list
62
+ current
63
+
64
+
27
65
  ## Contributing
28
66
 
29
67
  1. Fork it
@@ -5,12 +5,23 @@ require 'fileutils'
5
5
  HOME = File.expand_path('~')
6
6
  PROXYCONF_HOME = "#{HOME}/.proxyconf"
7
7
 
8
+ def create_proxyconf_sh
9
+ target = File.expand_path(File.join(File.dirname(__FILE__), "../script/proxyconf"))
10
+ link = File.join(PROXYCONF_HOME, "proxyconf")
11
+ if File.exist?(link)
12
+ File.delete link
13
+ elsif File.symlink? link
14
+ File.unlink link
15
+ end
16
+ File.symlink(target, link)
17
+ end
18
+
8
19
  # copy template files into ~/.proxyconf
9
20
  def create_proxyconf_home
10
21
  FileUtils.mkdir_p PROXYCONF_HOME
22
+ create_proxyconf_sh
11
23
  template_path = File.join(File.dirname(__FILE__), '../template')
12
24
  src = [
13
- File.join(template_path, "proxyconf"),
14
25
  File.join(template_path, "proxies")
15
26
  ]
16
27
  FileUtils.cp_r(src, PROXYCONF_HOME)
@@ -42,4 +53,16 @@ def setup
42
53
  update_bashconfig
43
54
  end
44
55
 
45
- setup
56
+ def update
57
+ create_proxyconf_sh
58
+ end
59
+
60
+ subcommand = ARGV[0]
61
+ case subcommand
62
+ when nil
63
+ setup
64
+ when 'update'
65
+ update
66
+ else
67
+ puts "unknown subcommand: #{subcommand}"
68
+ end
@@ -1,10 +1,24 @@
1
1
  require "proxyconf/version"
2
+ require "proxyconf/engine"
2
3
  require "proxyconf/cli"
3
4
 
4
5
  module ProxyConf
6
+ HOME = "#{File.expand_path('~')}/.proxyconf"
7
+ PROXIES_DIR = "proxies"
5
8
  end
6
9
 
7
- if true
10
+ proxies_dir_path = File.join(ProxyConf::HOME, ProxyConf::PROXIES_DIR)
11
+ unless File.exist? proxies_dir_path
12
+ puts "proxyconf home not found. do 'proxyconf-setup' first."
13
+ exit 1
14
+ end
15
+
16
+ case RbConfig::CONFIG['host_os']
17
+ when /darwin/
18
+ # MacOSX
8
19
  require "proxyconf/mac"
9
20
  ProxyConf::Cli.engine = ProxyConf::Mac.new
21
+ else
22
+ puts 'your operating system is not supported, sorry.'
23
+ exit 1
10
24
  end
@@ -12,16 +12,36 @@ module ProxyConf
12
12
  engine.export
13
13
  end
14
14
 
15
+ desc 'add name proxy', 'add proxy setting into ~/.proxyconf/proxies'
16
+ def add(name, proxy)
17
+ engine.add(name, proxy)
18
+ end
19
+
20
+ desc 'remove name', 'remove proxy specified by name'
21
+ def remove(name)
22
+ engine.remove(name)
23
+ end
24
+
25
+ desc 'info', 'show proxy setting for specifed name'
26
+ def info(name)
27
+ engine.info(name)
28
+ end
29
+
30
+ desc 'list', 'list all proxy settings'
31
+ def list
32
+ engine.list
33
+ end
34
+
35
+ desc 'version', 'show version'
36
+ def version
37
+ puts ProxyConf::VERSION
38
+ end
39
+
15
40
  desc 'active_network', 'show active network service name'
16
41
  def active_network
17
42
  puts engine.active_network
18
43
  end
19
44
 
20
- desc 'test', 'test'
21
- def proxy_info
22
- puts engine.proxy_info
23
- end
24
-
25
45
  private
26
46
  def engine
27
47
  self.class.engine
@@ -0,0 +1,62 @@
1
+ require 'uri'
2
+
3
+ module ProxyConf
4
+ class Engine
5
+ def add(name, proxy)
6
+ validate_name name
7
+ validate_uri proxy
8
+ filepath = File.join(ProxyConf::HOME, ProxyConf::PROXIES_DIR, name)
9
+ File.open(filepath, "w") do |file|
10
+ file.puts "export http_proxy=#{proxy}"
11
+ file.puts "export ftp_proxy=#{proxy}"
12
+ file.puts "export https_proxy=#{proxy}"
13
+ end
14
+ end
15
+
16
+ def remove(name)
17
+ if_exists(name) do |filepath|
18
+ File.delete(filepath)
19
+ end
20
+ end
21
+
22
+ def info(name)
23
+ if_exists(name) do |filepath|
24
+ puts File.read(filepath)
25
+ end
26
+ end
27
+
28
+ def list
29
+ path = File.join(ProxyConf::HOME, ProxyConf::PROXIES_DIR, "*")
30
+ Dir.glob(path).each do |filepath|
31
+ puts File.basename(filepath)
32
+ end
33
+ end
34
+
35
+ protected
36
+
37
+ def validate_name(name)
38
+ unless name =~ /^[0-9a-zA-Z_\-]*$/
39
+ $stderr.puts "invalid name: #{name}"
40
+ exit 1
41
+ end
42
+ end
43
+
44
+ def validate_uri(uri)
45
+ begin
46
+ URI.parse(uri)
47
+ rescue URI::InvalidURIError
48
+ $stderr.puts "invalid proxy uri: #{uri}"
49
+ exit 1
50
+ end
51
+ end
52
+
53
+ def if_exists(name, &block)
54
+ filepath = File.join(ProxyConf::HOME, ProxyConf::PROXIES_DIR, name)
55
+ if File.exist? filepath
56
+ block.call(filepath)
57
+ else
58
+ $stderr.puts "no such proxy name: #{name}"
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,7 +1,7 @@
1
1
  require 'yaml'
2
2
 
3
3
  module ProxyConf
4
- class Mac
4
+ class Mac < ProxyConf::Engine
5
5
  private
6
6
 
7
7
  def scutil_query(key)
@@ -11,7 +11,6 @@ get #{key}
11
11
  d.show
12
12
  close
13
13
  EOF
14
- #return
15
14
  IO.popen("scutil", "r+") do |io|
16
15
  io.puts send_data
17
16
  io.close_write
@@ -1,3 +1,3 @@
1
1
  module ProxyConf
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.version = ProxyConf::VERSION
9
9
  spec.authors = ["daixque"]
10
10
  spec.email = ["daixque@gmail.com"]
11
- spec.description = %q{proxyconf configurates proxy setting of terminal.}
11
+ spec.description = %q{proxyconf configurates proxy setting for terminal depends on System Preference.}
12
12
  spec.summary = %q{proxy switcher for terminal}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/daixque/proxyconf"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env bash
2
+
3
+ PROXYCONF_CMD=proxyconf-core
4
+ PROXYCONF_HOME=~/.proxyconf
5
+
6
+ __proxyconf_usage ()
7
+ {
8
+ cat <<EOF
9
+ usage:
10
+ $ proxyconf [command]
11
+
12
+ if command is not given, 'update' command will used.
13
+
14
+ commands:
15
+ update
16
+ update proxy setting for active network service.
17
+ help
18
+ show usage
19
+ add name proxy
20
+ add proxy setting into ~/.proxyconf/proxies
21
+ remove name
22
+ remove proxy specified by name
23
+ info name
24
+ show proxy setting for specifed name
25
+ list
26
+ list all proxy settings
27
+ use name
28
+ update proxy setting specified by name
29
+ EOF
30
+ }
31
+
32
+ __proxyconf_use ()
33
+ {
34
+ target_proxy_file=$PROXYCONF_HOME/proxies/$1
35
+ if ! [[ -f $target_proxy_file ]] ; then
36
+ echo 'no such proxy name:' $1 >&2
37
+ exit 1
38
+ fi
39
+ . $target_proxy_file
40
+ echo "set proxy:" $http_proxy
41
+ }
42
+
43
+ __proxyconf_update ()
44
+ {
45
+ $PROXYCONF_CMD export > $PROXYCONF_HOME/proxies/current
46
+ __proxyconf_use current
47
+ }
48
+
49
+ __proxyconf_deligate ()
50
+ {
51
+ $PROXYCONF_CMD $*
52
+ }
53
+
54
+ proxyconf ()
55
+ {
56
+ case $1 in
57
+ "") __proxyconf_update ;;
58
+ "update") __proxyconf_update ;;
59
+ "help") __proxyconf_usage ;;
60
+ "add") __proxyconf_deligate $* ;;
61
+ "remove") __proxyconf_deligate $* ;;
62
+ "info") __proxyconf_deligate $* ;;
63
+ "list") __proxyconf_deligate $* ;;
64
+ "use") __proxyconf_use $2 ;;
65
+ "-v") $PROXYCONF_CMD version ;;
66
+ * )
67
+ echo "unknown command:" $1
68
+ echo "type 'proxyconf help' to show usage";;
69
+ esac
70
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxyconf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - daixque
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-07 00:00:00.000000000 Z
11
+ date: 2013-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,31 +28,31 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: thor
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: proxyconf configurates proxy setting of terminal.
55
+ description: proxyconf configurates proxy setting for terminal depends on System Preference.
56
56
  email:
57
57
  - daixque@gmail.com
58
58
  executables:
@@ -70,13 +70,13 @@ files:
70
70
  - bin/proxyconf-setup
71
71
  - lib/proxyconf.rb
72
72
  - lib/proxyconf/cli.rb
73
+ - lib/proxyconf/engine.rb
73
74
  - lib/proxyconf/mac.rb
74
- - lib/proxyconf/sh.rb
75
75
  - lib/proxyconf/version.rb
76
76
  - proxyconf.gemspec
77
+ - script/proxyconf
77
78
  - template/proxies/current
78
- - template/proxyconf
79
- homepage: ''
79
+ homepage: https://github.com/daixque/proxyconf
80
80
  licenses:
81
81
  - MIT
82
82
  metadata: {}
@@ -86,12 +86,12 @@ require_paths:
86
86
  - lib
87
87
  required_ruby_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ! '>='
89
+ - - '>='
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
@@ -1,4 +0,0 @@
1
- module ProxyConf
2
- module Sh
3
- end
4
- end
@@ -1,45 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- PROXYCONF_CMD=proxyconf-core
4
- PROXYCONF_HOME=~/.proxyconf
5
-
6
- __proxyconf_usage ()
7
- {
8
- cat <<EOF
9
- usage:
10
- $ proxyconf [command]
11
-
12
- if command is not given, 'update' command will used.
13
-
14
- commands:
15
- update
16
- update proxy setting for active network service.
17
- help
18
- show usage
19
- EOF
20
- }
21
-
22
- __proxyconf_use ()
23
- {
24
- . $PROXYCONF_HOME/proxies/$1
25
- echo "set proxy:" $http_proxy
26
-
27
- }
28
-
29
- __proxyconf_update ()
30
- {
31
- $PROXYCONF_CMD export > $PROXYCONF_HOME/proxies/current
32
- __proxyconf_use current
33
- }
34
-
35
- proxyconf ()
36
- {
37
- case $1 in
38
- "") __proxyconf_update ;;
39
- "update") __proxyconf_update ;;
40
- "help") __proxyconf_usage ;;
41
- * )
42
- echo "unknown command:" $1
43
- echo "type 'proxyconf help' to show usage";;
44
- esac
45
- }