<commit_before>class MiscController < ApplicationController
  layout "application", :only => [:init]
  def init
    puts "<h2>Initializing Git Repository in #{ENV['TM_PROJECT_DIRECTORY']}</h2>"
    puts htmlize(git.init(ENV["TM_PROJECT_DIRECTORY"]))
  end
  
  def gitk
    run_detached("gitk --all", "Wish Shell")
  end
  
  def gitgui
    run_detached("git-gui", "Git Gui")
  end
  
  def gitnub
    cmd = first_which(git.config["git-tmbundle.gitnub-path"], "nub", "/Applications/GitNub.app/Contents/MacOS/GitNub")
    if cmd
      run_detached(cmd, "Gitnub")
    else
      puts "Unable to find Gitnub.  Use the config dialog to set the Gitnub path to where you've installed it."
      output_show_tool_tip
    end
  end
  
  protected
    def first_which(*args)
      args.map do |arg|
        next if arg.blank?
        result = `which '#{arg}'`.strip
        return result unless result.empty?
      end
      nil
    end
    
    def run_detached(cmd, app_name)
      exit if fork            # Parent exits, child continues.
      Process.setsid          # Become session leader.
      exit if fork            # Zap session leader.

      # After this point you are in a daemon process
      pid = fork do
        STDOUT.reopen(open('/dev/null'))
        STDERR.reopen(open('/dev/null'))
        git.chdir_base
        Thread.new do
          sleep 1
          %x{osascript -e 'tell app "#{app_name}" to activate'}
          exit
        end
        system(cmd)
      end

      Process.detach(pid)
      #inspired by http://andrejserafim.wordpress.com/2007/12/16/multiple-threads-and-processes-in-ruby/
    end
  
end<commit_msg>fixes for external app loader - automatically add the path to git in the PATH (just in case TM_GIT is set, but not PATH itself), so system can find gitk and git-gui<commit_after>class MiscController < ApplicationController
  layout "application", :only => [:init]
  def init
    puts "<h2>Initializing Git Repository in #{ENV['TM_PROJECT_DIRECTORY']}</h2>"
    puts htmlize(git.init(ENV["TM_PROJECT_DIRECTORY"]))
  end
  
  def gitk
    run_detached("PATH=#{File.dirname(git.git)}:$PATH && gitk --all", "Wish Shell")
  end
  
  def gitgui
    run_detached("PATH=#{File.dirname(git.git)}:$PATH && git-gui", "Git Gui")
  end
  
  def gitnub
    cmd = first_which(git.config["git-tmbundle.gitnub-path"], "nub", "/Applications/GitNub.app/Contents/MacOS/GitNub")
    if cmd
      run_detached(cmd, "Gitnub")
    else
      puts "Unable to find Gitnub.  Use the config dialog to set the Gitnub path to where you've installed it."
      output_show_tool_tip
    end
  end
  
  protected
    def first_which(*args)
      args.map do |arg|
        next if arg.blank?
        result = `which '#{arg}'`.strip
        return result unless result.empty?
      end
      nil
    end
    
    def run_detached(cmd, app_name)
      exit if fork            # Parent exits, child continues.
      Process.setsid          # Become session leader.
      exit if fork            # Zap session leader.

      # After this point you are in a daemon process
      pid = fork do
        STDOUT.reopen(open('/dev/null'))
        STDERR.reopen(open('/dev/null'))
        git.chdir_base
        Thread.new do
          sleep 1.5
          %x{osascript -e 'tell app "#{app_name}" to activate'}
          exit
        end
        system(cmd)
      end

      Process.detach(pid)
      #inspired by http://andrejserafim.wordpress.com/2007/12/16/multiple-threads-and-processes-in-ruby/
    end
  
end
{'fraction_non_alphanumeric': 0.105848787446505, 'fraction_numerical': 0.006562054208273894, 'mean_word_length': 2.335870599429115, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1874967', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1131, 'n_words': 309}