diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..0dae42c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,29 @@ +name: Linting and style checking + +on: [push, pull_request] + +jobs: + luacheck: + name: Luacheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Prepare + run: | + sudo apt update + sudo apt install -y luarocks + sudo luarocks install luacheck + + - name: Lint + run: sudo make lint + + stylua: + name: stylua + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: JohnnyMorganz/stylua-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --color always --check lua/ diff --git a/.gitignore b/.gitignore index 6fd0a37..fdfe930 100644 --- a/.gitignore +++ b/.gitignore @@ -1,41 +1,4 @@ -# Compiled Lua sources -luac.out - -# luarocks build files -*.src.rock -*.zip -*.tar.gz - -# Object files -*.o -*.os -*.ko -*.obj -*.elf - -# Precompiled Headers -*.gch -*.pch - -# Libraries -*.lib -*.a -*.la -*.lo -*.def -*.exp - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - +doc/tags +.luacheckcache +.luarc.json +*.DS_Store diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..45dc363 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,22 @@ +-- Rerun tests only if their modification time changed. +cache = true + +std = luajit +codes = true + +self = false + +-- Glorious list of warnings: https://luacheck.readthedocs.io/en/stable/warnings.html +ignore = { + --[[ + Unused argument, In the case of callback function, + _arg_name is easier to understand than _, + so this option is set to off. + ]] + '212', +} + +-- Global objects defined by the C code +read_globals = { + 'vim', +} diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..6cdf94f --- /dev/null +++ b/.stylua.toml @@ -0,0 +1,6 @@ +column_width = 78 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferSingle" +no_call_parentheses = false diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..085dfd6 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +lint: + luacheck lua diff --git a/README.md b/README.md index 52c8f04..618c833 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,36 @@ # vfiler-action-yanktree -The yanktree action extension plugin for vfiler.vim. + +This project is an extension plugin for `vfiler.vim` that provides the functionality to copy the filesystem tree structure to the clipboard. This plugin uses the `tree` command internally, so the `tree` command is necessary. + +## Prerequisites + +- Linux or macOS +- `tree` command installed + +## Installation + +Use your favorite plugin manager to install `vfiler-action-yanktree`. For example, if you are using [vim-plug](https://github.com/junegunn/vim-plug), follow the steps below. + +```vim +Plug 'your-github-username/vfiler-action-yanktree' +``` + +## Configuration + +After installation, to configure this plugin as an action in `vfiler.vim`, map the action to your preferred key as shown below. + +```vim +let g:vfiler_config = { +\ 'mappings': { +\ 'your-preferred-key': 'YankTree', +\ } +\} +``` + +## Usage + +Press the configured key to fetch the current directory structure using the `tree` command and copy it to the clipboard. This allows you to easily paste it into other applications. + +## License + +This project is released under the [MIT License](LICENSE). diff --git a/lua/vfiler/actions/yanktree.lua b/lua/vfiler/actions/yanktree.lua new file mode 100644 index 0000000..8f8d1b8 --- /dev/null +++ b/lua/vfiler/actions/yanktree.lua @@ -0,0 +1,65 @@ +local vim = require('vfiler/libs/vim') +local clipboard = require('vfiler/clipboard') +local core = require('vfiler/libs/core') + +local M = {} + +-- Default configs +M.configs = { + directories_only = false, + options_extened = '', +} + +local function system(dirpath) + local commands = { 'tree' } + if core.is_windows then + if not M.configs.directories_only then + table.insert(commands, '/f') + end + else + if M.configs.directories_only then + table.insert(commands, '-d') + end + end + if #M.configs.options_extened > 0 then + table.insert(commands, M.configs.options_extened) + end + table.insert(commands, ('"%s"'):format(dirpath)) + return core.system(table.concat(commands, ' ')) +end + +function M.yank_tree_root(vfiler, context, view) + if vim.fn.executable('tree') ~= 1 then + core.message.warning("The 'tree' command is requrired to run this.") + return + end + local path = context.root.path + clipboard.yank(system(path)) + core.message.info('Yanked "%s" tree', path) +end + +function M.yank_tree(vfiler, context, view) + if vim.fn.executable('tree') ~= 1 then + core.message.warning("The 'tree' command is requrired to run this.") + return + end + local item = view:get_item() + if not item then + return + end + local path = item.path + if not core.path.is_directory(path) then + path = item.parent.path + end + clipboard.yank(system(path)) + core.message.info('Yanked "%s" tree', path) +end + +--- Setup configs +---@param configs table +function M.setup(configs) + core.table.merge(M.configs, configs) + return M.configs +end + +return M