jump 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.
- data/COPYING.txt +674 -0
- data/POST_INSTALL.txt +60 -0
- data/README.rdoc +108 -0
- data/Rakefile +88 -0
- data/VERSION +1 -0
- data/bash_integration/bash_completion/jump +55 -0
- data/bash_integration/shell_driver +28 -0
- data/bin/jump-bin +90 -0
- data/lib/bookmarks.rb +146 -0
- data/test/bookmarks_test.rb +139 -0
- data/test/test_helper.rb +24 -0
- metadata +175 -0
@@ -0,0 +1,139 @@
|
|
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
|
+
# kaveau 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
|
+
# kaveau 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 Steet, Fifth Floor, Boston, MA 02110-1301, USA.
|
20
|
+
|
21
|
+
require "test_helper"
|
22
|
+
require 'bookmarks'
|
23
|
+
require 'fileutils'
|
24
|
+
|
25
|
+
class BookmarksTest < Test::Unit::TestCase
|
26
|
+
def setup
|
27
|
+
@test_bookmarks = { "foo" => "/tmp/foo",
|
28
|
+
"bar" => "/tmp/bar",
|
29
|
+
"complex" => "/tmp/foo/bar/complex"}
|
30
|
+
FakeFS do
|
31
|
+
File.open(Bookmarks::BOOKMARKS_PATH, 'w') do |file|
|
32
|
+
file << YAML::dump(@test_bookmarks)
|
33
|
+
end
|
34
|
+
|
35
|
+
@bookmarks = Bookmarks.new
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_expand_path
|
41
|
+
@test_bookmarks.each do |bookmark, expected_path|
|
42
|
+
current_path = @bookmarks.expand_path bookmark
|
43
|
+
assert_equal expected_path, current_path
|
44
|
+
end
|
45
|
+
|
46
|
+
# check absolute path
|
47
|
+
assert_equal "/foo", @bookmarks.expand_path("/foo")
|
48
|
+
|
49
|
+
# check multiple / handling
|
50
|
+
assert_equal "/tmp/foo/1/2", @bookmarks.expand_path("foo/1/2")
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_add
|
54
|
+
# should add a new bookmark
|
55
|
+
bookmark = "flavio_home"
|
56
|
+
path = "/home/flavio"
|
57
|
+
@bookmarks.add(path, bookmark)
|
58
|
+
assert_equal path, @bookmarks.expand_path(bookmark)
|
59
|
+
|
60
|
+
#should update a bookmark
|
61
|
+
new_path = "/tmp"
|
62
|
+
@bookmarks.add(new_path, bookmark)
|
63
|
+
assert_equal new_path, @bookmarks.expand_path(bookmark)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_to_s
|
67
|
+
output = <<EOF
|
68
|
+
+----------+----------------------+
|
69
|
+
| Bookmark | Path |
|
70
|
+
+----------+----------------------+
|
71
|
+
| bar | /tmp/bar |
|
72
|
+
| complex | /tmp/foo/bar/complex |
|
73
|
+
| foo | /tmp/foo |
|
74
|
+
+----------+----------------------+
|
75
|
+
EOF
|
76
|
+
assert_equal output, @bookmarks.to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_save
|
80
|
+
bookmark = "flavio_home"
|
81
|
+
path = "/home/flavio"
|
82
|
+
@bookmarks.add(path, bookmark)
|
83
|
+
|
84
|
+
expected_bookmarks = @test_bookmarks.dup
|
85
|
+
expected_bookmarks[bookmark] = path
|
86
|
+
|
87
|
+
FakeFS do
|
88
|
+
@bookmarks.save
|
89
|
+
|
90
|
+
assert File.exists?(Bookmarks::BOOKMARKS_PATH)
|
91
|
+
contents = YAML::load_file Bookmarks::BOOKMARKS_PATH
|
92
|
+
assert_equal expected_bookmarks, contents
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_bash_completion
|
97
|
+
FakeFS do
|
98
|
+
FileUtils.rm "~/.jumprc"
|
99
|
+
bookmarks = Bookmarks.new
|
100
|
+
bookmarks.add("/home/flavio/templates", "templates")
|
101
|
+
bookmarks.add("/home/flavio/templates", "test")
|
102
|
+
bookmarks.add("/home/flavio/test/rails_app", "rails")
|
103
|
+
|
104
|
+
FileUtils.mkdir_p "/home/flavio/templates/foo/bar"
|
105
|
+
FileUtils.mkdir_p "/home/flavio/test/rails_app/log"
|
106
|
+
FileUtils.mkdir_p "/home/flavio/test/rails_app/locale"
|
107
|
+
FileUtils.mkdir_p "/home/flavio/test/rails_app/app/model"
|
108
|
+
FileUtils.touch "/home/flavio/test/rails_app/local_file"
|
109
|
+
|
110
|
+
# should handle absolute paths
|
111
|
+
assert_equal "/rails", bookmarks.bash_completion('/rails')
|
112
|
+
|
113
|
+
# should return all the bookmarks
|
114
|
+
assert_equal "rails templates test", bookmarks.bash_completion(nil)
|
115
|
+
assert_equal "rails templates test", bookmarks.bash_completion('')
|
116
|
+
|
117
|
+
# no matches => should return the same text
|
118
|
+
assert_equal "foo", bookmarks.bash_completion("foo")
|
119
|
+
|
120
|
+
# should complete the text
|
121
|
+
assert_equal "templates test", bookmarks.bash_completion("te")
|
122
|
+
assert_equal "rails", bookmarks.bash_completion("ra")
|
123
|
+
|
124
|
+
# /home/flavio/templates/bar doesn't exist => should return the same text
|
125
|
+
assert_equal "templates/bar", bookmarks.bash_completion("templates/bar")
|
126
|
+
assert_equal( "templates/bar/1/2",
|
127
|
+
bookmarks.bash_completion("templates/bar/1/2"))
|
128
|
+
|
129
|
+
# should expand the path
|
130
|
+
assert_equal "rails/ rails/locale rails/log",
|
131
|
+
bookmarks.bash_completion("rails/lo")
|
132
|
+
|
133
|
+
# should expand the path
|
134
|
+
assert_equal "rails/ rails/app rails/locale rails/log",
|
135
|
+
bookmarks.bash_completion("rails/")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
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
|
+
# kaveau 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
|
+
# kaveau 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 Steet, Fifth Floor, Boston, MA 02110-1301, USA.
|
20
|
+
|
21
|
+
require 'rubygems'
|
22
|
+
require 'test/unit'
|
23
|
+
require 'fakefs/safe'
|
24
|
+
require 'yaml'
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jump
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Flavio Castelli
|
14
|
+
- Giuseppe Capizzi
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-08-09 00:00:00 +02:00
|
20
|
+
default_executable: jump-bin
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: terminal-table
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: fakefs
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
description: |-
|
51
|
+
Jump is a tool that allows you to quickly change
|
52
|
+
directories in the bash shell using bookmarks.
|
53
|
+
Thanks to Jump, you won't have to type those long paths anymore.
|
54
|
+
|
55
|
+
Jump was inspired by go-tool by ActiveState
|
56
|
+
(http://code.google.com/p/go-tool/).
|
57
|
+
email:
|
58
|
+
- flavio@castelli.name
|
59
|
+
- gcapizzi@gmail.com
|
60
|
+
executables:
|
61
|
+
- jump-bin
|
62
|
+
extensions: []
|
63
|
+
|
64
|
+
extra_rdoc_files:
|
65
|
+
- README.rdoc
|
66
|
+
files:
|
67
|
+
- COPYING.txt
|
68
|
+
- POST_INSTALL.txt
|
69
|
+
- README.rdoc
|
70
|
+
- Rakefile
|
71
|
+
- VERSION
|
72
|
+
- bash_integration/bash_completion/jump
|
73
|
+
- bash_integration/shell_driver
|
74
|
+
- lib/bookmarks.rb
|
75
|
+
- test/bookmarks_test.rb
|
76
|
+
- test/test_helper.rb
|
77
|
+
- bin/jump-bin
|
78
|
+
has_rdoc: true
|
79
|
+
homepage: http://github.com/flavio/jump
|
80
|
+
licenses: []
|
81
|
+
|
82
|
+
post_install_message: |-
|
83
|
+
It's strongly recommended to install bash_completion. In this way you will have
|
84
|
+
the best user experience.
|
85
|
+
Linux users can install it using their package manager (apt, zypper, yum, emerge...),
|
86
|
+
while OSX users can install it via ports, fink or brew.
|
87
|
+
|
88
|
+
Now that jump is installed you have to create a file called 'jump' containing the
|
89
|
+
following text:
|
90
|
+
|
91
|
+
_jump()
|
92
|
+
{
|
93
|
+
local cur prev opts
|
94
|
+
COMPREPLY=()
|
95
|
+
cur="${COMP_WORDS[COMP_CWORD]}"
|
96
|
+
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
97
|
+
opts="--help -h --add -a --del -d --list -l"
|
98
|
+
|
99
|
+
if [[ ${prev} == -d || ${prev} == --d* ]] ; then
|
100
|
+
# complete the del command with a list of the available bookmarks
|
101
|
+
local bookmarks=$(jump --bc)
|
102
|
+
COMPREPLY=( $(compgen -W "${bookmarks}" -- ${cur}) )
|
103
|
+
return 0
|
104
|
+
fi
|
105
|
+
|
106
|
+
if [[ ${cur:0:1} == "-" ]]; then
|
107
|
+
COMPREPLY="$(compgen -W "${opts}" -- ${cur}) "
|
108
|
+
return 0
|
109
|
+
else
|
110
|
+
local bookmarks=$(jump --bc ${cur})
|
111
|
+
COMPREPLY=( $(compgen -W "${bookmarks}" -- ${cur}) )
|
112
|
+
return 0
|
113
|
+
fi
|
114
|
+
}
|
115
|
+
|
116
|
+
function jump {
|
117
|
+
#echo "jump called with $*"
|
118
|
+
if [ ${1:0:1} == "-" ]; then
|
119
|
+
jump-bin $*
|
120
|
+
else
|
121
|
+
cd $(jump-bin $*)
|
122
|
+
fi
|
123
|
+
}
|
124
|
+
|
125
|
+
complete -o nospace -F _jump jump
|
126
|
+
|
127
|
+
|
128
|
+
The file must be located inside of the 'bash_completion.d' directory, which is
|
129
|
+
usually located under /etc/.
|
130
|
+
|
131
|
+
If you do not want to install 'bash_completion' then add the following code
|
132
|
+
to your bash configuration file (e.g. '~/.bash_profile' or '~/.bashrc'):
|
133
|
+
|
134
|
+
function jump {
|
135
|
+
if [ ${1:0:1} == "-" ]; then
|
136
|
+
jump-bin $*
|
137
|
+
else
|
138
|
+
cd $(jump-bin $*)
|
139
|
+
fi
|
140
|
+
}
|
141
|
+
|
142
|
+
Beware: without bash_completion you won't be able use jump's advanced completion features.
|
143
|
+
rdoc_options:
|
144
|
+
- --line-numbers
|
145
|
+
- --main
|
146
|
+
- README.rdoc
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
hash: 3
|
155
|
+
segments:
|
156
|
+
- 0
|
157
|
+
version: "0"
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
hash: 3
|
164
|
+
segments:
|
165
|
+
- 0
|
166
|
+
version: "0"
|
167
|
+
requirements: []
|
168
|
+
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 1.3.7
|
171
|
+
signing_key:
|
172
|
+
specification_version: 3
|
173
|
+
summary: A bookmarking system for the bash shell
|
174
|
+
test_files:
|
175
|
+
- test/bookmarks_test.rb
|