From 5b3bc3a1d6a8d412e83dc98fcf01f4c5779bfe5c Mon Sep 17 00:00:00 2001 From: Melker Ulander Date: Tue, 7 Feb 2023 16:57:50 +0100 Subject: [PATCH 1/2] feat: add map that does :tcd instead of :cd --- README.md | 8 +++++++- lua/telescope/_extensions/zoxide/config.lua | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b8b2d65..8742062 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,12 @@ vim.keymap.set("n", "cd", t.extensions.zoxide.list) action = function(selection) builtin.find_files({ cwd = selection.path }) end - } + }, + [""] = { + action = function(selection) + vim.cmd.tcd(selection.path) + end + }, } } ``` @@ -166,6 +171,7 @@ vim.keymap.set("n", "cd", t.extensions.zoxide.list) | Action | Description | Command executed | | ------- | ---------------------------------------------------- | ------------------------------------------------ | | `` | Change current directory to selection | `cd ` | +| `` | Change current tab's directory to selection | `tcd ` | | `` | Open selection in a split | `split ` | | `` | Open selection in a vertical split | `vsplit ` | | `` | Open selection in current window | `edit ` | diff --git a/lua/telescope/_extensions/zoxide/config.lua b/lua/telescope/_extensions/zoxide/config.lua index 1406c97..661faad 100644 --- a/lua/telescope/_extensions/zoxide/config.lua +++ b/lua/telescope/_extensions/zoxide/config.lua @@ -32,7 +32,12 @@ local default_config = { action = function(selection) builtin.find_files({ cwd = selection.path }) end - } + }, + [""] = { + action = function(selection) + vim.cmd.tcd(selection.path) + end + }, } } From 4fd4ae2b88488ec6ccdaadd72a4a3f88e2e3a531 Mon Sep 17 00:00:00 2001 From: Melker Ulander Date: Tue, 7 Feb 2023 17:01:39 +0100 Subject: [PATCH 2/2] refactor: use indexing of vim.cmd Switch to using Lua indexing of `vim.cmd` instead of string concatenation --- README.md | 6 +++--- lua/telescope/_extensions/zoxide/config.lua | 2 +- lua/telescope/_extensions/zoxide/utils.lua | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8742062..4df7f3d 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ require('telescope').setup{ [""] = { before_action = function(selection) print("before C-s") end, action = function(selection) - vim.cmd("edit " .. selection.path) + vim.cmd.edit(selection.path) end }, -- Opens the selected entry in a new split @@ -109,7 +109,7 @@ t.setup({ [""] = { before_action = function(selection) print("before C-s") end, action = function(selection) - vim.cmd("edit " .. selection.path) + vim.cmd.edit(selection.path) end }, [""] = { action = z_utils.create_basic_command("split") }, @@ -136,7 +136,7 @@ vim.keymap.set("n", "cd", t.extensions.zoxide.list) mappings = { default = { action = function(selection) - vim.cmd("cd " .. selection.path) + vim.cmd.edit(selection.path) end, after_action = function(selection) print("Directory changed to " .. selection.path) diff --git a/lua/telescope/_extensions/zoxide/config.lua b/lua/telescope/_extensions/zoxide/config.lua index 661faad..ab54410 100644 --- a/lua/telescope/_extensions/zoxide/config.lua +++ b/lua/telescope/_extensions/zoxide/config.lua @@ -12,7 +12,7 @@ local default_config = { mappings = { default = { action = function(selection) - vim.cmd("cd " .. selection.path) + vim.cmd.cd(selection.path) end, after_action = function(selection) print("Directory changed to " .. selection.path) diff --git a/lua/telescope/_extensions/zoxide/utils.lua b/lua/telescope/_extensions/zoxide/utils.lua index aa0224f..3a24a9e 100644 --- a/lua/telescope/_extensions/zoxide/utils.lua +++ b/lua/telescope/_extensions/zoxide/utils.lua @@ -2,7 +2,7 @@ local utils = {} utils.create_basic_command = function(command) return function(selection) - vim.cmd(command .. " " .. selection.path) + vim.cmd[command](selection.path) end end