Skip to content

Instantly share code, notes, and snippets.

@DeaR
Last active December 11, 2015 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeaR/4647152 to your computer and use it in GitHub Desktop.
Save DeaR/4647152 to your computer and use it in GitHub Desktop.
Complete by command for NYAOS 3.x
-- Complete by command for NYAOS 3.x
--
-- Maintainer: DeaR <nayuri@kuonn.mydns.jp>
-- Last Change: 13-Aug-2013.
-- License: MIT License {{{
-- Copyright (c) 2013 DeaR <nayuri@kuonn.mydns.jp>
-- Copyright (c) 2011 azu_re
-- Copyright (c) 2010 wantora
--
-- Permission is hereby granted, free of charge, to any person obtaining a
-- copy of this software and associated documentation files (the
-- "Software"), to deal in the Software without restriction, including
-- without limitation the rights to use, copy, modify, merge, publish,
-- distribute, sublicense, and/or sell copies of the Software, and to
-- permit persons to whom the Software is furnished to do so, subject to
-- the following conditions:
--
-- The above copyright notice and this permission notice shall be included
-- in all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- }}}
nyaos_complete_by = {}
function nyaos.complete(basestring, pos, misc)
local cl = misc.text:match('[;|]') and misc.text:match('[^;|]+$') or misc.text
local cmd = (cl:match('^%s*\034([^\034]+)\034') or cl:match('^%s*([^%s]+)') or ''):match('[^/\\]+$')
return cmd and nyaos_complete_by[cmd] and nyaos_complete_by[cmd](basestring, pos, misc) or nyaos.default_complete(basestring, pos)
end
-- _nya_git.lua
local completes_cache = {}
function nyaos_complete_by.hg(basestring, pos, misc)
if not completes_cache['hg'] then
local cmds = nyaos.default_complete(basestring, pos)
local function insert_cmd(str)
for line in (str:match('\nlist of commands:\n\n(.-)\n\n') or ''):gmatch('[^\n]+') do
local name = line:match('^ ([^%s:,]+)')
if name then
table.insert(cmds, name)
end
end
end
local HGPLAIN = os.getenv('HGPLAIN') or ''
nyaos.exec('set HGPLAIN=1')
h = nyaos.eval('hg help -v')
insert_cmd(h)
for line in (h:match('\nenabled extensions:\n\n(.-)\n\n') or ''):gmatch('[^\n]+') do
insert_cmd(nyaos.eval('hg help '..line:match('^ ([^%s]*)')..' -v'))
end
nyaos.exec('set HGPLAIN='..HGPLAIN)
completes_cache['hg'] = cmds
end
return completes_cache['hg']
end
function nyaos_complete_by.gem(basestring, pos, misc)
if not completes_cache['gem'] then
local cmds = nyaos.default_complete(basestring, pos)
for line in nyaos.eval('gem help commands'):gmatch('[^\n]+') do
local name = line:match('^ ([^%s]*)')
if #cmds > 0 and (not name) then
break
end
if name and #name > 0 then
table.insert(cmds, name)
end
end
completes_cache['gem'] = cmds
end
return completes_cache['gem']
end
function nyaos_complete_by.git(basestring, pos, misc)
function ArrayUnique(arr)
local key = {};
local ret = {};
for k, v in pairs(arr) do
if type(key[v]) == [[nil]] then
key[v] = v;
table.insert(ret,v);
end
end
return ret;
end
if not completes_cache['git'] then
local cmds = nyaos.default_complete(basestring, pos)
for line in nyaos.eval('git help -a'):gmatch('[^\n]+') do
if line:match('^%s') then
for name in line:gmatch('%s+([%w-]*)') do
if #cmds > 0 and (not name) then
break
end
if name and #name > 1 then
table.insert(cmds, name)
end
end
end
end
for line in nyaos.eval('git help'):gmatch('[^\n]+') do
local name = line:match('^ ([%w-]*)')
if name and #name > 0 then
table.insert(cmds, name)
end
end
completes_cache['git'] = ArrayUnique(cmds)
end
return completes_cache['git']
end
nyaos_complete_by['hg.exe'] = nyaos_complete_by.hg
nyaos_complete_by['gem.exe'] = nyaos_complete_by.gem
nyaos_complete_by['git.exe'] = nyaos_complete_by.git
-- vim: ft=lua

complete_by.lua

Complete by command for NYAOS 3.x

Install

  1. Checkout the source from repository

    git clone https://gist.github.com/4647152.git complete_by
  2. add to _nya

    source complete_by/complete_by.lua

Usage

  • git and press complete key

Issue

Author

DeaR (nayuri@kuonn.mydns.jp)

@nayuri_aohime

License

Copyright (c) 2013 DeaR <nayuri@kuonn.mydns.jp>
Copyright (c) 2011 azu_re
Copyright (c) 2010 wantora

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@DeaR
Copy link
Author

DeaR commented Jan 27, 2013

_nya_git.lua との違い

  • キャッシュの使用は各コマンドに任せる(z.luabasestringによって動的に生成している)
  • 他ファイルでも宣言できるようグローバル化(なので早めに読み込んだ方が良い)
  • C:\Program Files\Mercurial\hg.exeの様なのもhg.exeとして関数を呼ばれる

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment