warp-dir 1.6.2 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
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
+ &copy; 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,68 +1,29 @@
1
- task :reinstall => [ :'development:cleanup' ] do
2
- [ %q(chmod -R o+r .),
3
- %q(rm -f *.gem),
4
- %q(gem uninstall -quiet -a --executables warp-dir 2> /dev/null; true),
5
- %q(gem build warp-dir.gemspec)
6
- ].each do |command|
7
- sh command
8
- end
1
+ # frozen_string_literal: true
9
2
 
10
- sh <<-EOF.gsub(%r{^\s+}m, '')
11
- export gem_file=$(ls -1 *.gem | tail -1)
12
- export gem_name=${gem_file//.gem/}
13
- if [ "$(which ruby)" == "/usr/bin/ruby" ]; then
14
- gem install $gem_file -n /usr/local/bin
15
- else
16
- gem install $gem_file
17
- fi
18
- EOF
19
- end
20
-
21
- namespace :development do
22
- desc 'Setup temporary Gemfile, install all dependencies, and remove Gemfile'
23
- task :install => [:setup, :cleanup]
24
-
25
- desc 'Setup temporary Gemfile and install all dependencies.'
26
- task :setup do
27
- sh %q{
28
- bundle install
29
- }.gsub(%r{^\s+}m, '')
30
- end
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
31
5
 
32
- task :cleanup do
33
- sh %q{ rm -f build }
34
- end
6
+ require 'yard'
35
7
 
36
- namespace :bundler do
37
- task :load do
38
- require 'bundler'
39
- require 'bundler/gem_tasks'
40
- end
41
- desc "Invoke Bundler's 'release' task to push the gem to RubyGems.org"
42
- task :release => [ :setup, :load ] do
43
- Rake::Task['release'].invoke
44
- Rake::Task['development:cleanup'].invoke
45
- end
8
+ def shell(*args)
9
+ puts "running: #{args.join(' ')}"
10
+ system(args.join(' '))
11
+ end
46
12
 
47
- desc 'Package and install the gem locally'
48
- task :install => [ :setup, :load ] do
49
- Rake::Task['install:local'].invoke
50
- Rake::Task['development:cleanup'].invoke
51
- end
52
- 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 {} \\;")
53
17
  end
54
18
 
55
- require 'rake/clean'
56
- CLEAN.include %w(pkg coverage *.gem)
19
+ task build: :permissions
57
20
 
58
- begin
59
- require 'rspec/core/rake_task'
60
- RSpec::Core::RakeTask.new(:spec)
61
- rescue LoadError
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/
62
25
  end
63
26
 
64
- task :spec => [ 'development:setup' ] do
65
- Rake::Task['development:cleanup'].invoke
66
- end
27
+ RSpec::Core::RakeTask.new(:spec)
67
28
 
68
- task :default => [:spec]
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 "colored"
4
- require "warp/dir"
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 "pry"
8
+ # require 'pry'
8
9
  # Pry.start
9
10
 
10
- require "irb"
11
+ require 'irb'
11
12
  IRB.start
data/bin/warp-dir.bash CHANGED
@@ -1,80 +1,236 @@
1
1
  #!/usr/bin/env bash
2
+ # vim: ft=bash
2
3
  #
3
- # %WARP-DIR% shell wrapper, installed by a gem 'warp-dir'
4
+ # WarpDir (v1.7.0) shell wrapper, installed by a gem 'warp-dir'
4
5
  #
5
- # © 2015-2016, Konstantin Gredeskoul
6
- # https://github.com/kigster/warp-dir
6
+ # © 2012-2011, Konstantin Gredeskoul
7
7
  #
8
+ # https://github.com/kigster/warp-dir
8
9
  #
9
- wd() {
10
- if [[ -z "${warp_dir_exec_installed}" || "${warp_dir_exec_installed}" -eq 1 ]]; then
11
- $(which 'warp-dir') 2>&1 1>/dev/null
12
- export warp_dir_exec_installed=$?
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
13
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
+ }
14
77
 
15
- if [[ ${warp_dir_exec_installed} -ne 0 ]]; then
16
- wd_not_found
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
+ }
17
98
  return 1
18
99
  fi
19
100
 
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
+
20
122
  local previous_ifs=$IFS
21
123
  IFS="+"
22
124
 
23
- local output=$(WARP_DIR_SHELL=yes RUBYOPT="-W0" warp-dir $@ 2>&1)
125
+ local output
126
+ set +e
127
+ output="$(_wd::exec "$@")"
24
128
  local code=$?
129
+ ((DEBUG)) && printf "DEBUG OUTPUT: [%s]" "${output}"
25
130
 
26
131
  if [[ $code -eq 127 ]]; then
27
- [[ -n $(command -v rbenv) ]] && rbenv rehash >/dev/null 2>&1
28
- output=$(WARP_DIR_SHELL=yes RUBYOPT="-W0" warp-dir $@ 2>&1)
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 "$@")"
29
140
  code=$?
30
- if [ $code -eq 127 ]; then
31
- unset warp_dir_exec_installed
32
- wd_not_found
33
- IFS=$previous_ifs
141
+ if [[ $code -eq 127 ]]; then
142
+ _wd::not-found
143
+ export IFS="${previous_ifs}"
34
144
  return 1
35
145
  fi
36
146
  fi
37
147
 
38
- eval "${output}"
39
- export IFS=$previous_ifs
148
+ if [[ "${output}" =~ (cd |printf ) ]]; then
149
+ eval "${output}"
150
+ code=$?
151
+ else
152
+ printf "%s\n" "${output}"
153
+ code=0
154
+ fi
155
+ export IFS="${previous_ifs}"
156
+ return "${code}"
40
157
  }
41
158
 
42
- wd_not_found() {
43
- printf "\nWhoops – I can't find 'warp-dir' executable.\n"
44
- printf "Is the gem properly installed?\n"
45
- printf "\nTry reinstalling the gem with, for example:\n\n"
46
- printf " $ gem install warp-dir --no-wrappers\n"
47
- printf " $ hash -r\n"
48
- printf " $ warp-dir install [ --dotfile ~/.bashrc ]\n"
49
- }
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
50
183
 
51
- _wd() {
52
- local WD_OPTS WD_POINTS cur prev
53
-
54
- cur="${COMP_WORDS[COMP_CWORD]}"
55
- prev="${COMP_WORDS[COMP_CWORD-1]}"
56
-
57
- COMPREPLY=()
58
-
59
- # Only perform completion if the current word starts with a dash ('-'),
60
- # meaning that the user is trying to complete an option.
61
- if [[ ${cur} == -* ]] ; then
62
- # COMPREPLY is the array of possible completions, generated with
63
- WD_COMP_OPTIONS=$(wd --help | awk 'BEGIN{FS="--"}{print "--" $2}' | sed -E '/^--$/d' | egrep -v ']|help' | egrep -- "${cur}" | awk '{if ($1 != "") { printf "%s\n", $1} } ')
64
- else
65
- WD_COMMANDS="add ls remove warp install help list"
66
- if [[ -z "${cur}" ]] ; then
67
- WD_POINTS=$(wd list --no-color | awk '{ print $1 }')
68
- WD_DIRS=$(ls -1p | grep '/')
69
- else
70
- WD_POINTS=$(wd list --no-color | awk '{ print $1 }' | egrep -e "^${cur}")
71
- WD_DIRS=$(ls -1p | grep '/' | egrep -e "^${cur}")
72
- fi
73
- WD_COMP_OPTIONS="$WD_POINTS $WD_DIRS"
74
- fi
75
- [[ $COMP_CWORD == 1 ]] && WD_COMP_OPTIONS="${WD_COMP_OPTIONS} ${WD_COMMANDS}"
76
- COMPREPLY=( $(compgen -W "${WD_COMP_OPTIONS}" -- ${cur}) )
77
- return 0
78
- }
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
234
+ }
79
235
 
80
- complete -F _wd wd
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__) + '/../lib'
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.exit! if response
13
+ response.print if response