2012-08-11 17:22:29 -07:00
|
|
|
class Pry
|
2012-12-25 23:35:17 +02:00
|
|
|
class Command::ShellCommand < Pry::ClassCommand
|
2013-03-02 16:01:55 -08:00
|
|
|
match(/\.(.*)/)
|
2012-08-11 18:26:59 -07:00
|
|
|
group 'Input and Output'
|
|
|
|
description "All text following a '.' is forwarded to the shell."
|
2012-12-25 23:35:17 +02:00
|
|
|
command_options :listing => '.<shell command>', :use_prefix => false,
|
2012-08-11 18:26:59 -07:00
|
|
|
:takes_block => true
|
2012-08-11 17:22:29 -07:00
|
|
|
|
2013-01-09 22:23:19 +02:00
|
|
|
banner <<-'BANNER'
|
|
|
|
Usage: .COMMAND_NAME
|
|
|
|
|
|
|
|
All text following a "." is forwarded to the shell.
|
|
|
|
|
|
|
|
.ls -aF
|
|
|
|
.uname
|
|
|
|
BANNER
|
|
|
|
|
2012-08-11 18:26:59 -07:00
|
|
|
def process(cmd)
|
2013-12-08 21:48:52 -05:00
|
|
|
if cmd =~ /^cd\s*(.*)/i
|
2013-12-07 19:05:48 -05:00
|
|
|
process_cd parse_destination($1)
|
2012-08-11 17:22:29 -07:00
|
|
|
else
|
2012-08-11 18:26:59 -07:00
|
|
|
pass_block(cmd)
|
|
|
|
if command_block
|
|
|
|
command_block.call `#{cmd}`
|
|
|
|
else
|
2014-02-07 01:52:12 +01:00
|
|
|
_pry_.config.system.call(output, cmd, _pry_)
|
2012-08-11 18:26:59 -07:00
|
|
|
end
|
2012-08-11 17:22:29 -07:00
|
|
|
end
|
|
|
|
end
|
2012-08-21 00:44:26 -07:00
|
|
|
|
2013-12-07 19:05:48 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def parse_destination(dest)
|
2013-12-08 21:48:52 -05:00
|
|
|
return "~" if dest.empty?
|
2013-12-07 19:05:48 -05:00
|
|
|
return dest unless dest == "-"
|
|
|
|
state.old_pwd || raise(CommandError, "No prior directory available")
|
|
|
|
end
|
|
|
|
|
|
|
|
def process_cd(dest)
|
|
|
|
state.old_pwd = Dir.pwd
|
|
|
|
Dir.chdir File.expand_path(dest)
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
raise CommandError, "No such directory: #{dest}"
|
|
|
|
end
|
2012-08-11 17:22:29 -07:00
|
|
|
end
|
2012-12-25 23:35:17 +02:00
|
|
|
|
|
|
|
Pry::Commands.add_command(Pry::Command::ShellCommand)
|
2012-08-11 17:22:29 -07:00
|
|
|
end
|