diff --git a/doc/oil.txt b/doc/oil.txt index 8540cbd1..bd259400 100644 --- a/doc/oil.txt +++ b/doc/oil.txt @@ -122,6 +122,10 @@ CONFIG *oil-confi return nil end, }, + -- Set the default mode to create files + new_files_mode = 644, + -- Set the default mode to create folders + new_folder_mode = 755, -- Extra arguments to pass to SCP when moving/copying files over SSH extra_scp_args = {}, -- EXPERIMENTAL support for performing file operations with git diff --git a/lua/oil/adapters/files.lua b/lua/oil/adapters/files.lua index 593cfcec..38b9119e 100644 --- a/lua/oil/adapters/files.lua +++ b/lua/oil/adapters/files.lua @@ -530,7 +530,7 @@ M.perform_action = function(action, cb) end if action.entry_type == "directory" then - uv.fs_mkdir(path, 493, function(err) + uv.fs_mkdir(path, config.new_folder_mode, function(err) -- Ignore if the directory already exists if not err or err:match("^EEXIST:") then cb() @@ -550,7 +550,7 @@ M.perform_action = function(action, cb) ---@diagnostic disable-next-line: param-type-mismatch uv.fs_symlink(target, path, flags, cb) else - fs.touch(path, cb) + fs.touch(path, config.new_file_mode, cb) end elseif action.type == "delete" then local _, path = util.parse_url(action.url) diff --git a/lua/oil/adapters/trash/mac.lua b/lua/oil/adapters/trash/mac.lua index 8b2d33a3..6674bb26 100644 --- a/lua/oil/adapters/trash/mac.lua +++ b/lua/oil/adapters/trash/mac.lua @@ -166,7 +166,7 @@ M.perform_action = function(action, cb) ---@diagnostic disable-next-line: param-type-mismatch uv.fs_symlink(target, path, flags, cb) else - fs.touch(path, cb) + fs.touch(path, config.new_file_mode, cb) end elseif action.type == "delete" then local _, path = util.parse_url(action.url) diff --git a/lua/oil/config.lua b/lua/oil/config.lua index 9102727d..5e06cb16 100644 --- a/lua/oil/config.lua +++ b/lua/oil/config.lua @@ -105,6 +105,10 @@ local default_config = { return nil end, }, + -- Set the default mode to create files + new_file_mode = 644, + -- Set the default mode to create folders + new_folder_mode = 755, -- Extra arguments to pass to SCP when moving/copying files over SSH extra_scp_args = {}, -- EXPERIMENTAL support for performing file operations with git @@ -232,6 +236,8 @@ default_config.view_options.highlight_filename = nil ---@field keymaps table ---@field use_default_keymaps boolean ---@field view_options oil.ViewOptions +---@field new_file_mode integer +---@field new_folder_mode integer ---@field extra_scp_args string[] ---@field git oil.GitOptions ---@field float oil.FloatWindowConfig @@ -260,6 +266,8 @@ local M = {} ---@field keymaps? table ---@field use_default_keymaps? boolean Set to false to disable all of the above keymaps ---@field view_options? oil.SetupViewOptions Configure which files are shown and how they are shown. +---@field new_file_mode? integer Set the default mode to create files +---@field new_folder_mode? integer Set the default mode to create folders ---@field extra_scp_args? string[] Extra arguments to pass to SCP when moving/copying files over SSH ---@field git? oil.SetupGitOptions EXPERIMENTAL support for performing file operations with git ---@field float? oil.SetupFloatWindowConfig Configuration for the floating window in oil.open_float @@ -408,6 +416,9 @@ M.setup = function(opts) if opts.preview and not opts.confirmation then new_conf.confirmation = vim.tbl_deep_extend("keep", opts.preview, default_config.confirmation) end + + new_conf.new_file_mode = tonumber(tostring(new_conf.new_file_mode), 8) + new_conf.new_folder_mode = tonumber(tostring(new_conf.new_folder_mode), 8) -- Backwards compatibility. We renamed the 'preview' config to 'preview_win' if opts.preview and opts.preview.update_on_cursor_moved ~= nil then new_conf.preview_win.update_on_cursor_moved = opts.preview.update_on_cursor_moved diff --git a/lua/oil/fs.lua b/lua/oil/fs.lua index ac216a18..f6b82981 100644 --- a/lua/oil/fs.lua +++ b/lua/oil/fs.lua @@ -36,9 +36,10 @@ M.abspath = function(path) end ---@param path string +---@param mode integer mode to open file (octal) ---@param cb fun(err: nil|string) -M.touch = function(path, cb) - uv.fs_open(path, "a", 420, function(err, fd) -- 0644 +M.touch = function(path, mode, cb) + uv.fs_open(path, "a", mode, function(err, fd) if err then cb(err) else @@ -146,7 +147,6 @@ end ---@param dir string ---@param mode? integer M.mkdirp = function(dir, mode) - mode = mode or 493 local mod = "" local path = dir while vim.fn.isdirectory(path) == 0 do