diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fbfde7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*/tags diff --git a/.luarc.jsonc b/.luarc.jsonc new file mode 100644 index 0000000..641727b --- /dev/null +++ b/.luarc.jsonc @@ -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" +} diff --git a/README.md b/README.md index 8b1edbe..81ef1a0 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,7 @@ use( vim.keymap.set("n", "", ":Lf") end, - requires = { - "plenary.nvim", - "toggleterm.nvim" - } + requires = {"plenary.nvim", "toggleterm.nvim"} } ) ``` @@ -174,3 +171,4 @@ The `autocmd` `LfTermEnter` is fired when the terminal buffer first opens - [ ] `:LfToggle` command - [ ] Save previous size when terminal is closed, so it is restored on open - [ ] Set Lualine to `Lf` title +- [ ] Fix weird wrapping error that occurs every so often when moving down a list of files diff --git a/doc/lf.txt b/doc/lf.txt new file mode 100644 index 0000000..2a3d48a --- /dev/null +++ b/doc/lf.txt @@ -0,0 +1,78 @@ +*lf.txt* File Manager + +Version: 0.2 +Author : Lucas Burns +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* file manager inside of Neovim. + +There is a similar plugin *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 . + +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", "", ":Lf") + 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: diff --git a/lua/lf/main.lua b/lua/lf/main.lua index b55cdf4..f94c8e4 100644 --- a/lua/lf/main.lua +++ b/lua/lf/main.lua @@ -18,9 +18,9 @@ end local api = vim.api local fn = vim.fn -local fs = vim.fs local uv = vim.loop local o = vim.o +local fs = utils.fs local map = utils.map ---Error for this program diff --git a/lua/lf/utils.lua b/lua/lf/utils.lua index ff48af4..29c1c81 100644 --- a/lua/lf/utils.lua +++ b/lua/lf/utils.lua @@ -1,7 +1,5 @@ local M = {} --- This was taken from toggleterm.nvim - local fn = vim.fn local api = vim.api local levels = vim.log.levels @@ -10,7 +8,7 @@ local o = vim.o ---Echo a message with `nvim_echo` ---@param msg string message ---@param hl string highlight group -M.echomsg = function(msg, hl) +function M.echomsg(msg, hl) hl = hl or "Title" api.nvim_echo({{msg, hl}}, true, {}) end @@ -19,7 +17,7 @@ end ---@param msg string ---@param level number ---@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"}) vim.notify(msg, level, opts) end @@ -28,7 +26,7 @@ end ---@param msg string ---@param notify boolean? ---@param opts table? -M.info = function(msg, notify, opts) +function M.info(msg, notify, opts) if notify then M.notify(msg, levels.INFO, opts) else @@ -40,7 +38,7 @@ end ---@param msg string ---@param notify boolean? ---@param opts table? -M.warn = function(msg, notify, opts) +function M.warn(msg, notify, opts) if notify then M.notify(msg, levels.WARN, opts) else @@ -52,7 +50,7 @@ end ---@param msg string ---@param notify boolean? ---@param opts table? -M.err = function(msg, notify, opts) +function M.err(msg, notify, opts) if notify then M.notify(msg, levels.ERROR, opts) else @@ -62,7 +60,7 @@ end ---Helper function to derive the current git directory path ---@return string|nil -M.git_dir = function() +function M.git_dir() ---@diagnostic disable-next-line: missing-parameter 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 rhs string|function string or lua function that is mapped to the keys ---@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.noremap = opts.noremap == nil and true or opts.noremap vim.keymap.set(mode, lhs, rhs, opts) @@ -86,7 +84,7 @@ end ---Set the tmux statusline when opening/closing `Lf` ---@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 return end @@ -155,4 +153,25 @@ function M.get_view(opts, bufnr, signcolumn) } 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