Skip to content

Commit 285f8d5

Browse files
committed
feat: add picker.nvim source
1 parent aea0284 commit 285f8d5

File tree

2 files changed

+102
-17
lines changed

2 files changed

+102
-17
lines changed

README.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ It is inspired by VSCode's tasks-manager.
77

88
<!-- vim-markdown-toc GFM -->
99

10-
* [Install](#install)
11-
* [Setup](#setup)
12-
* [Usage](#usage)
13-
* [Commands](#commands)
14-
* [Custom tasks](#custom-tasks)
15-
* [Task Problems Matcher](#task-problems-matcher)
16-
* [Task auto-detection](#task-auto-detection)
17-
* [Task provider](#task-provider)
18-
* [Debug](#debug)
19-
* [Self-Promotion](#self-promotion)
20-
* [License](#license)
10+
- [Install](#install)
11+
- [Setup](#setup)
12+
- [Usage](#usage)
13+
- [Commands](#commands)
14+
- [Telescope extension](#telescope-extension)
15+
- [picker.nvim extension](#pickernvim-extension)
16+
- [Custom tasks](#custom-tasks)
17+
- [Task Problems Matcher](#task-problems-matcher)
18+
- [Task auto-detection](#task-auto-detection)
19+
- [Task provider](#task-provider)
20+
- [Debug](#debug)
21+
- [Self-Promotion](#self-promotion)
22+
- [License](#license)
2123

2224
<!-- vim-markdown-toc -->
2325

@@ -60,19 +62,28 @@ require('tasks').setup({
6062

6163
### Commands
6264

63-
| Key Bindings | Descriptions |
64-
| ------------------ | ----------------------------------------------------------------------- |
65-
| `:TasksList` | list all available tasks |
66-
| `:TasksEdit` | open local tasks configuration file, use `:TasksEdit!` for global tasks |
67-
| `:TaskSelect` | select task to run |
68-
| `:Telescope tasks` | fuzzy find tasks(require `telescope.nvim`) |
65+
| Key Bindings | Descriptions |
66+
| ------------- | ----------------------------------------------------------------------- |
67+
| `:TasksList` | list all available tasks |
68+
| `:TasksEdit` | open local tasks configuration file, use `:TasksEdit!` for global tasks |
69+
| `:TaskSelect` | select task to run |
6970

7071
`:TasksList` will open the tasks manager windows, in the tasks manager windows, you can use `Enter` to run task under the cursor.
7172

73+
### Telescope extension
74+
7275
If `telescope.nvim` is installed, you can also use `:Telescope tasks` to fuzzy find specific task, and run the select task.
7376

7477
![fuzzy-task](https://img.spacevim.org/199057483-d5cce17c-2f06-436d-bf7d-24a78d0eeb11.png)
7578

79+
### picker.nvim extension
80+
81+
This plugin also provides a source for [picker.nvim](https://github.com/wsdjeg/picker.nvim).
82+
83+
```
84+
:Picker tasks
85+
```
86+
7687
### Custom tasks
7788

7889
This is a basic task configuration for running `echo hello world`,
@@ -272,3 +283,4 @@ Love this plugin? Follow [me](https://wsdjeg.net/) on
272283
## License
273284

274285
This project is licensed under the GPL-3.0 License.
286+
This project is licensed under the GPL-3.0 License.

lua/picker/sources/tasks.lua

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
local M = {}
2+
local taskmanager = require('tasks')
3+
4+
local widths = {
5+
{ width = 25 },
6+
{ width = 10 },
7+
{ width = 15 },
8+
}
9+
10+
function M.get()
11+
local items = {}
12+
13+
for k, v in pairs(taskmanager.get_tasks()) do
14+
local desc = v.description
15+
if desc == nil then
16+
desc = v.command
17+
if v.args ~= nil then
18+
desc = desc .. ' ' .. table.concat(v.args, ' ')
19+
end
20+
end
21+
local task_name = k
22+
local task_type = 'local'
23+
if v.isGlobal == 1 then
24+
task_type = 'global'
25+
elseif v.isDetected == 1 then
26+
task_type = 'detected'
27+
task_name = (v.detectedName or '') .. task_name
28+
end
29+
local background = 'no-background'
30+
if v.isBackground then
31+
background = 'background'
32+
end
33+
local str = string.format(
34+
'[%s] %s [%s] %s [%s] %s %s',
35+
task_name,
36+
string.rep(' ', widths[1].width - #task_name - 3),
37+
task_type,
38+
string.rep(' ', widths[2].width - #task_type - 3),
39+
background,
40+
task_type,
41+
string.rep(' ', widths[3].width - #background - 3),
42+
desc
43+
)
44+
table.insert(items, {
45+
value = v,
46+
str = str,
47+
highlight = {
48+
{ 0, widths[1].width, 'String' },
49+
{ widths[1].width, widths[1].width + widths[2].width, 'Tag' },
50+
{
51+
widths[1].width + widths[2].width,
52+
widths[1].width + widths[2].width + widths[3].width + 2,
53+
'Number',
54+
},
55+
{
56+
widths[1].width + widths[2].width + widths[3].width + 2,
57+
#str,
58+
'Comment',
59+
},
60+
},
61+
})
62+
end
63+
return items
64+
end
65+
66+
function M.default_action(entry)
67+
local ok, runner = pcall(require, 'code-runner')
68+
if ok then
69+
runner.run_task(taskmanager.expand_task(entry.value))
70+
end
71+
end
72+
73+
return M

0 commit comments

Comments
 (0)