TextMate包搜索和粘贴代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TextMate包搜索和粘贴代码相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env ruby -wKU # Copyright 2008 Hirotsugu Asari require "xmlrpc/client" require 'cgi' CMD = [ ENV['TM_SUPPORT_PATH'] + '/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog' ] if ENV['SNIPPLR_KEY'].nil? args = [ 'ok-msgbox', '--no-cancel', '--title "Snipplr"', '--text "Environment variable SNIPPLR_KEY missing."', '2>/dev/null' ] %x{ #{ (CMD + args).join(" ") } } exit end # get tags from user args = [ 'standard-inputbox', '--title "Get Snippet from Snipplr"', '--informative-text "Enter tags to search for"', '--string-output', '2>/dev/null' ] user_response_for_tags = %x{#{(CMD + args).join(" ")}}.split(" ") if user_response_for_tags[0] == 'Cancel' exit end # grab snippets from server matches = [] begin matches = srv.call('snippet.list',ENV['SNIPPLR_KEY'],user_response_for_tags[1],'date') rescue args = [ 'ok-msgbox', '--no-cancel', '--title "Snipplr"', "--text 'No matching snippet found.'", '2>/dev/null' ] %x{ #{ (CMD + args).join(" ") } } exit end ## XML-RPC call may return multiple instances of identical item, so trim ## the hash to our needs snippet_title = {} matches.each do |h| if !snippet_title.has_key?(h['id']) snippet_title[h['id']] = h['title'] end end item_string = '' # for CocoaDialog option snippet_title.each_value do |s| item_string += %Q{ '#{s}' } end args = [ 'standard-dropdown', '--title "Snipplr"', '--text "Select Snippet"', '--exit-onchange', '--string-output', '--items ' + item_string, '2>/dev/null' ] user_choice_for_snippet = %x{#{(CMD + args).join(" ")}}.split(" ") if user_choice_for_snippet[0] == 'Cancel' exit end begin puts CGI.unescapehtml(srv.call('snippet.get',snippet_title.index(user_choice_for_snippet[1]))["source"]) rescue args = [ 'ok-msgbox', '--no-cancel', '--title "Snipplr"', "--text 'No matching snippet found.'", '2>/dev/null' ] %x{ #{ (CMD + args).join(" ") } } end
以上是关于TextMate包搜索和粘贴代码的主要内容,如果未能解决你的问题,请参考以下文章