diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33c27d4..f6c1953 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: - name: panvimdoc uses: kdheepak/panvimdoc@main with: - vimdoc: nvim-plugin-template.nvim + vimdoc: QQdock.nvim.nvim treesitter: true - uses: stefanzweifel/git-auto-commit-action@v4 with: @@ -31,3 +31,4 @@ jobs: commit_user_name: "github-actions[bot]" commit_user_email: "github-actions[bot]@users.noreply.github.com" commit_author: "github-actions[bot] " +ub.com>" diff --git a/README.md b/README.md index b548c8d..4e26bce 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,61 @@ -# nvim-plugin-template +# QQdock.nvim -Neovim plugin template; includes automatic documentation generation from README, integration tests with Busted, and linting with Stylua +持久化自适应浮动终端管理器。 -## Usage +每次按 `` 打开 shell,聊完 Reasonix 按 `` 隐藏,再按回来——对话还在。横屏自动右侧分屏,竖屏自动下方分屏。 -1. Click `use this template` button generate a repo on your github. -2. Clone your plugin repo. Open terminal then cd plugin directory. -3. Run `python3 rename.py your-plugin-name`. This will replace all `nvim-plugin-template` to your `plugin-name`. - Then it will prompt you input `y` or `n` to remove example codes in `init.lua` and - `test/plugin_spec.lua`. If you are familiar this repo just input `y`. If you are looking at this template for the first time I suggest you inspect the contents. After this step `rename.py` will also auto-remove. +## 安装 -Now you have a clean plugin environment. Enjoy! +```lua +-- lazy.nvim +{ + 'newbie/QQdock.nvim', + dependencies = { 'akinsho/toggleterm.nvim' }, + config = function() + -- QQdock 无全局配置,直接用 + end, +} +``` -## Format +## 用法 -The CI uses `stylua` to format the code; customize the formatting by editing `.stylua.toml`. +```lua +local Q = require('QQdock') -## Test +Q.shell() -- 普通 shell +Q.open('reasonix') -- Reasonix AI agent +Q.open('lazygit') -- lazygit +Q.open('btm') -- 系统监控 +Q.open('yazi') -- 文件管理器 +``` -See [Running tests locally](https://github.com/nvim-neorocks/nvim-busted-action?tab=readme-ov-file#running-tests-locally) +## 推荐键位 -## CI +```lua +vim.keymap.set({ 'n', 'i' }, '', Q.shell, { noremap = true }) +vim.keymap.set('n', '', function() Q.open('reasonix') end) +vim.keymap.set('n', 'gg', function() Q.open('lazygit') end) +``` -- Auto generates doc from README. -- Runs the [nvim-busted-action](https://github.com/nvim-neorocks/nvim-busted-action) for test. -- Lints with `stylua`. +## API -## More +| 函数 | 参数 | 作用 | +|------|------|------| +| `Q.shell()` | — | 打开/关闭持久 shell | +| `Q.open(cmd)` | cmd | 打开/关闭指定命令的持久终端 | -To see this template in action, take a look at my other plugins. +## 特性 -## License MIT +- **持久化** — toggle 显隐,终端状态保留 +- **自适应** — 横屏右侧 45%,竖屏下方 40% +- **轻量** — 仅依赖 toggleterm.nvim,无其他依赖 + +## TODO + +- [ ] 翻译(trans) +- [ ] 系统监控(btop) +- [ ] 文件管理器(yazi) + +## 协议 + +MIT diff --git a/doc/nvim-plugin-template.nvim.txt b/doc/nvim-plugin-template.nvim.txt deleted file mode 100644 index fc4af21..0000000 --- a/doc/nvim-plugin-template.nvim.txt +++ /dev/null @@ -1,60 +0,0 @@ -*nvim-plugin-template.nvim.txt* For NVIM v0.8.0 Last change: 2025 February 12 - -============================================================================== -Table of Contents *nvim-plugin-template.nvim-table-of-contents* - -1. nvim-plugin-template |nvim-plugin-template.nvim-nvim-plugin-template| - - Usage |nvim-plugin-template.nvim-nvim-plugin-template-usage| - - Format |nvim-plugin-template.nvim-nvim-plugin-template-format| - - Test |nvim-plugin-template.nvim-nvim-plugin-template-test| - - CI |nvim-plugin-template.nvim-nvim-plugin-template-ci| - - More |nvim-plugin-template.nvim-nvim-plugin-template-more| - - License MIT |nvim-plugin-template.nvim-nvim-plugin-template-license-mit| - -============================================================================== -1. nvim-plugin-template *nvim-plugin-template.nvim-nvim-plugin-template* - -Neovim plugin template; includes automatic documentation generation from -README, integration tests with Busted, and linting with Stylua - - -USAGE *nvim-plugin-template.nvim-nvim-plugin-template-usage* - -1. Click `use this template` button generate a repo on your github. -2. Clone your plugin repo. Open terminal then cd plugin directory. -3. Run `python3 rename.py your-plugin-name`. This will replace all `nvim-plugin-template` to your `plugin-name`. -Then it will prompt you input `y` or `n` to remove example codes in `init.lua` and -`test/plugin_spec.lua`. If you are familiar this repo just input `y`. If you are looking at this template for the first time I suggest you inspect the contents. After this step `rename.py` will also auto-remove. - -Now you have a clean plugin environment. Enjoy! - - -FORMAT *nvim-plugin-template.nvim-nvim-plugin-template-format* - -The CI uses `stylua` to format the code; customize the formatting by editing -`.stylua.toml`. - - -TEST *nvim-plugin-template.nvim-nvim-plugin-template-test* - -See Running tests locally - - - -CI *nvim-plugin-template.nvim-nvim-plugin-template-ci* - -- Auto generates doc from README. -- Runs the nvim-busted-action for test. -- Lints with `stylua`. - - -MORE *nvim-plugin-template.nvim-nvim-plugin-template-more* - -To see this template in action, take a look at my other plugins. - - -LICENSE MIT *nvim-plugin-template.nvim-nvim-plugin-template-license-mit* - -Generated by panvimdoc - -vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/lua/QQdock/init.lua b/lua/QQdock/init.lua new file mode 100644 index 0000000..68913ad --- /dev/null +++ b/lua/QQdock/init.lua @@ -0,0 +1,38 @@ +-- QQdock.nvim — Persistent adaptive terminal dock +-- +-- 特性:持久化终端实例、自适应窗口方向(横屏右分屏/竖屏下分屏)、依赖 toggleterm.nvim +-- +-- 用法: +-- local Q = require('QQdock') +-- Q.shell() -- 打开/关闭普通 shell +-- Q.open('reasonix') -- 打开/关闭 Reasonix +-- Q.open('lazygit') -- 打开/关闭 lazygit + +local M = {} + +local terms = {} -- 缓存终端实例,key 是命令名(nil = 普通 shell) + +function M.open(cmd) + local ui = vim.api.nvim_list_uis()[1] + if not ui then + return + end + local tall = ui.height > ui.width + local name = cmd or '__shell__' + + if not terms[name] or not terms[name]:is_open() then + terms[name] = require('toggleterm.terminal').Terminal:new({ + direction = tall and 'horizontal' or 'vertical', + cmd = cmd, + size = tall and math.floor(ui.height * 0.4) or math.floor(ui.width * 0.45), + }) + end + + terms[name]:toggle() +end + +function M.shell() + M.open(nil) +end + +return M diff --git a/lua/nvim-plugin-template/init.lua b/lua/nvim-plugin-template/init.lua deleted file mode 100644 index afa0777..0000000 --- a/lua/nvim-plugin-template/init.lua +++ /dev/null @@ -1,7 +0,0 @@ -local function example() - return true -end - -return { - example = example, -} diff --git a/doc/.gitkeep b/plugin/QQdock.lua similarity index 100% rename from doc/.gitkeep rename to plugin/QQdock.lua diff --git a/plugin/nvim-plugin-template.lua b/plugin/nvim-plugin-template.lua deleted file mode 100644 index e69de29..0000000 diff --git a/rename.py b/rename.py deleted file mode 100644 index 7ad9a36..0000000 --- a/rename.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/python -# -*- coding: UTF-8 -*- - -import os, sys, shutil -pdir = os.getcwd() - -# ANSI color codes -class Colors: - RED = '\033[91m' - GREEN = '\033[92m' - YELLOW = '\033[93m' - BLUE = '\033[94m' - RESET = '\033[0m' - -def print_colored(message, color): - print(color + message + Colors.RESET) - -if len(sys.argv) != 2: - print_colored("plugin name is missing", Colors.RED) - sys.exit(1) - -new_name = sys.argv[1] -for dir in os.listdir(pdir): - if dir == "lua": - os.rename(os.path.join("lua", "nvim-plugin-template"), os.path.join("lua",new_name)) - print_colored("Renamed files under lua folder successed", Colors.GREEN) - if dir == "plugin": - os.rename(os.path.join("plugin", "nvim-plugin-template.lua"), - os.path.join("plugin",new_name + ".lua")) - print_colored("Renamed files under plugin folder successed", Colors.GREEN) - if dir == 'doc': - os.rename(os.path.join("doc", "nvim-plugin-template.nvim.txt"), - os.path.join("doc",new_name + ".txt")) - print_colored("Renamed files under doc folder successed", Colors.GREEN) - if dir == '.github': - with open(os.path.join(".github","workflows","ci.yml"), 'r+') as f: - d = f.read() - t = d.replace('nvim-plugin-template', new_name) - f.seek(0, 0) - f.write(t) - print_colored("Ci yaml has been updated", Colors.GREEN) - -choice = input("Do you need plugin folder in your plugin (y|n): ") -if choice.lower() == 'n': - shutil.rmtree(os.path.join(os.getcwd(), 'plugin')) - -choice = input("Do you want also remove example code in init.lua and test (y|n): ") -if choice.lower() == 'y': - with open(os.path.join(pdir, 'lua',new_name,'init.lua'), 'w') as f: - f.truncate() - - with open(os.path.join(pdir, 'test','plugin_spec.lua'), 'w') as f: - f.truncate() - -os.remove(os.path.join(os.getcwd(), 'rename.py')) -print_colored("All works done enjoy", Colors.YELLOW) diff --git a/test/plugin_spec.lua b/test/plugin_spec.lua deleted file mode 100644 index 4f1ef32..0000000 --- a/test/plugin_spec.lua +++ /dev/null @@ -1,8 +0,0 @@ -local example = require('nvim-plugin-template').example - -describe('neovim plugin', function() - it('work as expect', function() - local result = example() - assert.is_true(result) - end) -end)