-
Notifications
You must be signed in to change notification settings - Fork 8
Custom Actions
TheBlob42 edited this page Mar 19, 2022
·
6 revisions
- use
<CR>
on a closed directory to open it - use
<CR>
on an open directory to close it - use
<CR>
on a file to open it
require('drex.config').configure {
keybindings = {
['n'] = {
['<CR>'] = function()
local drex = require('drex')
local line = vim.api.nvim_get_current_line()
if require('drex.utils').is_open_directory(line) then
drex.collapse_directory()
else
drex.expand_element()
end
end
}
}
}
This example uses trash-cli but you can use whatever command you prefer
require('drex.config').configure {
keybindings = {
['n'] = {
['t'] = function()
local line = vim.api.nvim_get_current_line()
local element = require('drex.utils').get_element(line)
vim.fn.jobstart("trash-put '" .. element .. "' &", { detach = true })
end
}
}
}
This example only works on Linux with xdg-open
available on the PATH
Check out
start
for Windows andopen
for MacOS as an alternative
require('drex.config').configure {
keybindings = {
['n'] = {
['X'] = function()
local line = vim.api.nvim_get_current_line()
local element = require('drex.utils').get_element(line)
vim.fn.jobstart("xdg-open '" .. element .. "' &", { detach = true })
end
}
}
}
Expand or collapse (recursively) all directories of the current DREX buffer
config.configure {
keybindings = {
['n'] = {
-- expand every directory in the current buffer
['O'] = function()
local row = 1
while true do
local line = vim.api.nvim_buf_get_lines(0, row - 1, row, false)[1]
if utils.is_closed_directory(line) then
drex.expand_element(0, row)
end
row = row + 1
if row > vim.fn.line('$') then
break
end
end
end,
-- collapse every directory in the current buffer
['C'] = function()
local row = 1
while true do
local line = vim.api.nvim_buf_get_lines(0, row - 1, row, false)[1]
if utils.is_open_directory(line) then
drex.collapse_directory(0, row)
end
row = row + 1
if row > vim.fn.line('$') then
break
end
end
end,
},
},
}