Permalink
Browse files

• Add `Rush::quote`, a method to quote a path.

  The quoted path can safely be used inside shellout (like backticks).
  Quotation function adapted from TextMate’s `e_sh` function (lib/escape.rb).
• Add `Rush::Entry.quoted_path`, which returns an entry’s quoted `full_path`.
  • Loading branch information...
1 parent 88657bb commit 130084d61657fe64b10fe9b22464a80c2b61f417 @mkhl mkhl committed with adamwiggins Jan 25, 2009
Showing with 9 additions and 0 deletions.
  1. +5 −0 lib/rush.rb
  2. +4 −0 lib/rush/entry.rb
View
@@ -54,6 +54,11 @@ def self.my_process
def self.box
@@box = Rush::Box.new
end
+
+ # Quote a path for use in backticks, say.
+ def self.quote(path)
+ path.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''")
+ end
end
module Rush::Connection; end
View
@@ -50,6 +50,10 @@ def full_path
"#{@path}/#{@name}"
end
+ def quoted_path
+ Rush.quote(full_path)
+ end
+
# Return true if the entry currently exists on the filesystem of the box.
def exists?
stat

0 comments on commit 130084d

Please sign in to comment.