Something went wrong. Try again.
A TextMate Bundle for Forester
Something went wrong. Try again.
2.6 kB · 94 lines
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict> <key>beforeRunningCommand</key> <string>nop</string> <key>command</key> <string>#!/usr/bin/env ruby# encoding: utf-8require "#{ENV['TM_SUPPORT_PATH']}/lib/ui"require 'pathname'
file = ENV['TM_FILEPATH']scope = ENV['TM_SCOPE'] || ""raw_query = STDIN.read
# Determine wrapper and strip it from queryprefix, suffix = case scope when /meta\.link\.wiki\.forester/ then ['[[', ']]'] when /meta\.link\.ref\.forester/ then ['{', '}'] when /meta\.link\.md\.forester/ then ['(', ')'] else ['', '']end
query = raw_query.dupquery = query[prefix.length..] if prefix.length > 0 && query.start_with?(prefix)query = query[0..-(suffix.length + 1)] if suffix.length > 0 && query.end_with?(suffix)
def find_forest_root(path) return nil if path.nil? current = Pathname.new(path).parent while current.to_s != "/" return current if (current + "forest.toml").exist? current = current.parent end nilend
root = find_forest_root(file)unless root TextMate::UI.tool_tip "No forest.toml found in ancestor directories." exit 200end
Dir.chdir(root) do raw_output = `forester complete --title="#{query}"` if $?.exitstatus != 0 TextMate::UI.tool_tip "forester failed to find completions (try building)." exit 200 end
if raw_output.nil? || raw_output.strip.empty? TextMate::UI.tool_tip "No matches found." exit 200 end
choices = raw_output.split("\n").map do |l| id, title = l.split(',', 2) next nil if id.nil? { 'display' => "#{title.strip} (#{id.strip})", 'insert' => "#{prefix}#{id.strip}#{suffix}", } end.compact
if choices.any? selected = TextMate::UI.menu(choices.map { |c| c['display'] }) print choices[selected]['insert'] if selected else TextMate::UI.tool_tip "No matches for: #{query}" endend</string> <key>input</key> <string>scope</string> <key>inputFormat</key> <string>text</string> <key>keyEquivalent</key> <string>^.</string> <key>name</key> <string>Complete</string> <key>outputCaret</key> <string>afterOutput</string> <key>outputFormat</key> <string>text</string> <key>outputLocation</key> <string>replaceInput</string> <key>scope</key> <string>meta.link.wiki.forester, meta.link.ref.forester, meta.link.md.forester</string> <key>uuid</key> <string>63B481D1-6AA9-457D-B872-CFC5EE99F8EC</string> <key>version</key> <integer>2</integer></dict></plist>