about summary refs log tree commit diff stats
path: root/code
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-07-20 02:47:08 +0200
committerhut <hut@lavabit.com>2009-07-20 02:47:08 +0200
commit080e74951f679c9376b67199df1bebb498398e5c (patch)
tree5b1c98435001d309b9818f235c8c01ab09897074 /code
parent7ab72bac38a8f32fa20e4d08b9b2754de5295840 (diff)
downloadranger-080e74951f679c9376b67199df1bebb498398e5c.tar.gz
added Array#sh, cleaned up code/extensions/basic.rb
Diffstat (limited to 'code')
-rw-r--r--code/extensions/basic.rb24
1 files changed, 10 insertions, 14 deletions
diff --git a/code/extensions/basic.rb b/code/extensions/basic.rb
index c07402d7..0dbd8a96 100644
--- a/code/extensions/basic.rb
+++ b/code/extensions/basic.rb
@@ -20,6 +20,15 @@ class Array
 		self[n .. -1]
 	end
 	alias car first
+	def sh
+		map do |x|
+			if x.respond_to? :path
+				x.path.to_s
+			else
+				x.to_s
+			end.sh
+		end.join(" ")
+	end
 end
 
 class String
@@ -65,20 +74,6 @@ class String
 		Directory::Entry::MIMETYPES[self] || 'unknown'
 	end
 
-	def sh
-		res = self.dup
-		res.gsub!('\\\\', "\000")
-		res.gsub!(' ', '\\ ')
-		res.gsub!('(', '\\(')
-		res.gsub!('&', '\\\&')
-		res.gsub!(')', '\\)')
-		res.gsub!('*', '\\*')
-		res.gsub!('\'', "\\\\'")
-		res.gsub!('"', '\\"')
-		res.gsub!("\000", '\\\\')
-		return res
-	end
-
 	## encodes a string for the shell.
 	##   peter's song.mp3 -> 'peter'\''s song.mp3'
 	##
@@ -90,6 +85,7 @@ class String
 		"#{ gsub("'", "'\\\\''") }"
 	end
 	alias ~ bash_escape
+	alias sh bash_escape
 end
 
 class Numeric