init plugin

This commit is contained in:
kyazdani42 2020-02-04 19:59:14 +01:00
commit 7ec6a588d5
4 changed files with 142 additions and 0 deletions

15
LICENSE Normal file
View File

@ -0,0 +1,15 @@
Tree.lua is a simple tree for neovim
Copyright © 2012 Yazdani Kiyan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

20
README.md Normal file
View File

@ -0,0 +1,20 @@
# A simple tree for neovim written in lua
## Notice
This work is under development, do not try to use it, it does not work.
I am working on this plugin to learn lua, become better with neovim api and create a **simple** file explorer with features i need.
I really don't like any of the vim trees, they are all too complicated for their purpose. I do have my shell to do most commands.
## Goals / Features
- [] moving around the file structure like any basic tree
- [] open file in current buffer or in split with FzF like bindings (CR, C-v, C-x)
- [] add / delete file in directory
- [] quickly find file in the directory structure
- [] icons for files
- [] simple git integration (color of file changing when staged/changed)

95
lua/tree.lua Normal file
View File

@ -0,0 +1,95 @@
local dir_struct = vim.fn.systemlist('ls')
local sys = function(v) vim.fn.system(v) end
local syslist = function(v) vim.fn.systemlist(v) end
local api = vim.api
local buf = nil
local win = nil
local function open()
local win_width = 30
local options = {
bufhidden = 'wipe';
buftype = 'nowrite';
modifiable = false;
}
buf = api.nvim_create_buf(false, true)
for opt, val in pairs(options) do
api.nvim_buf_set_option(buf, opt, val)
end
api.nvim_command('topleft '..win_width..'vnew | set nonumber norelativenumber')
win = api.nvim_win_get_number(0)
api.nvim_win_set_buf(win, buf)
end
local function update_view()
api.nvim_buf_set_option(buf, 'modifiable', true)
api.nvim_buf_set_lines(buf, 1, -1, false, dir_struct)
api.nvim_buf_set_option(buf, 'modifiable', false)
end
local function is_dir(path)
return string.match(sys('ls -l '..path), 'total [0-9].*') ~= nil
end
local function close()
api.nvim_win_close(win, true)
win = nil
buf = nil
end
local function set_mappings()
local mappings = {
['<CR>'] = 'open_file("edit")';
['<C-v>'] = 'open_file("vsplit")';
['<C-x>'] = 'open_file("split")';
f = 'find_file()';
}
for k,v in pairs(mappings) do
api.nvim_buf_set_keymap(buf, 'n', k, ':lua require"tree".'..v..'<cr>', {
nowait = true, noremap = true, silent = true
})
end
end
local function open_file(open_type)
local str = api.nvim_get_current_line()
if is_dir(str) then
local cur_dir = syslist('ls')
local sub_dir = syslist('ls')
-- local final_data = {}
update_view()
else
print(open_type)
-- api.nvim_command(open_type..' '..str)
end
end
local function find_file()
local str = api.nvim_get_current_line()
print(str)
end
local function win_open()
return false
end
local function toggle()
if win_open() then
close()
else
open()
update_view()
set_mappings()
end
end
return {
toggle = toggle;
open_file = open_file;
find_file = find_file;
}

12
plugin/tree.vim Normal file
View File

@ -0,0 +1,12 @@
if exists('g:loaded_tree') | finish | endif
let s:save_cpo = &cpo
set cpo&vim
command! LuaTree lua require'tree'.toggle()
let &cpo = s:save_cpo
unlet s:save_cpo
let g:loaded_tree = 1