Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
103 lines (92 sloc) 3.236 kb
Vimdb.vim = 'mvim -v'
Vimdb.plugins_dir = '(plugins|autoload)'
# Additional commands for keys
class Vimdb::Runner
option :list, :desc => 'only prints list of keys left'
desc 'Determines keys left for a given key combo'
def left(key_combo, options={})
query = '^' + Regexp.escape(key_combo)
query << '[a-z]' if query.end_with?('-')
regex = Regexp.new query
keys = Vimdb.user.items
keys.select! {|e| e[:key] =~ regex }
available = ('a' .. 'z').to_a
if key_combo.end_with? '-'
available.map! {|e| key_combo + e }
available -= keys.map {|e| e[:key][/^\S+/] }.compact
elsif key_combo[/-\S/]
available.map! {|e| "#{key_combo} #{e}" }
if !keys.empty? && keys.all? {|e| e[:key] == key_combo }
abort "This key is a top level key"
end
available -= keys.map {|e| e[:key] }
else
abort "Invalid query. Query must be the beginning of a key combo" +
" i.e. C- or C-a."
end
if options[:list]
available << "No combinations left" if available.empty?
puts available, "#{available.size} keys left"
else
keys += available.map {|key| {key: key, desc: '** AVAILABLE **'} }
keys.sort_by! {|e| e[:key] }
puts Hirb::Helpers::Table.render(keys,
fields: [:key, :mode, :from, :desc], headers: {:desc => 'desc/action'})
end
end
desc 'List conflict keys'
def conflict
keys = Vimdb.user.items
defaults = keys.select {|e| e[:from] == 'default' }.
each_with_object({}) {|e,t| t[e[:key]] = e }
conflicts = []
keys.each {|e|
if e[:from] != 'default' && (default = defaults[e[:key]]) &&
modes_are_same?(e, default)
conflicts << default
conflicts << e
end
}
puts Hirb::Helpers::Table.render(conflicts,
fields: [:key, :mode, :from, :desc], headers: {desc: 'desc/action'})
end
common_search_options
desc 'Prints out item info in tab format for anki'
def anki(query=nil, options={})
require 'cgi'
keys = Vimdb.user.search(query, options)
keys.group_by {|e| e[:desc] }.each {|desc,common_keys|
puts "#{CGI.escapeHTML(desc)}<br/>mode: #{common_keys.map {|e| e[:mode] }.uniq.join(',')}" +
"\t" + CGI.escapeHTML(common_keys.map {|e| e[:key] }.uniq.join(', '))
}
end
common_search_options
option :tag, :required => true
desc 'Tags a specific item with a tag'
def tag(query, options={})
items = Vimdb.user.search(query, options)
if items.size > 1
Hirb.enable
items = Hirb::Menu.render(items, fields: Vimdb.item.fields)
end
items.each do |item|
system('tag', 'add', "#{item[:key]}.#{item[:mode]}", '--tags', options[:tag])
end
end
desc 'List items in tag'
def tag_list(tag)
ids = `tag list #{tag}`.split("\n")
items = Vimdb.user.items
keys = ids.map {|id| id.split('.') }.map do |(key, mode)|
items.find {|item|
item[:key] == key && item[:mode].include?(mode)
} or raise "No key found for '#{key}.#{mode}'"
end
puts Hirb::Helpers::Table.render(keys, fields: Vimdb.item.fields)
end
private
def modes_are_same?(key1, key2)
(key1[:mode].split('') & key2[:mode].split('')).any?
end
end
# vim: ft=ruby
Jump to Line
Something went wrong with that request. Please try again.