Skip to content

Commit e96ca6f

Browse files
committed
Add config keys to set custom permission for files and folders
Add config key to set the file creation permissions Rename file_mode to new_file_mode Add new_folder_mode to store the default folder creation mode Remove doc about new_file_mode Fix how the folder and file mode are added to config
1 parent dba0375 commit e96ca6f

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

doc/oil.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ CONFIG *oil-confi
4545
},
4646
-- Send deleted files to the trash instead of permanently deleting them (:help oil-trash)
4747
delete_to_trash = false,
48+
-- Set the default mode to create files (:help oil-file_creation)
49+
create_files_mode = 420,
4850
-- Skip the confirmation popup for simple operations (:help oil.skip_confirm_for_simple_edits)
4951
skip_confirm_for_simple_edits = false,
5052
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
@@ -714,5 +716,6 @@ Mac:
714716
Windows:
715717
Oil supports the Windows Recycle Bin. All features should work.
716718

719+
717720
================================================================================
718721
vim:tw=80:ts=2:ft=help:norl:syntax=help:

lua/oil/adapters/files.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ M.perform_action = function(action, cb)
530530
end
531531

532532
if action.entry_type == "directory" then
533-
uv.fs_mkdir(path, 493, function(err)
533+
uv.fs_mkdir(path, config.new_folder_mode, function(err)
534534
-- Ignore if the directory already exists
535535
if not err or err:match("^EEXIST:") then
536536
cb()
@@ -550,7 +550,7 @@ M.perform_action = function(action, cb)
550550
---@diagnostic disable-next-line: param-type-mismatch
551551
uv.fs_symlink(target, path, flags, cb)
552552
else
553-
fs.touch(path, cb)
553+
fs.touch(path, config.new_file_mode, cb)
554554
end
555555
elseif action.type == "delete" then
556556
local _, path = util.parse_url(action.url)

lua/oil/adapters/trash/mac.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ M.perform_action = function(action, cb)
166166
---@diagnostic disable-next-line: param-type-mismatch
167167
uv.fs_symlink(target, path, flags, cb)
168168
else
169-
fs.touch(path, cb)
169+
fs.touch(path, config.new_file_mode, cb)
170170
end
171171
elseif action.type == "delete" then
172172
local _, path = util.parse_url(action.url)

lua/oil/config.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ local default_config = {
105105
return nil
106106
end,
107107
},
108+
-- Set the default mode to create files
109+
new_file_mode = 644,
110+
-- Set the default mode to create folders
111+
new_folder_mode = 755,
108112
-- Extra arguments to pass to SCP when moving/copying files over SSH
109113
extra_scp_args = {},
110114
-- EXPERIMENTAL support for performing file operations with git
@@ -232,6 +236,8 @@ default_config.view_options.highlight_filename = nil
232236
---@field keymaps table<string, any>
233237
---@field use_default_keymaps boolean
234238
---@field view_options oil.ViewOptions
239+
---@field new_file_mode integer
240+
---@field new_folder_mode integer
235241
---@field extra_scp_args string[]
236242
---@field git oil.GitOptions
237243
---@field float oil.FloatWindowConfig
@@ -260,6 +266,8 @@ local M = {}
260266
---@field keymaps? table<string, any>
261267
---@field use_default_keymaps? boolean Set to false to disable all of the above keymaps
262268
---@field view_options? oil.SetupViewOptions Configure which files are shown and how they are shown.
269+
---@field new_file_mode? integer Set the default mode to create files
270+
---@field new_folder_mode? integer Set the default mode to create folders
263271
---@field extra_scp_args? string[] Extra arguments to pass to SCP when moving/copying files over SSH
264272
---@field git? oil.SetupGitOptions EXPERIMENTAL support for performing file operations with git
265273
---@field float? oil.SetupFloatWindowConfig Configuration for the floating window in oil.open_float
@@ -408,6 +416,9 @@ M.setup = function(opts)
408416
if opts.preview and not opts.confirmation then
409417
new_conf.confirmation = vim.tbl_deep_extend("keep", opts.preview, default_config.confirmation)
410418
end
419+
420+
new_conf.new_file_mode = tonumber(tostring(new_conf.new_file_mode), 8)
421+
new_conf.new_folder_mode = tonumber(tostring(new_conf.new_folder_mode), 8)
411422
-- Backwards compatibility. We renamed the 'preview' config to 'preview_win'
412423
if opts.preview and opts.preview.update_on_cursor_moved ~= nil then
413424
new_conf.preview_win.update_on_cursor_moved = opts.preview.update_on_cursor_moved

lua/oil/fs.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ M.abspath = function(path)
3636
end
3737

3838
---@param path string
39+
---@param mode integer mode to open file (octal)
3940
---@param cb fun(err: nil|string)
40-
M.touch = function(path, cb)
41-
uv.fs_open(path, "a", 420, function(err, fd) -- 0644
41+
M.touch = function(path, mode, cb)
42+
uv.fs_open(path, "a", mode, function(err, fd)
4243
if err then
4344
cb(err)
4445
else
@@ -146,7 +147,6 @@ end
146147
---@param dir string
147148
---@param mode? integer
148149
M.mkdirp = function(dir, mode)
149-
mode = mode or 493
150150
local mod = ""
151151
local path = dir
152152
while vim.fn.isdirectory(path) == 0 do

0 commit comments

Comments
 (0)