Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to exit nonzero for unknown bookmarks #3

Merged
merged 2 commits into from
Feb 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bash_integration/shell_driver
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

function jump {
local dest
#echo "jump called with $*"
if [ $# -lt 1 ]; then
jump-bin --help
elif [ ${1:0:1} == "-" ]; then
jump-bin $*
else
cd "$(jump-bin $*)"
dest="$(jump-bin $*)" && cd "$dest"
fi
}

# vim: ft=sh et sw=2 ts=2 sts=2
39 changes: 25 additions & 14 deletions bin/jump-bin
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require 'optparse'

options = {}
begin
OptionParser.new do |opts|
opts = OptionParser.new do |opts|
opts.banner = "Usage: jump [options] [BOOKMARK[/path/to/subfolder]]"

opts.on("-a", "--add BOOKMARK", "Saves the current directory in BOOKMARK") do |v|
Expand Down Expand Up @@ -57,7 +57,8 @@ begin
puts opts
exit
end
end.parse!
end
opts.parse!
rescue OptionParser::InvalidOption
if $!.args.first == "--bc"
# This is an hidden method used by bash_completion
Expand All @@ -72,6 +73,8 @@ end

bookmarks = Bookmarks.new

### handle options, if present

if options.has_key?(:add)
bookmarks.add(Dir.pwd, options[:add])
bookmarks.save
Expand All @@ -87,16 +90,24 @@ if options.has_key?(:del)
end
end

puts bookmarks if options.has_key?(:list)
if ARGV.size == 1
expanded_path = bookmarks.expand_path(ARGV[0])
if expanded_path.nil?
STDERR.puts "Unknown bookmark: '#{ARGV[0]}'."
puts Dir.pwd
else
puts expanded_path
end
elsif ARGV.size > 1
STDERR.puts "Wrong arguments."
puts Dir.pwd
if options.has_key?(:list)
puts bookmarks
end

exit if ARGV.empty?

### remaining argument(s) must be a single bookmark

if ARGV.size > 1
STDERR.puts opts
exit 1
end

expanded_path = bookmarks.expand_path(ARGV[0])
if expanded_path.nil?
STDERR.puts "Unknown bookmark: '#{ARGV[0]}'."
exit 42
else
puts expanded_path
end

9 changes: 6 additions & 3 deletions zsh_integration/jump
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _jump()
{
local user_input
read -cA user_input
local cur prev
local cur prev
reply=()

cur="${user_input[$#user_input]}"
Expand All @@ -41,19 +41,22 @@ _jump()
else
reply=( $(jump-bin --bc ${cur}) )
return 0
fi
fi
}

function jump {
local args dest
args=$*
#echo "jump called with |$args|"
if [[ $#args -lt 1 ]]; then
jump-bin --help
elif [[ ${args[0,1]} = "-" ]]; then
jump-bin $*
else
cd "$(jump-bin $*)"
dest="$(jump-bin $*)" && cd "$dest"
fi
}

compctl -K _jump -S '' jump

# vim: ft=zsh et sw=2 ts=2 sts=2