jump 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,3 +1,8 @@
1
+ Thu Feb 21 12:49:52 CET 2013 Flavio Castelli <flavio@castelli.name>
2
+
3
+ Version 0.3.2:
4
+ * complete even after the first children.
5
+
1
6
  Wed Feb 06 09:08:54 CET 2013 Flavio Castelli <flavio@castelli.name>
2
7
 
3
8
  Version 0.3.1:
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # tools
4
+ gem 'rake'
5
+ gem 'jeweler'
6
+
7
+ # devel deps
8
+ gem 'fakefs'
9
+
10
+ # runtime deps
11
+ gem 'terminal-table', '>= 1.4.4'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -28,7 +28,7 @@ _jump()
28
28
 
29
29
  if [[ ${prev} == "-d" || ${prev} == "--del" ]] ; then
30
30
  # complete the del command with a list of the available bookmarks
31
- local bookmarks=$(jump --bc)
31
+ local bookmarks=$(jump --complete)
32
32
  COMPREPLY=( $(compgen -W "${bookmarks}" -- ${cur}) )
33
33
  return 0
34
34
  fi
@@ -37,7 +37,7 @@ _jump()
37
37
  COMPREPLY="$(compgen -W "${opts}" -- ${cur}) "
38
38
  return 0
39
39
  else
40
- local bookmarks=$(jump --bc ${cur})
40
+ local bookmarks=$(jump --complete ${cur})
41
41
  COMPREPLY=( $(compgen -W "${bookmarks}" -- ${cur}) )
42
42
  return 0
43
43
  fi
data/bin/jump-bin CHANGED
@@ -60,10 +60,10 @@ begin
60
60
  end
61
61
  opts.parse!
62
62
  rescue OptionParser::InvalidOption
63
- if $!.args.first == "--bc"
64
- # This is an hidden method used by bash_completion
63
+ if $!.args.first == "--complete"
64
+ # This is an hidden method used by the shell completion
65
65
  bookmarks = Bookmarks.new
66
- puts bookmarks.bash_completion(ARGV[0])
66
+ puts bookmarks.complete(ARGV[0])
67
67
  exit 0
68
68
  else
69
69
  STDERR.puts $!
data/lib/bookmarks.rb CHANGED
@@ -83,49 +83,34 @@ class Bookmarks
83
83
  end
84
84
  end
85
85
 
86
- def bash_completion text
87
- if text.nil? || text.empty?
88
- # nothing is provided -> return all the bookmarks
89
- @bookmarks.keys.sort.join(' ')
90
- elsif text.include? '/'
91
- if text.index('/') == 0
92
- # this is an absolute path (eg: /foo)
93
- return text
94
- end
86
+ def sorted_bookmarks() sorted_list @bookmarks.keys end
87
+ def sorted_list(terms) terms.sort.join ' ' end
95
88
 
96
- # [bookmark]/path
97
- bookmark = text[0, text.index('/')]
98
- path = text[text.index('/')+1, text.size]
99
- if @bookmarks.has_key?(bookmark)
100
- # this is a known bookmark
101
- entries = []
102
- Dir.foreach(@bookmarks[bookmark]) do |filename|
103
- next if !path.empty? && (filename =~ /\A#{path}.*/).nil?
104
- if File.directory?(File.join(@bookmarks[bookmark], filename))
105
- next if filename == "." || filename == ".."
106
- entries << File.join(bookmark, filename)
107
- end
108
- end
89
+ # Provide a list of completion options, starting with given prefix
90
+ def complete prefix
91
+ # Special cases:
92
+ # - nothing is provided: return all the bookmarks
93
+ # - absolute path: don't complete
94
+ return sorted_bookmarks if prefix.nil? || prefix.empty?
95
+ return prefix if prefix.start_with? File::SEPARATOR
109
96
 
110
- if entries.empty?
111
- text
112
- else
113
- entries << "#{bookmark}/"
114
- entries.sort.join(' ')
115
- end
116
- else
117
- # this is an unknown bookmark
118
- text
119
- end
120
- else
121
- # text could match one of the bookmarks
122
- matches = @bookmarks.keys.find_all { |b| b =~ /\A#{text}/ }
123
- if matches.empty?
124
- text
125
- else
126
- matches.sort.join(' ')
97
+ bookmark, path = prefix.split File::SEPARATOR, 2 # File.split only does path/basename
98
+
99
+ completions = [ ]
100
+ if path.nil?
101
+ # still in 1st element, could match several bookmarks
102
+ completions += @bookmarks.keys.find_all { |b| b.start_with? prefix }
103
+ elsif @bookmarks.has_key?(bookmark)
104
+ # bookmark known, complete further
105
+ completions += Dir.chdir(@bookmarks[bookmark]) do
106
+ Dir.glob(["#{path}*"]) \
107
+ .select { |f| File.directory? f } \
108
+ .collect { |f| File.join bookmark, f }
127
109
  end
128
110
  end
111
+ completions.map! { |d| d + File::SEPARATOR }
112
+ completions << prefix if completions.empty?
113
+ sorted_list completions
129
114
  end
130
115
 
131
116
  # Simplifies given path by replacing the user's homedir with ~
@@ -23,6 +23,7 @@ require 'bookmarks'
23
23
  require 'fileutils'
24
24
 
25
25
  class BookmarksTest < Test::Unit::TestCase
26
+
26
27
  def setup
27
28
  @test_bookmarks = { "foo" => "/tmp/foo",
28
29
  "bar" => "/tmp/bar",
@@ -35,7 +36,6 @@ class BookmarksTest < Test::Unit::TestCase
35
36
 
36
37
  @bookmarks = Bookmarks.new
37
38
  end
38
-
39
39
  end
40
40
 
41
41
  def test_expand_path
@@ -93,48 +93,5 @@ EOF
93
93
  assert_equal expected_bookmarks, contents
94
94
  end
95
95
  end
96
-
97
- def test_bash_completion
98
- FakeFS do
99
- FileUtils.rm "~/.jumprc"
100
- bookmarks = Bookmarks.new
101
- bookmarks.add("/home/flavio/templates", "templates")
102
- bookmarks.add("/home/flavio/templates", "test")
103
- bookmarks.add("/home/flavio/test/rails_app", "rails")
104
-
105
- FileUtils.mkdir_p "/home/flavio/templates/foo/bar"
106
- FileUtils.mkdir_p "/home/flavio/test/rails_app/log"
107
- FileUtils.mkdir_p "/home/flavio/test/rails_app/locale"
108
- FileUtils.mkdir_p "/home/flavio/test/rails_app/app/model"
109
- FileUtils.touch "/home/flavio/test/rails_app/local_file"
110
-
111
- # should handle absolute paths
112
- assert_equal "/rails", bookmarks.bash_completion('/rails')
113
-
114
- # should return all the bookmarks
115
- assert_equal "rails templates test", bookmarks.bash_completion(nil)
116
- assert_equal "rails templates test", bookmarks.bash_completion('')
117
-
118
- # no matches => should return the same text
119
- assert_equal "foo", bookmarks.bash_completion("foo")
120
-
121
- # should complete the text
122
- assert_equal "templates test", bookmarks.bash_completion("te")
123
- assert_equal "rails", bookmarks.bash_completion("ra")
124
-
125
- # /home/flavio/templates/bar doesn't exist => should return the same text
126
- assert_equal "templates/bar", bookmarks.bash_completion("templates/bar")
127
- assert_equal( "templates/bar/1/2",
128
- bookmarks.bash_completion("templates/bar/1/2"))
129
-
130
- # should expand the path
131
- assert_equal "rails/ rails/locale rails/log",
132
- bookmarks.bash_completion("rails/lo")
133
-
134
- # should expand the path
135
- assert_equal "rails/ rails/app rails/locale rails/log",
136
- bookmarks.bash_completion("rails/")
137
- end
138
- end
139
-
140
96
  end
97
+
@@ -0,0 +1,107 @@
1
+ # This file is part of the jump project
2
+ #
3
+ # Copyright (C) 2010 Flavio Castelli <flavio@castelli.name>
4
+ # Copyright (C) 2010 Giuseppe Capizzi <gcapizzi@gmail.com>
5
+ #
6
+ # jump is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # jump is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Keep; if not, write to the
18
+ # Free Software Foundation, Inc.,
19
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
+
21
+ require "test_helper"
22
+ require 'bookmarks'
23
+ require 'fileutils'
24
+
25
+ class BookmarkCompletionTest < Test::Unit::TestCase
26
+
27
+ def setup
28
+ FakeFS do
29
+ @bookmarks = Bookmarks.new
30
+ @bookmarks.add("/home/flavio/templates", "templates")
31
+ @bookmarks.add("/home/flavio/templates", "test")
32
+ @bookmarks.add("/home/flavio/test/rails_app", "rails")
33
+ @bookmarks.add("/home/flavio/test/another_rails_app", "rails2")
34
+
35
+ FileUtils.mkdir_p "/home/flavio/templates/foo/bar"
36
+ FileUtils.mkdir_p "/home/flavio/templates/baz"
37
+ FileUtils.mkdir_p "/home/flavio/test/rails_app/log"
38
+ FileUtils.mkdir_p "/home/flavio/test/rails_app/locale"
39
+ FileUtils.mkdir_p "/home/flavio/test/rails_app/app/model"
40
+ FileUtils.touch "/home/flavio/test/rails_app/local_file"
41
+ FileUtils.mkdir_p "/home/flavio/test/another_rails_app"
42
+ end
43
+ end
44
+
45
+ def test_absolute_path
46
+ FakeFS do
47
+ assert_equal "/rails", @bookmarks.complete('/rails')
48
+ end
49
+ end
50
+
51
+ def test_empty_completes_to_all
52
+ FakeFS do
53
+ assert_equal "rails rails2 templates test", @bookmarks.complete(nil)
54
+ assert_equal "rails rails2 templates test", @bookmarks.complete('')
55
+ end
56
+ end
57
+
58
+ def test_no_matches # => should return the same text
59
+ FakeFS do
60
+ assert_equal "foo", @bookmarks.complete("foo")
61
+ end
62
+ end
63
+
64
+ def test_no_matches_with_suffix
65
+ FakeFS do
66
+ assert_equal "foo/meh/zzz", @bookmarks.complete("foo/meh/zzz")
67
+ end
68
+ end
69
+
70
+ def test_prefix
71
+ FakeFS do
72
+ assert_equal "templates/ test/", @bookmarks.complete("te")
73
+ assert_equal "rails/ rails2/", @bookmarks.complete("ra")
74
+ end
75
+ end
76
+
77
+ def test_nonexisting_suffix
78
+ FakeFS do
79
+ # /home/flavio/templates/bar doesn't exist => should return the same text
80
+ assert_equal "templates/bar", @bookmarks.complete("templates/bar")
81
+ assert_equal "templates/bar/1/2",
82
+ @bookmarks.complete("templates/bar/1/2")
83
+ end
84
+ end
85
+
86
+ def test_completes_children_after_separator
87
+ FakeFS do
88
+ assert_equal "rails/app/ rails/locale/ rails/log/",
89
+ @bookmarks.complete("rails/")
90
+ end
91
+ end
92
+
93
+ def test_completes_suffix
94
+ FakeFS do
95
+ assert_equal "rails/locale/ rails/log/",
96
+ @bookmarks.complete("rails/lo")
97
+ end
98
+ end
99
+
100
+ def test_completes_suffix_path
101
+ FakeFS do
102
+ assert_equal "rails/app/model/",
103
+ @bookmarks.complete("rails/app/")
104
+ end
105
+ end
106
+
107
+ end
data/zsh_integration/jump CHANGED
@@ -31,7 +31,7 @@ _jump()
31
31
 
32
32
  if [[ ${prev} = "-d" || ${prev} = "--del" ]] ; then
33
33
  # complete the del command with a list of the available bookmarks
34
- reply=( $(jump-bin --bc) )
34
+ reply=( $(jump-bin --complete) )
35
35
  return 0
36
36
  fi
37
37
 
@@ -39,7 +39,7 @@ _jump()
39
39
  reply=( --help -h --add -a --del -d --list -l )
40
40
  return 0
41
41
  else
42
- reply=( $(jump-bin --bc ${cur}) )
42
+ reply=( $(jump-bin --complete ${cur}) )
43
43
  return 0
44
44
  fi
45
45
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,72 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-06 00:00:00.000000000 Z
13
+ date: 2013-02-21 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: jeweler
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: fakefs
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: terminal-table
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 1.4.4
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 1.4.4
15
79
  - !ruby/object:Gem::Dependency
16
80
  name: terminal-table
17
81
  requirement: !ruby/object:Gem::Requirement
@@ -59,6 +123,7 @@ extra_rdoc_files:
59
123
  files:
60
124
  - COPYING.txt
61
125
  - Changelog
126
+ - Gemfile
62
127
  - POST_INSTALL.txt
63
128
  - README.rdoc
64
129
  - Rakefile
@@ -67,6 +132,7 @@ files:
67
132
  - bash_integration/shell_driver
68
133
  - lib/bookmarks.rb
69
134
  - test/bookmarks_test.rb
135
+ - test/completion_test.rb
70
136
  - test/test_helper.rb
71
137
  - zsh_integration/jump
72
138
  - bin/jump-bin
@@ -110,4 +176,5 @@ signing_key:
110
176
  specification_version: 3
111
177
  summary: A bookmarking system for bash and zsh shells
112
178
  test_files:
179
+ - test/completion_test.rb
113
180
  - test/bookmarks_test.rb