snailed
/
taolf
Archived
2
0
Fork 0

fix#2: fixes error indexing vim.fs

This commit is contained in:
Lucas Burns 2022-07-19 14:35:57 -05:00
parent 2c94f8da87
commit 6669d6aa35
No known key found for this signature in database
GPG Key ID: C011CBEF6628B679
6 changed files with 133 additions and 15 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*/tags

22
.luarc.jsonc Normal file
View File

@ -0,0 +1,22 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"IntelliSense.traceBeSetted": true,
"IntelliSense.traceFieldInject": true,
"IntelliSense.traceLocalSet": true,
"IntelliSense.traceReturn": true,
"completion.callSnippet": "Replace",
"completion.displayContext": 50,
"completion.keywordSnippet": "Disable",
"completion.postfix": ".",
"diagnostics.globals": [
"vim",
"jit",
"it",
"describe",
"before_each",
"after_each",
"setup",
"teardown"
],
"runtime.version": "LuaJIT"
}

View File

@ -25,10 +25,7 @@ use(
vim.keymap.set("n", "<C-o>", ":Lf<CR>") vim.keymap.set("n", "<C-o>", ":Lf<CR>")
end, end,
requires = { requires = {"plenary.nvim", "toggleterm.nvim"}
"plenary.nvim",
"toggleterm.nvim"
}
} }
) )
``` ```
@ -174,3 +171,4 @@ The `autocmd` `LfTermEnter` is fired when the terminal buffer first opens
- [ ] `:LfToggle` command - [ ] `:LfToggle` command
- [ ] Save previous size when terminal is closed, so it is restored on open - [ ] Save previous size when terminal is closed, so it is restored on open
- [ ] Set Lualine to `Lf` title - [ ] Set Lualine to `Lf` title
- [ ] Fix weird wrapping error that occurs every so often when moving down a list of files

78
doc/lf.txt Normal file
View File

@ -0,0 +1,78 @@
*lf.txt* File Manager
Version: 0.2
Author : Lucas Burns <https://github.com/lmburns>
License: BSD3
================================================================================
TABLE OF CONTENTS *lf-table-of-contents*
Introduction |lf-introduction|
Requirements |lf-requirements|
Installation |lf-installation|
Usage |lf-usage|
Configuration |lf-configuration|
================================================================================
INTRODUCTION *lf-introduction*
*lf.nvim* is a plugin written in Lua that allows you to use the
*lf* <https://github.com/gokechan/lf> file manager inside of Neovim.
There is a similar plugin *lf.vim* <https://github.com/ptzz/lf.vim> which
basically does the same thing, except that is is written in Vimscript.
Since this plugin uses the Neovim window API, Vim is not supported.
================================================================================
REQUIREMENTS *lf-requirements*
1. *Lf* (https://github.com/gokechan/lf)
2. *toggleterm.nvim* (https://github.com/akinsho/toggleterm.nvim)
3. *plenary.nvim* (https://github.com/nvim-lua/plenary.nvim)
================================================================================
INSTALLATION *lf-installation*
Requires *lf* to be installed. The installation instructions for *lf* can be
found here <https://github.com/gokcehan/lf#installation>.
A sample installation is given.
NOTE: Replacing |netrw| will not work correctly if the plugin is lazily loaded.
>
use(
{
"lmburns/lf.nvim",
config = function()
vim.g.lf_netrw = 1
require("lf").setup(
{
escape_quit = false,
border = "rounded",
highlights = {FloatBorder = {guifg = require("kimbox.palette").colors.magenta}}
}
)
vim.keymap.set("n", "<C-o>", ":Lf<CR>")
end,
requires = {"plenary.nvim", "toggleterm.nvim"}
}
)
<
================================================================================
USAGE *lf-usage*
The file manager can be opened with the |:Lf| command.
================================================================================
CONFIGURATION *lf-configuration*
================================================================================
vim:tw=80:sw=0:ts=2:sts=2:et:ft=help:norl:

View File

@ -18,9 +18,9 @@ end
local api = vim.api local api = vim.api
local fn = vim.fn local fn = vim.fn
local fs = vim.fs
local uv = vim.loop local uv = vim.loop
local o = vim.o local o = vim.o
local fs = utils.fs
local map = utils.map local map = utils.map
---Error for this program ---Error for this program

View File

@ -1,7 +1,5 @@
local M = {} local M = {}
-- This was taken from toggleterm.nvim
local fn = vim.fn local fn = vim.fn
local api = vim.api local api = vim.api
local levels = vim.log.levels local levels = vim.log.levels
@ -10,7 +8,7 @@ local o = vim.o
---Echo a message with `nvim_echo` ---Echo a message with `nvim_echo`
---@param msg string message ---@param msg string message
---@param hl string highlight group ---@param hl string highlight group
M.echomsg = function(msg, hl) function M.echomsg(msg, hl)
hl = hl or "Title" hl = hl or "Title"
api.nvim_echo({{msg, hl}}, true, {}) api.nvim_echo({{msg, hl}}, true, {})
end end
@ -19,7 +17,7 @@ end
---@param msg string ---@param msg string
---@param level number ---@param level number
---@param opts table? ---@param opts table?
M.notify = function(msg, level, opts) function M.notify(msg, level, opts)
opts = vim.tbl_extend("force", opts or {}, {title = "lf.nvim"}) opts = vim.tbl_extend("force", opts or {}, {title = "lf.nvim"})
vim.notify(msg, level, opts) vim.notify(msg, level, opts)
end end
@ -28,7 +26,7 @@ end
---@param msg string ---@param msg string
---@param notify boolean? ---@param notify boolean?
---@param opts table? ---@param opts table?
M.info = function(msg, notify, opts) function M.info(msg, notify, opts)
if notify then if notify then
M.notify(msg, levels.INFO, opts) M.notify(msg, levels.INFO, opts)
else else
@ -40,7 +38,7 @@ end
---@param msg string ---@param msg string
---@param notify boolean? ---@param notify boolean?
---@param opts table? ---@param opts table?
M.warn = function(msg, notify, opts) function M.warn(msg, notify, opts)
if notify then if notify then
M.notify(msg, levels.WARN, opts) M.notify(msg, levels.WARN, opts)
else else
@ -52,7 +50,7 @@ end
---@param msg string ---@param msg string
---@param notify boolean? ---@param notify boolean?
---@param opts table? ---@param opts table?
M.err = function(msg, notify, opts) function M.err(msg, notify, opts)
if notify then if notify then
M.notify(msg, levels.ERROR, opts) M.notify(msg, levels.ERROR, opts)
else else
@ -62,7 +60,7 @@ end
---Helper function to derive the current git directory path ---Helper function to derive the current git directory path
---@return string|nil ---@return string|nil
M.git_dir = function() function M.git_dir()
---@diagnostic disable-next-line: missing-parameter ---@diagnostic disable-next-line: missing-parameter
local gitdir = fn.system(("git -C %s rev-parse --show-toplevel"):format(fn.expand("%:p:h"))) local gitdir = fn.system(("git -C %s rev-parse --show-toplevel"):format(fn.expand("%:p:h")))
@ -78,7 +76,7 @@ end
---@param lhs string keys that are bound ---@param lhs string keys that are bound
---@param rhs string|function string or lua function that is mapped to the keys ---@param rhs string|function string or lua function that is mapped to the keys
---@param opts table? options set for the mapping ---@param opts table? options set for the mapping
M.map = function(mode, lhs, rhs, opts) function M.map(mode, lhs, rhs, opts)
opts = opts or {} opts = opts or {}
opts.noremap = opts.noremap == nil and true or opts.noremap opts.noremap = opts.noremap == nil and true or opts.noremap
vim.keymap.set(mode, lhs, rhs, opts) vim.keymap.set(mode, lhs, rhs, opts)
@ -86,7 +84,7 @@ end
---Set the tmux statusline when opening/closing `Lf` ---Set the tmux statusline when opening/closing `Lf`
---@param disable boolean: whether the statusline is being enabled or disabled ---@param disable boolean: whether the statusline is being enabled or disabled
M.tmux = function(disable) function M.tmux(disable)
if not vim.env.TMUX then if not vim.env.TMUX then
return return
end end
@ -155,4 +153,25 @@ function M.get_view(opts, bufnr, signcolumn)
} }
end end
M.fs = {}
---Return basename of the given file entry
---
---@param file string: File or directory
---@return string: Basename of `file`
function M.fs.basename(file)
return fn.fnamemodify(file, ":t")
end
---Return parent directory of the given file entry
---
---@param file string: File or directory
---@return string?: Parent directory of file
function M.fs.dirname(file)
if file == nil then
return nil
end
return fn.fnamemodify(file, ':h')
end
return M return M