diff --git a/README.md b/README.md index dd89d84..22e3fcf 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,15 @@ Key mappings can either be a string, or a table of strings if you want multiple } ``` +## Commands +```viml +" Toggle Triptych +:Triptych + +" Open Triptych at specific directory +:Triptych ~/Documents +``` + ## LSP Integration If you have [antosha417/nvim-lsp-file-operations](https://github.com/antosha417/nvim-lsp-file-operations) installed, performing diff --git a/lua/triptych/init.lua b/lua/triptych/init.lua index 121163b..38b2e0a 100644 --- a/lua/triptych/init.lua +++ b/lua/triptych/init.lua @@ -18,7 +18,7 @@ end ---@param dir? string Path of directory to open. If omitted will be the directory containing the current buffer ---@return fun()|nil local function toggle_triptych(dir) - if dir and not vim.fn.isdirectory(dir) then + if dir and vim.fn.isdirectory(dir) == 0 then return warn(tostring(dir) .. ' is not a directory') end @@ -157,9 +157,19 @@ local function setup(user_config) vim.g.triptych_is_open = false - vim.api.nvim_create_user_command('Triptych', function() - toggle_triptych() - end, {}) + vim.api.nvim_create_user_command('Triptych', function(opts) + if opts.args == "" then + toggle_triptych() + else + local path = vim.fn.expand(opts.args) + + toggle_triptych(path) + end + end, + { + nargs = '?', + complete = 'dir', + }) vim.g.triptych_config = require('triptych.config').create_merged_config(user_config or {}) end diff --git a/lua/triptych/view.lua b/lua/triptych/view.lua index 029e6b6..dd2fcc5 100644 --- a/lua/triptych/view.lua +++ b/lua/triptych/view.lua @@ -271,6 +271,9 @@ end ---@param maybe_cursor_target_path string? ---@return nil function M.set_primary_and_parent_window_targets(State, target_dir, maybe_cursor_target_path) + if target_dir:len() > 1 and string.sub(target_dir, -1) == '/' then + target_dir = string.sub(target_dir, 1, target_dir:len() - 1) + end local config_options = vim.g.triptych_config.options local icons_enabled = config_options.file_icons.enabled