# Encoding: UTF-8

[{beforeRunningCommand: "nop",
  command: "\"${TM_P4:=p4}\" add \"$TM_FILEPATH\"\n",
  input: "none",
  keyEquivalent: "^$",
  name: "Add to Depot",
  output: "showAsTooltip",
  uuid: "AD9B4CB8-7577-11D9-A32D-000A95A89C98"},
 {beforeRunningCommand: "nop",
  command: "\"${TM_P4:=p4}\" annotate -c -i -q \"$TM_FILEPATH\"\n",
  input: "none",
  keyEquivalent: "^$",
  name: "Annotate",
  output: "openAsNewDocument",
  uuid: "D6F5F368-C476-4882-82EA-D11E22A445BF"},
 {beforeRunningCommand: "nop",
  command: 
   "labels=`\"${TM_P4:=p4}\" labels | cut -d \" \" -f 2`\n#echo $labels\n\ndifflabels=`osascript<<END\n\tset AppleScript's text item delimiters to {\"\\n\", \"\\r\"}\n\ttell app \"SystemUIServer\" to activate\n\ttell app \"SystemUIServer\" to choose from list (every text item of \"$labels\") with prompt \"Please \nchoose two labels:\" with multiple selections allowed\nEND`\n#echo $difflabels\n\nIFS=\", \"\ndifflabels=( $difflabels )\n\n#echo \"0:\" ${difflabels[0]}\n#echo \"1:\" ${difflabels[1]}\n\nruby -I \"$TM_BUNDLE_SUPPORT/lib/\"<<END\n\trequire 'p4_diff'\n\tPerforce::diff_files_in_revisions(\"@${difflabels[0]}\", \"@${difflabels[1]}\", \"Perforce—Diff Labels…\")\nEND\n",
  input: "none",
  keyEquivalent: "^$",
  name: "Diff Labels…",
  output: "openAsNewDocument",
  uuid: "556314B2-B3BF-11D9-9B1F-000A95A89C98"},
 {beforeRunningCommand: "nop",
  command: 
   "#!/usr/bin/env ruby -w\n\n$LOAD_PATH << ENV['TM_BUNDLE_SUPPORT'] + \"/lib\"\nrequire 'p4_diff'\n\nPerforce::diff_active_file(\"\", \"Perforce—Diff With Base\")\n",
  input: "none",
  keyEquivalent: "^$",
  name: "Diff With Base",
  output: "openAsNewDocument",
  uuid: "38C6DE3A-7664-11D9-B58C-000A95A89C98"},
 {beforeRunningCommand: "nop",
  command: 
   "labels=`\"${TM_P4:=p4}\" labels \"$TM_FILEPATH\" | cut -d \" \" -f 2`\n\nrevs=`osascript<<END\n\tset AppleScript's text item delimiters to {\"\\n\",\"\\r\"}\n\ttell app \"SystemUIServer\"\n\t\tactivate\n\t\tset ourList to (every text item of \"$labels\")\n\t\tif the count of items in ourList is 0 then\n\t\t\tdisplay dialog \"No labels found\" buttons (\"OK\")\n\t\t\tset the result to false\n\t\telse\n\t\t\tchoose from list ourList with prompt \"Diff '$(basename \"$TM_FILEPATH\")' with version in label:\"\n\t\tend if\n\tend tell\nEND`\n\n# exit if user canceled\nif [ $revs = \"false\" ]\nthen\n\tosascript >/dev/null 2>&1 -e 'tell application \"TextMate\" to activate' &\texit 0\t\nfi\n\nrevs=( $revs )\n\nruby -I \"$TM_BUNDLE_SUPPORT/lib/\"<<END\n\trequire 'p4_diff'\n\tPerforce::diff_active_file(\"@$revs\", \"Perforce—Diff With Revision in Label…\")\nEND\n",
  input: "none",
  keyEquivalent: "^$",
  name: "Diff With Revision In Label…",
  output: "openAsNewDocument",
  uuid: "97E895A4-B5B9-11D9-80D4-000A95A89C98"},
 {beforeRunningCommand: "nop",
  command: 
   "cd $TM_PROJECT_DIRECTORY\n\"${TM_P4:=p4}\" diff -se ./... | \"${TM_P4:=p4}\" -x - edit",
  input: "none",
  keyEquivalent: "^$",
  name: "Edit Lurkers",
  output: "openAsNewDocument",
  uuid: "3E208CDF-268C-4A23-902B-5628596E4BC8"},
 {beforeRunningCommand: "nop",
  command: 
   ". \"$TM_SUPPORT_PATH/lib/webpreview.sh\"\n\nhtml_header \"Perforce Bundle Help\" \"Perforce\"\n\nMarkdown.pl <<\"EOF\"|SmartyPants.pl\n\nThe Perforce bundle contains commands to allow one to work with the [Perforce Software Configuration Management System](http://perforce.com/) from within TextMate.\n\nThis document assumes that the reader has already installed and is familiar with Perforce.  For help with Perforce, see [http://perforce.com/perforce/technical.html](http://perforce.com/perforce/technical.html).\n\n## Setup\n\nYou probably already have the following environment variables defined (in a file such as .bash_profile or .p4config) in order to use the `p4` shell command:\n\n *  P4PORT\n *  P4USER\n *  P4CLIENT\n\nThe Perforce bundle commands that don't use the shell (such as \"Diff With Base\") don't have access to environment variables (such as those defined in .bash_profile), so they need to be defined in TextMate.\n\n 1.  Select the TextMate → Preferences… menu item\n 2.  Click on Advanced (the gear icon)\n 3.  Click on Shell Variables\n 4.  Click on '+', and change \"MY_VARIABLE\" to \"P4PORT\" and change \"some value\" to the appropriate P4PORT value for your Perforce server\n 5.  Repeat step 4 for P4USER and P4CLIENT \n\nEOF\n\nhtml_footer\n",
  input: "none",
  name: "Help",
  output: "showAsHTML",
  uuid: "80BD96D6-C41C-45F3-8CAE-E6D88B9D7339"},
 {beforeRunningCommand: "nop",
  command: 
   "# record a file that we're editing offline for later\n# (presumably when access to Perforce is restored)\n\n# now record the file\nmkdir -p \"$HOME/P4Cache\"\necho \"$TM_FILEPATH\" >> \"$HOME/P4Cache/OfflineAdds.txt\";\n",
  input: "none",
  keyEquivalent: "^$",
  name: "Offline Add to Depot",
  output: "showAsTooltip",
  uuid: "1194ED50-336C-45F8-9E73-C777FB3FAF88"},
 {beforeRunningCommand: "nop",
  command: 
   "# record a file that we're editing offline for later\n# (presumably when access to Perforce is restored)\n\n# first, unlock the file if we need to unlock it\nchmod +r \"$TM_FILEPATH\"\n/Developer/Tools/SetFile -a l \"$TM_FILEPATH\"\n\n# now record the file\nmkdir -p \"$HOME/P4Cache\"\necho \"$TM_FILEPATH\" >> \"$HOME/P4Cache/OfflineEdits.txt\";\n",
  input: "none",
  keyEquivalent: "^$",
  name: "Offline Open For Editing",
  output: "showAsTooltip",
  uuid: "092CED4D-9C4C-4ED7-BB6A-5C80D929D9FD"},
 {beforeRunningCommand: "nop",
  command: 
   "\n# if we have offline edits, send them now (assumes we're actually online again)\nif [[ -e  \"$HOME/P4Cache/OfflineEdits.txt\" ]]; then\n\t\"$TM_P4\" -x \"$HOME/P4Cache/OfflineEdits.txt\" edit && rm \"$HOME/P4Cache/OfflineEdits.txt\"\nfi\n\n# if we have offline adds, send them now (assumes we're actually online again)\nif [ -e  \"$HOME/P4Cache/OfflineAdds.txt\" ]; then\n\t\"$TM_P4\" -x add \"$HOME/P4Cache/OfflineAdds.txt\" && rm \"$HOME/P4Cache/OfflineAdds.txt\"\nfi\n",
  input: "none",
  keyEquivalent: "^$",
  name: "Offline Send Offline Edits",
  output: "showAsTooltip",
  uuid: "A1DCDF0B-628B-4590-87C0-A551DC1F5F3A"},
 {beforeRunningCommand: "nop",
  command: "\"${TM_P4:=p4}\" edit \"$TM_FILEPATH\"\n",
  input: "none",
  keyEquivalent: "^$",
  name: "Open for Editing",
  output: "showAsTooltip",
  uuid: "9982EC7A-7577-11D9-A32D-000A95A89C98"},
 {beforeRunningCommand: "nop",
  command: 
   "\"${TM_P4:=p4}\" revert \"$TM_FILEPATH\"\n\n# force TM to refresh the current file..\nrescan_project\n",
  input: "none",
  keyEquivalent: "^$",
  name: "Revert to Latest",
  output: "showAsTooltip",
  uuid: "E73FA01C-7625-11D9-B58C-000A95A89C98"},
 {beforeRunningCommand: "nop",
  command: 
   "#!/usr/bin/env ruby -w\n\n$LOAD_PATH << ENV['TM_BUNDLE_SUPPORT'] + \"/lib\"\n$LOAD_PATH << ENV['TM_SUPPORT_PATH'] + \"/lib\"\n\nrequire 'p4_forms'\nrequire 'shelltokenize'\n\np4\t\t\t\t= ENV['TM_P4'] || 'p4'\n#commit_paths\t= ENV['CommitPaths']\nsupport\t\t\t= ENV['TM_SUPPORT_PATH']\ncommit_tool\t\t= support + \"/bin/CommitWindow.app/Contents/MacOS/CommitWindow\"\n\nignore_file_pattern = /(\\/.*)*(\\/\\..*|\\.(tmproj|o|pyc)|Icon)/\n\n\nStatusMap = {\t'edit' \t\t=> 'M',\n\t\t\t'add'\t\t=> 'A',\n\t\t\t'delete'\t=> 'D'}\n\t# TODO others probably needed\n\t\t\noutput = %x{\"\#{p4}\" change -o}\nputs output\n\ncommit_form = Perforce::Form.new(output)\n#puts commit_form.inspect\n\nraw_paths = commit_form.paths_from_entry(\"Files\")\ncommit_paths = []\ncommit_status = []\n\nraw_paths.each do |path|\n\tmatch = /^(.*)\\s#\\s(\\w*)/.match(path)\n\tcommit_paths.push(match[1])\n\tcommit_status.push(match[2])\nend\n\t\t\n# map to CVS-like status for CommitWindow display\ncommit_status = commit_status.collect{|status| StatusMap[status]}\n\ncommit_paths = commit_paths.collect {|path| path.p4_to_local_path }\ncommit_path_text = commit_paths.join_p4_to_local_paths\n\n#puts commit_path_text\n#puts \"--------------\"\n\ncommit_args = %x{\"\#{commit_tool}\" --status \#{commit_status.join(\":\")} \#{commit_path_text}}\n#puts commit_args\n#puts \"--------------\"\n\ncommit_tokens = commit_args.tokenize\n\n#puts commit_tokens.inspect\n\ncommit_form.fields['Status'] = 'pending'\ncommit_form.fields['Description'] = commit_tokens[1]\ncommit_form.fields['Files'] = commit_tokens[2...commit_tokens.size].local_to_p4_paths.inject(\"\") {|out, path| out += \"\#{path}\\n\" }\n\n\nputs commit_form.to_s\n\nIO.popen(%Q{\"\#{p4}\" submit -i}, \"w+\" ) {|p| p.puts commit_form.to_s }\n\n",
  input: "none",
  keyEquivalent: "^$",
  name: "Submit Changelist…",
  output: "openAsNewDocument",
  uuid: "BE2B6161-2E23-4C08-B438-409BB1E82DA8"}]
