Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
obaland committed May 11, 2024
1 parent c6fbdfe commit 73d1267
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 42 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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/
45 changes: 4 additions & 41 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -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',
}
6 changes: 6 additions & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
column_width = 78
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferSingle"
no_call_parentheses = false
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lint:
luacheck lua
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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).
65 changes: 65 additions & 0 deletions lua/vfiler/actions/yanktree.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 73d1267

Please sign in to comment.