From bfa870f126c64d1ed0ea3c3b8028ad7716c45455 Mon Sep 17 00:00:00 2001
From: Martin Kuehl <martin.kuehl@gmail.com>
Date: Wed, 25 Mar 2009 18:51:50 +0100
Subject: [PATCH 4/7] =?utf-8?q?=E2=80=A2=20Add=20:version=5Freplace=20option=20to=20allow=20mangling=20of=20the=20parsed=20--version=20output.
=20=E2=80=A2=20Document=20the=20:version=5Freplace=20option.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

---
 lib/tm/executor.rb |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/lib/tm/executor.rb b/lib/tm/executor.rb
index 6bf85f3..a09c274 100644
--- a/lib/tm/executor.rb
+++ b/lib/tm/executor.rb
@@ -32,7 +32,9 @@
 # TextMate::Executor.run also accepts six optional named arguments.
 #   :version_args are arguments that will be passed to the executable to generate a version string for use as the page's subtitle.
 #   :version_regex is a regular expression to which the resulting version string is passed.
-#     $1 of this regex is used as the subtitle of the Executor.run output.  By default, this just takes the first line.
+#     The subtitle of the Executor.run output is generated from this match.  By default, this just takes the first line.
+#   :version_replace is a string that is used to generate a version string for the page's subtitle from matching :version_regex.
+#     The rules of String.sub apply.  By default, this just extracts $1 from the match.
 #   :verb describes what the call to Executor is doing.  Default is “Running”.
 #   :env is the environment in which the command will be run.  Default is ENV.
 #   :script_args are arguments to be passed to the *script* as opposed to the interpreter.  They will
@@ -63,12 +65,13 @@ module TextMate
         block ||= Proc.new {}
         args.flatten!
 
-        options = {:version_args  => ['--version'],
-                   :version_regex => /\A(.*)$/,
-                   :verb          => "Running",
-                   :env           => nil,
-                   :script_args   => [],
-                   :use_hashbang  => true}
+        options = {:version_args    => ['--version'],
+                   :version_regex   => /\A(.*)$/,
+                   :version_replace => '\1',
+                   :verb            => "Running",
+                   :env             => nil,
+                   :script_args     => [],
+                   :use_hashbang    => true}
 
         options[:bootstrap] = ENV["TM_BUNDLE_SUPPORT"] + "/bin/bootstrap.sh" unless ENV["TM_BUNDLE_SUPPORT"].nil?
 
@@ -190,7 +193,9 @@ module TextMate
 
       def parse_version(executable, options)
         out, err = TextMate::Process.run(executable, options[:version_args], :interactive_input => false)
-        return $1 if options[:version_regex] =~ (out + err)
+        if options[:version_regex] =~ (out + err)
+          return (out + err).sub(options[:version_regex], options[:version_replace])
+        end
       end
 
       private
-- 
1.6.1.3

