Skip to content

Custom Actions

TheBlob42 edited this page Jan 25, 2022 · 6 revisions

<CR> to toggle directories and open files

  • 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
        }
    }
}

Trash element

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
        }
    }
}

Open element with system default application

This example only works on Linux with xdg-open available on the PATH

Check out start for Windows and open 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
        }
    }
}
Clone this wiki locally