warp-dir 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/rubocop.yml +27 -0
- data/.github/workflows/ruby.yml +27 -0
- data/.github/workflows/shellcheck.yml +18 -0
- data/.gitignore +1 -1
- data/.idea/runConfigurations/All_Specs.xml +6 -9
- data/.relaxed-rubocop-2.5.yml +153 -0
- data/.rspec +1 -0
- data/.rubocop.yml +40 -1154
- data/.rubocop_todo.yml +685 -0
- data/Gemfile +9 -0
- data/LICENSE +2 -2
- data/README.adoc +244 -0
- data/Rakefile +19 -61
- data/bin/console +5 -4
- data/bin/warp-dir.bash +220 -54
- data/exe/warp-dir +3 -2
- data/lib/warp/dir/app/cli.rb +5 -5
- data/lib/warp/dir/app/response.rb +8 -10
- data/lib/warp/dir/command/clean.rb +1 -1
- data/lib/warp/dir/command/help.rb +0 -1
- data/lib/warp/dir/command/install.rb +12 -15
- data/lib/warp/dir/command/ls.rb +3 -3
- data/lib/warp/dir/command.rb +2 -2
- data/lib/warp/dir/config.rb +1 -1
- data/lib/warp/dir/errors.rb +3 -0
- data/lib/warp/dir/formatter.rb +2 -2
- data/lib/warp/dir/point.rb +1 -2
- data/lib/warp/dir/serializer/dotfile.rb +1 -1
- data/lib/warp/dir/store.rb +2 -2
- data/lib/warp/dir/version.rb +23 -19
- data/lib/warp/dir.rb +6 -6
- data/warp-dir.gemspec +15 -9
- metadata +69 -23
- data/.atom-build.json +0 -22
- data/.codeclimate.yml +0 -22
- data/.travis.yml +0 -13
- data/Guardfile +0 -14
- data/README.md +0 -181
- data/ROADMAP.md +0 -96
data/README.adoc
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
= Warp Directory
|
2
|
+
:author: Version v1.7.0
|
3
|
+
:doctype: book
|
4
|
+
:source-highlighter: rouge
|
5
|
+
:rouge-style: base16.monokai
|
6
|
+
:toclevels: 5
|
7
|
+
:toc:
|
8
|
+
:sectnums: 9
|
9
|
+
:icons: font
|
10
|
+
:license: MIT
|
11
|
+
|
12
|
+
|
13
|
+
image:https://github.com/kigster/warp-dir/actions/workflows/ruby.yml/badge.svg[Specs,link=https://github.com/kigster/warp-dir/actions/workflows/ruby.yml]
|
14
|
+
image:https://github.com/kigster/warp-dir/actions/workflows/rubocop.yml/badge.svg[Rubocop,link=https://github.com/kigster/warp-dir/actions/workflows/rubocop.yml]
|
15
|
+
image:https://github.com/kigster/warp-dir/actions/workflows/shellcheck.yml/badge.svg[ShellCheck,link=https://github.com/kigster/warp-dir/actions/workflows/shellcheck.yml]
|
16
|
+
|
17
|
+
image:https://ruby-gem-downloads-badge.herokuapp.com/warp-dir?type=total[Downloads,link=https://rubygems.org/gems/warp-dir]
|
18
|
+
image:https://badge.fury.io/rb/warp-dir.svg[Gem Version,link=https://badge.fury.io/rb/warp-dir]
|
19
|
+
image:https://img.shields.io/gitter/room/gitterHQ/gitter.svg[Gitter,link=https://gitter.im/kigster/warp-dir]
|
20
|
+
|
21
|
+
image::https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkigster%2Fwarp-dir.svg?type=large[FOSSA Status,link=https://app.fossa.com/projects/git%2Bgithub.com%2Fkigster%2Fwarp-dir?ref=badge_large]
|
22
|
+
|
23
|
+
TIP: You can read this README in a nicely formatted xref:README.pdf[PDF Document].
|
24
|
+
|
25
|
+
This is a ruby implementation of the tool `wd` (warp directory), https://github.com/mfaerevaag/wd[originally written as a `ZSH` module] by https://github.com/mfaerevaag[Markus Færevaag].
|
26
|
+
|
27
|
+
I personally went back to `bash` after trying out `ZSH`, but it was the `wd` plugin that I really missed.
|
28
|
+
|
29
|
+
While Markus kindly offered a ruby version in a https://github.com/mfaerevaag/wd/tree/ruby[separate branch of this module],
|
30
|
+
it wasn't quite as extensible as I wanted to (or well tested), so it ended up being an inspiration for this gem.
|
31
|
+
|
32
|
+
== Warp This
|
33
|
+
|
34
|
+
WarpDir is a UNIX command line tool that works somewhat similar to the standard built-in command `cd` -- "change directory".
|
35
|
+
|
36
|
+
The main difference is that `wd` is able to add/remove/list folder "shortcuts", and allows you to jump to these shortcuts from anywhere on the filesystem.
|
37
|
+
|
38
|
+
This of this as a folder-navigation super-charge tool that you'd use on a most frequently-used set of folders. This becomes *really useful* if you are often finding yourself going into a small number of deeply nested folders with a long path prefix.
|
39
|
+
|
40
|
+
== Installation
|
41
|
+
|
42
|
+
Three steps:
|
43
|
+
|
44
|
+
* `wd` requires a Ruby interpreter version 2.2 higher.
|
45
|
+
** Please Check your default ruby with `ruby --version`. You should see something like "ruby 2.3.0p0....".
|
46
|
+
** If you see version 1.9 or earlier, please upgrade your ruby using the package manager native to your OS.
|
47
|
+
* Install `warp-dir` ruby gem (note: you may need to prefix the command with `sudo` if you are installing into the "system" ruby namespace).
|
48
|
+
+
|
49
|
+
[source,bash]
|
50
|
+
----
|
51
|
+
$ gem install warp-dir
|
52
|
+
----
|
53
|
+
|
54
|
+
* The last step is to install the `wd` BASH function and auto-completion. This step appends the required shell function to your shell initialization file, that is specified with the `warp-dir install --dotfile <shell-dot-file>` command:
|
55
|
+
+
|
56
|
+
[source,bash]
|
57
|
+
----
|
58
|
+
$ warp-dir install --dotfile ~/.bash_profile
|
59
|
+
Shell support is installed in the following files:
|
60
|
+
/Users/kig/.bash_profile
|
61
|
+
$ source ~/.bash_profile
|
62
|
+
# Now we can use 'wd' shortcut
|
63
|
+
$ wd --help
|
64
|
+
----
|
65
|
+
|
66
|
+
After the last step you *need to restart your session*, so -- if you are on Mac OS X, -- please reopen your Terminal or better yet -- https://www.iterm2.com/[iTerm2], and then type:
|
67
|
+
|
68
|
+
[source,bash]
|
69
|
+
----
|
70
|
+
$ wd help
|
71
|
+
----
|
72
|
+
|
73
|
+
If the above command returns a properly formatted help that looks like the image below, your setup is now complete!
|
74
|
+
|
75
|
+
image:https://raw.githubusercontent.com/kigster/warp-dir/master/doc/wd-help.png[Image]
|
76
|
+
|
77
|
+
== Usage
|
78
|
+
|
79
|
+
NOTE: in the below examples, the characters `~ ❯ ` denote the current shell prompt, showing the current folder you are in. The command to type is on the right hand side of the "❯".
|
80
|
+
|
81
|
+
Let's first bookmark a long directory:
|
82
|
+
|
83
|
+
[source,bash]
|
84
|
+
----
|
85
|
+
~ ❯ cd ~/workspace/arduino/robots/command-bridge/src
|
86
|
+
~/workspace/arduino/robots/command-bridge/src ❯ wd add cbsrc
|
87
|
+
Warp point saved!
|
88
|
+
|
89
|
+
~/workspace/arduino/robots/command-bridge/src ❯ cd ~/workspace/c++/foo/src
|
90
|
+
~/workspace/c++/foo/src ❯ wd add foosrc
|
91
|
+
Warp point saved!
|
92
|
+
|
93
|
+
~/workspace/c++/foo/src ❯ cd /usr/local/Cellar
|
94
|
+
/usr/local/Cellar ❯ wd add brew
|
95
|
+
Warp point saved!
|
96
|
+
----
|
97
|
+
|
98
|
+
Now we can list/inspect current set of warp points:
|
99
|
+
|
100
|
+
[source,bash]
|
101
|
+
----
|
102
|
+
/usr/local/Cellar ❯ wd l
|
103
|
+
cbsrc -> ~/workspace/arduino/robots/command-bridge/src
|
104
|
+
foosrc -> ~/workspace/c++/foo/src
|
105
|
+
brew -> /usr/local/Cellar
|
106
|
+
----
|
107
|
+
|
108
|
+
Now we can jump around these warp points, as well as run 'ls' inside (even passing arbitrary arguments to the `ls` itself):
|
109
|
+
|
110
|
+
[source,bash]
|
111
|
+
----
|
112
|
+
/usr/local/Cellar ❯ wd cbsrc
|
113
|
+
~/workspace/arduino/robots/command-bridge/src ❯ wd foosrc
|
114
|
+
~/workspace/c++/foo/src ❯ 1 wd ls brew -- -alF | head -4 # run ls -alF inside /usr/local/Cellar
|
115
|
+
total 0
|
116
|
+
drwxrwx--- 73 kig staff 2482 May 7 15:29 ./
|
117
|
+
drwxrwx--- 21 kig staff 714 Apr 28 11:40 ../
|
118
|
+
drwxrwx--- 3 kig staff 102 Dec 24 03:14 ack/
|
119
|
+
----
|
120
|
+
|
121
|
+
==== Command Completion in BASH
|
122
|
+
|
123
|
+
If you installed `wd` properly, it should register it's own command completion for BASH and be ready for your tabs :)
|
124
|
+
|
125
|
+
Note that you can use `wd` to change directory by giving an absolute or relative directory name, just like `cd` (so not just using warp-points), so when you type `wd <TAB><TAB>` you should see the list of _all saved warp points as well as all of the local sub-directories relative to where you are at_.
|
126
|
+
|
127
|
+
[source,bash]
|
128
|
+
----
|
129
|
+
# And, it supports command completion in BASH!
|
130
|
+
$ wd<TAB><TAB>
|
131
|
+
# should print the list of registered warp points, and commands.
|
132
|
+
|
133
|
+
$ wd install --dotfile /Users/kig/.bash<TAB><TAB>
|
134
|
+
/Users/kig/.bash_login /Users/kig/.bash_profile /Users/kig/.bashrc
|
135
|
+
----
|
136
|
+
|
137
|
+
Command completion is activated by loading the `~/.bash_wd` file that's installed with `warp-dir install` command.
|
138
|
+
|
139
|
+
==== Config File (aka. Warp Points Database)
|
140
|
+
|
141
|
+
All of the mappings are stored in the `~/.warprc` file, where the warp point name is followed by a colon, and the path it maps to. So it's trivial to do a global search/replace on that file in your favorite editor, if, for example, a commond top level folder had changed.
|
142
|
+
|
143
|
+
The format of the file was left identical to that of the `ZSH` version of `wd` so that one could switch back and force between the two versions of `wd` and still be able to use their collection of warp points.
|
144
|
+
|
145
|
+
See? I think we thought of everything :)
|
146
|
+
|
147
|
+
Happy warping!
|
148
|
+
|
149
|
+
== `wd` Concept
|
150
|
+
|
151
|
+
The overall concept comes from the realization that when we work on the command line, we often do things that `wd` tool provides straight out of the box, such as:
|
152
|
+
|
153
|
+
* we often have to deal with a limited number of folders at any given time
|
154
|
+
* on occastion have to jump between these folders (which we call *warp points*), which may require mult-level `cd` command, for example: `+cd ~/workspace/foo/src/include/; ....; cd ~/Documents/Microsoft\ Word/; ...+`
|
155
|
+
* seems like it should be easy to add, remove and list warp points
|
156
|
+
* everything should require typing few characters as possible :)
|
157
|
+
* it would be great to have full BASH completion support
|
158
|
+
|
159
|
+
Some future extensions could be based on some additional realizations:
|
160
|
+
|
161
|
+
* perhaps you might want to inspect a bookmarked folder without leaving your current place.
|
162
|
+
* maybe by inspecting we mean -- running a `find`, or `ls` or any other command for that matter
|
163
|
+
|
164
|
+
=== Notable Differences with original `wd`
|
165
|
+
|
166
|
+
* instead of `wd add!` use `wd add -f <point>` (or --force)
|
167
|
+
|
168
|
+
These features will be added shortly:
|
169
|
+
|
170
|
+
* for now `wd clean` is not supported
|
171
|
+
* for now history is not supported
|
172
|
+
* for now '-' is not supported
|
173
|
+
|
174
|
+
=== Future Feature Brainstorm
|
175
|
+
|
176
|
+
==== Simplify The CLI
|
177
|
+
|
178
|
+
Questionable value, but this sort of interface appear a bit more consistent.
|
179
|
+
|
180
|
+
Still I am not sure I want to type `wd -j proj` or `wd -a proj` instead of `wd proj` and `wd add proj`...
|
181
|
+
|
182
|
+
[,bash]
|
183
|
+
----
|
184
|
+
wd -j/--jump point
|
185
|
+
wd -a/--add point
|
186
|
+
wd -r/--remove point
|
187
|
+
wd -l/--ls point
|
188
|
+
wd -p/--path point
|
189
|
+
|
190
|
+
wd -L/--list
|
191
|
+
wd -C/--clean
|
192
|
+
wd -S/--scan # report whether points exist on the file system
|
193
|
+
----
|
194
|
+
|
195
|
+
== Run Commands In A Warp Point
|
196
|
+
|
197
|
+
Pass an arbitrary command to execute, and return back to CWD.
|
198
|
+
|
199
|
+
[,bash]
|
200
|
+
----
|
201
|
+
wd proj -x/--exec -- "command"
|
202
|
+
----
|
203
|
+
|
204
|
+
|
205
|
+
=== Networking
|
206
|
+
|
207
|
+
Can we go across SSH?
|
208
|
+
|
209
|
+
[,bash]
|
210
|
+
----
|
211
|
+
wd add proj kig@remote.server.com:~/workspace/proj
|
212
|
+
wd ls proj
|
213
|
+
wd proj
|
214
|
+
----
|
215
|
+
|
216
|
+
This then establishes and SSH connection to the server and logs you into the shell. Should be pretty easy, I think :)
|
217
|
+
|
218
|
+
== Development
|
219
|
+
|
220
|
+
Fork the repo to your github username, and create a feature branch. Run `bundle install`.
|
221
|
+
|
222
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
223
|
+
|
224
|
+
To submit your change, create a new pull request, and ensure to provide tests for any new code.
|
225
|
+
|
226
|
+
== Adding New Commands
|
227
|
+
|
228
|
+
Just follow the pattern in the `lib/warp/dir/commands/` folder, copy and modify
|
229
|
+
one of the existing commands. Command class name is used as an actual command.
|
230
|
+
|
231
|
+
Add a working rspec.
|
232
|
+
|
233
|
+
== Contributing
|
234
|
+
|
235
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kigster/warp-dir.
|
236
|
+
|
237
|
+
== Author
|
238
|
+
|
239
|
+
© 2016-2022 Konstantin Gredeskoul, All rights reserved.
|
240
|
+
|
241
|
+
== License
|
242
|
+
|
243
|
+
This project is distributed under the https://raw.githubusercontent.com/kigster/warp-dir/master/LICENSE[MIT License].
|
244
|
+
|
data/Rakefile
CHANGED
@@ -1,71 +1,29 @@
|
|
1
|
-
|
2
|
-
[ %q(chmod -R o+r .),
|
3
|
-
%q(rm -f *.gem),
|
4
|
-
%q(rm -rf build),
|
5
|
-
%q(gem uninstall -quiet -a --executables warp-dir 2> /dev/null; true),
|
6
|
-
%q(gem build warp-dir.gemspec)
|
7
|
-
].each do |command|
|
8
|
-
sh command
|
9
|
-
end
|
1
|
+
# frozen_string_literal: true
|
10
2
|
|
11
|
-
|
12
|
-
|
13
|
-
export gem_name=${gem_file//.gem/}
|
14
|
-
if [ "$(which ruby)" == "/usr/bin/ruby" ]; then
|
15
|
-
gem install $gem_file -n /usr/local/bin --no-ri --no-rdoc
|
16
|
-
else
|
17
|
-
gem install $gem_file --no-ri --no-rdoc
|
18
|
-
fi
|
19
|
-
EOF
|
20
|
-
end
|
21
|
-
|
22
|
-
namespace :development do
|
23
|
-
desc 'Setup temporary Gemfile, install all dependencies, and remove Gemfile'
|
24
|
-
task :install => [:setup, :cleanup]
|
25
|
-
|
26
|
-
desc 'Setup temporary Gemfile and install all dependencies.'
|
27
|
-
task :setup do
|
28
|
-
sh %q{
|
29
|
-
echo "source 'https://rubygems.org'; gemspec" > Gemfile
|
30
|
-
[[ -n $(which bundle) ]] || gem install bundler --no-ri --no-rdoc --quiet
|
31
|
-
bundle install --quiet
|
32
|
-
}.gsub(%r{^\s+}m, '')
|
33
|
-
end
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
34
5
|
|
35
|
-
|
36
|
-
sh %q{ rm -f Gemfile }
|
37
|
-
end
|
6
|
+
require 'yard'
|
38
7
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
desc "Invoke Bundler's 'release' task to push the gem to RubyGems.org"
|
45
|
-
task :release => [ :setup, :load ] do
|
46
|
-
Rake::Task['release'].invoke
|
47
|
-
Rake::Task['development:cleanup'].invoke
|
48
|
-
end
|
8
|
+
def shell(*args)
|
9
|
+
puts "running: #{args.join(' ')}"
|
10
|
+
system(args.join(' '))
|
11
|
+
end
|
49
12
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
13
|
+
task :permissions do
|
14
|
+
shell('rm -rf pkg/ doc/')
|
15
|
+
shell("chmod -v o+r,g+r * */* */*/* */*/*/* */*/*/*/* */*/*/*/*/*")
|
16
|
+
shell("find . -type d -exec chmod o+x,g+x {} \\;")
|
56
17
|
end
|
57
18
|
|
58
|
-
|
59
|
-
CLEAN.include %w(pkg coverage *.gem)
|
19
|
+
task build: :permissions
|
60
20
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
21
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
22
|
+
t.files = %w(lib/**/*.rb exe/* - README.md LICENSE)
|
23
|
+
t.options.unshift('--title', '"warp-dir", or "wd" (which stands for warp directory) is a Ruby implementation of the ZSH module by the same name, which is compatible with this gem. The `wd` command lets you "bookmark" and then "jump" to custom directories in BASH, without using cd. Why? Because cd seems inefficient when the folder is frequently visited or has a long path.')
|
24
|
+
t.after = -> { exec('open doc/index.html') } if RUBY_PLATFORM =~ /darwin/
|
65
25
|
end
|
66
26
|
|
67
|
-
|
68
|
-
Rake::Task['development:cleanup'].invoke
|
69
|
-
end
|
27
|
+
RSpec::Core::RakeTask.new(:spec)
|
70
28
|
|
71
|
-
task :
|
29
|
+
task default: :spec
|
data/bin/console
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# vim: ft=ruby
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'colored2'
|
5
|
+
require 'warp/dir'
|
5
6
|
|
6
7
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
7
|
-
# require
|
8
|
+
# require 'pry'
|
8
9
|
# Pry.start
|
9
10
|
|
10
|
-
require
|
11
|
+
require 'irb'
|
11
12
|
IRB.start
|
data/bin/warp-dir.bash
CHANGED
@@ -1,70 +1,236 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
|
+
# vim: ft=bash
|
2
3
|
#
|
3
|
-
#
|
4
|
+
# WarpDir (v1.7.0) shell wrapper, installed by a gem 'warp-dir'
|
4
5
|
#
|
5
|
-
# ©
|
6
|
-
# https://github.com/kigster/warp-dir
|
6
|
+
# © 2012-2011, Konstantin Gredeskoul
|
7
7
|
#
|
8
|
+
# https://github.com/kigster/warp-dir
|
8
9
|
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# shellcheck disable=SC2207,SC2206,SC2059
|
11
|
+
|
12
|
+
declare -a wd_commands
|
13
|
+
declare -a wd_short_flags
|
14
|
+
declare -a wd_long_flags
|
15
|
+
declare -a wd_default_dotfiles
|
16
|
+
|
17
|
+
declare wd_temp
|
18
|
+
|
19
|
+
export wd_commands=(add ls remove warp install help list)
|
20
|
+
export wd_default_dotfiles=(~/.bash_profile ~/.bashrc ~/.bash_login ~/.profile ~/.zshrc)
|
21
|
+
|
22
|
+
function _wd::init() {
|
23
|
+
# shellcheck disable=SC2155
|
24
|
+
export wd_temp="$(mktemp)"
|
25
|
+
rm -f "${wd_temp}" && touch "${wd_temp}"
|
26
|
+
|
27
|
+
[[ ${#wd_long_flags[@]} -gt 0 ]] && return
|
28
|
+
command -v warp-dir >/dev/null && {
|
29
|
+
export wd_long_flags=($(warp-dir --help | awk 'BEGIN{FS="--"}{print "--" $2}' | sed -E '/^--$/d' | grep -E -v ']|help' | grep -E -- "${cur}" | awk '{if ($1 != "") { printf "%s\n", $1} } '))
|
30
|
+
export wd_short_flags=($(warp-dir --help | grep -E -- '-[a-z], --' | cut -d '-' -f 2 | tr -d ',' | sed 's/^/-/g'))
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
function _wd::debug() {
|
35
|
+
printf "%-20s: %s\n" "long0 flags" "$(echo "${wd_long_flags[*]}" | tr '\n' ' ')"
|
36
|
+
printf "%-20s: %s\n" "short flags" "$(echo "${wd_short_flags[*]}" | tr '\n' ' ')"
|
37
|
+
printf "%-20s: %s\n" "commands" "$(echo "${wd_commands[*]}" | tr '\n' ' ')"
|
38
|
+
printf "%-20s: %s\n" "points" "$(_wd::current-points | tr '\n' ' ')"
|
39
|
+
}
|
40
|
+
|
41
|
+
function _wd::current-points() {
|
42
|
+
warp-dir list --no-color | awk '{ print $1 }'
|
43
|
+
}
|
44
|
+
|
45
|
+
function _wd::err() {
|
46
|
+
printf "\n\e[7;31m ERROR ❯❯ \e[0;31m $*\e[0;0m\n" >&2
|
47
|
+
}
|
48
|
+
|
49
|
+
function _wd::info() {
|
50
|
+
printf "\n\e[7;34m INFO ❯❯ \e[0;35m $*\e[0;0m\n" >&2
|
51
|
+
}
|
52
|
+
|
53
|
+
function _wd::exec() {
|
54
|
+
export WARP_DIR_SHELL=yes
|
55
|
+
export RUBYOPT=W0
|
56
|
+
if type rbenv | grep -q function; then
|
57
|
+
rbenv exec warp-dir "$@" 2>/dev/null
|
58
|
+
else
|
59
|
+
warp-dir "$@" 2>/dev/null
|
60
|
+
fi
|
61
|
+
}
|
62
|
+
|
63
|
+
function _wd::not-found() {
|
64
|
+
_wd::err "Can't find 'warp-dir' executable!"
|
65
|
+
|
66
|
+
printf "
|
67
|
+
Is the gem properly installed?
|
68
|
+
|
69
|
+
Perhaps try reinstalling the gem as shown: \e[0;34m
|
70
|
+
|
71
|
+
gem install warp-dir --no-wrapper
|
72
|
+
warp-dir install --dotfile ~/.bash_profile
|
73
|
+
hash -r
|
74
|
+
wd -h\e[0;0m
|
75
|
+
"
|
76
|
+
}
|
77
|
+
|
78
|
+
function _wd::gem-install() {
|
79
|
+
local code
|
80
|
+
|
81
|
+
_wd::info "Ruby $(ruby --version) does not have warp-dir gem. Installing the missing gem..."
|
82
|
+
gem install -N --quiet --force --no-wrapper warp-dir >"${wd_temp}" 2>&1
|
83
|
+
code=$?
|
84
|
+
|
85
|
+
hash -r 2>/dev/null
|
86
|
+
|
87
|
+
if [[ ${code} -eq 0 ]]; then
|
88
|
+
_wd::info "Installation was successful, warp-dir executable is now at:"
|
89
|
+
_wd::info "\e[1;32m$(which warp-dir)"
|
90
|
+
_wd::init
|
91
|
+
else
|
92
|
+
_wd::err "Install failed, exit code=${code}\n"
|
93
|
+
[[ -s "${wd_temp}" ]] && {
|
94
|
+
printf "\e[1;31m"
|
95
|
+
cat "${wd_temp}"
|
96
|
+
printf "\e[0;0m"
|
97
|
+
}
|
98
|
+
return 1
|
13
99
|
fi
|
14
100
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
101
|
+
}
|
102
|
+
|
103
|
+
function wd() {
|
104
|
+
if [[ "$1" == "--comp-debug" ]]; then
|
105
|
+
_wd::debug
|
106
|
+
return
|
107
|
+
fi
|
108
|
+
|
109
|
+
_wd::init
|
110
|
+
|
111
|
+
command -v warp-dir >/dev/null || {
|
112
|
+
hash -r 2>/dev/null
|
113
|
+
if [[ -z $(which warp-dir) ]]; then
|
114
|
+
_wd::gem-install || return 1
|
115
|
+
fi
|
116
|
+
}
|
117
|
+
|
118
|
+
command -v warp-dir >/dev/null || {
|
119
|
+
_wd::err "Can't find warp-dir executable in the PATH" && return 1
|
120
|
+
}
|
121
|
+
|
122
|
+
local previous_ifs=$IFS
|
123
|
+
IFS="+"
|
124
|
+
|
125
|
+
local output
|
126
|
+
set +e
|
127
|
+
output="$(_wd::exec "$@")"
|
128
|
+
local code=$?
|
129
|
+
((DEBUG)) && printf "DEBUG OUTPUT: [%s]" "${output}"
|
130
|
+
|
131
|
+
if [[ $code -eq 127 ]]; then
|
132
|
+
[[ -n $(command -v rbenv) ]] && {
|
133
|
+
_wd::gem-install || {
|
134
|
+
export IFS="${previous_ifs}"
|
135
|
+
return 1
|
136
|
+
}
|
137
|
+
rbenv rehash >/dev/null 2>&1
|
138
|
+
}
|
139
|
+
output="$(_wd::exec "$@")"
|
19
140
|
code=$?
|
20
|
-
if [ $code -eq 127 ]; then
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
eval ${output}
|
25
|
-
IFS=$IFS_BACKUP
|
141
|
+
if [[ $code -eq 127 ]]; then
|
142
|
+
_wd::not-found
|
143
|
+
export IFS="${previous_ifs}"
|
144
|
+
return 1
|
26
145
|
fi
|
146
|
+
fi
|
147
|
+
|
148
|
+
if [[ "${output}" =~ (cd |printf ) ]]; then
|
149
|
+
eval "${output}"
|
150
|
+
code=$?
|
27
151
|
else
|
28
|
-
|
152
|
+
printf "%s\n" "${output}"
|
153
|
+
code=0
|
29
154
|
fi
|
155
|
+
export IFS="${previous_ifs}"
|
156
|
+
return "${code}"
|
30
157
|
}
|
31
158
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
159
|
+
# @description Command Completion
|
160
|
+
#
|
161
|
+
# COMP_WORDS: an array of all the words typed after the name of the program
|
162
|
+
# the compspec belongs to
|
163
|
+
#
|
164
|
+
# COMP_CWORD: an index of the COMP_WORDS array pointing to the word the current
|
165
|
+
# cursor is at—in other words, the index of the word the cursor was
|
166
|
+
# when the tab key was pressed
|
167
|
+
#
|
168
|
+
# COMP_LINE: the current command line
|
169
|
+
#
|
170
|
+
# suggestions: The contents of the suggestions variable are
|
171
|
+
# always displayed. The function is now
|
172
|
+
# responsible for adding or removing entries from
|
173
|
+
# there. If the suggestions variable had only one
|
174
|
+
# element, then that word would be automatically
|
175
|
+
# completed in the command.
|
176
|
+
#
|
177
|
+
# Enter compgen: builtin command that generates completions
|
178
|
+
# supporting most of the options of the complete command
|
179
|
+
# generator (ex. -W for word list, -d for directories) and
|
180
|
+
# filtering them based on what the user has already typed.
|
181
|
+
function _wd_completions() {
|
182
|
+
_wd::init
|
40
183
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
184
|
+
if [[ "${#COMP_WORDS[@]}" -lt 2 ]]; then
|
185
|
+
return
|
186
|
+
fi
|
187
|
+
|
188
|
+
local -a wd_points=($(_wd::current-points))
|
189
|
+
local -a suggestions=()
|
190
|
+
|
191
|
+
local cur="${COMP_WORDS[${COMP_CWORD}]}"
|
192
|
+
local prev="${COMP_WORDS[$((COMP_CWORD - 1))]}"
|
193
|
+
|
194
|
+
if [[ ${cur} == --* ]]; then
|
195
|
+
suggestions+=(${wd_long_flags[@]})
|
196
|
+
elif [[ ${cur} == -* ]]; then
|
197
|
+
suggestions+=(${wd_short_flags[@]})
|
198
|
+
elif [[ ${COMP_CWORD} -gt 1 ]]; then
|
199
|
+
suggestions+=(${wd_short_flags[@]})
|
200
|
+
suggestions+=(${wd_long_flags[@]})
|
201
|
+
else
|
202
|
+
suggestions+=(${wd_points[@]})
|
203
|
+
suggestions+=(${wd_commands[@]})
|
204
|
+
fi
|
205
|
+
|
206
|
+
suggestions=($(compgen -W "${suggestions[*]}" -- "${cur}"))
|
207
|
+
|
208
|
+
if [[ "${prev}" == wd ]]; then
|
209
|
+
suggestions+=($(compgen -d -- "${cur}"))
|
210
|
+
|
211
|
+
elif [[ "${prev}" == "--dotfile" ]]; then
|
212
|
+
local -a inits
|
213
|
+
|
214
|
+
for file in "${wd_default_dotfiles[@]}"; do
|
215
|
+
[[ -s "${file}" ]] && inits+=("${file}")
|
216
|
+
done
|
217
|
+
|
218
|
+
case "${cur}" in
|
219
|
+
[a-z]*)
|
220
|
+
cur="${HOME}/.${cur}"
|
221
|
+
;;
|
222
|
+
.[a-z]*)
|
223
|
+
cur="${HOME}/${cur}"
|
224
|
+
;;
|
225
|
+
esac
|
226
|
+
suggestions=($(compgen -W "${inits[*]}" -- "${cur}"))
|
227
|
+
fi
|
228
|
+
|
229
|
+
if [[ "${#suggestions[@]}" -eq 1 ]]; then
|
230
|
+
COMPREPLY=("${suggestions[0]}")
|
231
|
+
else
|
232
|
+
COMPREPLY=(${suggestions[@]})
|
233
|
+
fi
|
68
234
|
}
|
69
235
|
|
70
|
-
complete -F
|
236
|
+
complete -F _wd_completions wd
|
data/exe/warp-dir
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# vim: ft=ruby
|
2
3
|
|
3
|
-
lib_path = File.dirname(__FILE__)
|
4
|
+
lib_path = "#{File.dirname(__FILE__)}/../lib"
|
4
5
|
if File.exist?(lib_path)
|
5
6
|
$LOAD_PATH << lib_path
|
6
7
|
end
|
@@ -9,4 +10,4 @@ require 'warp/dir'
|
|
9
10
|
require 'warp/dir/app/cli'
|
10
11
|
|
11
12
|
response = Warp::Dir::App::CLI.new(ARGV.dup).run
|
12
|
-
response.print
|
13
|
+
response.print if response
|