Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ require("dired").setup({
show_banner = false, -- Do not show the banner
hide_details = false, -- Show file details by default
sort_order = "name", -- Sort files by name by default
override_cwd = true, -- Override cwd by default

-- Define keybindings for various 'dired' actions
keybinds = {
Expand Down
1 change: 1 addition & 0 deletions doc/dired.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ You can require this plugin and use it like this.
hide_details = false, -- Show file details by default
sort_order = "name", -- Sort files by name by default

override_cwd = true, -- Override cwd by default
-- Define keybindings for various 'dired' actions
keybinds = {
dired_enter = "<CR>",
Expand Down
8 changes: 8 additions & 0 deletions lua/dired/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ local CONFIG_SPEC = {
end
end,
},
override_cwd = {
default = true,
check = function (val)
if type(val) ~= "boolean" then
return "Must be boolean, instead received " .. type(val)
end
end
},
-- control mouse/preview UX
enable_click_preview = {
-- highlights the current line on single left-click
Expand Down
12 changes: 10 additions & 2 deletions lua/dired/dired.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,22 @@ function M.init_dired()
if fs.is_directory(path) ~= true then
path = fs.get_parent_path(path)
end
vim.api.nvim_set_current_dir(path)

if vim.g.dired_override_cwd then
vim.api.nvim_set_current_dir(path)
end

display.render(path)
end

-- open a new directory
function M.open_dir(path)
if path == "" then
path = "."
if vim.g.dired_override_cwd then
path = "."
else
path = vim.fn.fnamemodify(vim.fn.expand("%"), ":p"):gsub("\\", "/")
end
end

path = fs.get_simplified_path(fs.get_absolute_path(path))
Expand Down
7 changes: 7 additions & 0 deletions lua/dired/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ function M.setup(opts)
vim.g.dired_sort_order = config.get("sort_order")
end

if config.get("override_cwd") == nil then
-- Default: true (do override user's cwd)
vim.g.dired_override_cwd = true
else
vim.g.dired_override_cwd = config.get("override_cwd")
end

vim.cmd([[command! -nargs=? -complete=dir Dired lua require'dired'.open(<q-args>)]])
vim.cmd([[command! -nargs=? -complete=file DiredRename lua require'dired'.rename(<q-args>)]])
vim.cmd([[command! -nargs=? -complete=file DiredDelete lua require'dired'.delete(<q-args>)]])
Expand Down