Skip to content

Commit

Permalink
Add Taskfile initialization command
Browse files Browse the repository at this point in the history
  • Loading branch information
biozz committed Jul 4, 2021
1 parent 352d239 commit 910ffc7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.4.0 - 2021-07-05

- Add `Taskfile: Init` command

## v0.3.4 - 2021-07-04

- Remove `.python-version` from my global `.gitignore` to fix the issue when plugin picked up wrong python version (3.3 instead of 3.8)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

A Sublime Text 4 plugin for running tasks from [Taskfile](https://taskfile.dev). It adds `Taskfile: Run Task` to your command palette and you can select which task to run. The output of the task is than displayed in the quick panel on the bottom.

It is also possible to initialize the `Taskfile` with `Taskfile: Init` command, which basically does `task -i` in one of the project directories you chose.

![Usage](Usage.gif)

## Caveats

- made for Sublime Text 4
- uses [Sublime's python version 3.8](https://www.sublimetext.com/docs/api_environments.html#selecting_python_version)
- uses [`pyyaml`](https://github.com/packagecontrol/pyyaml) dependency
- as a result of the above dependency local development can be difficult, but you can try executing `sys.path.append('/Users/<user>/Library/Application Support/Sublime Text/Packages/pyyaml/st3/yaml')`

## Installation

Expand Down
18 changes: 18 additions & 0 deletions Taskfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
import yaml


class InitCommand(sublime_plugin.WindowCommand):
def run(self):
folders = self.window.folders()
if not folders:
self.window.status_message("You have to be in a directory for init to work")
return
# TODO: check if Taskfile has been initialized already and filter out these folders
if len(folders) > 1:
on_done = partial(initialize_taskfile, self.window, folders)
self.window.show_quick_panel(folders, on_done)


class RunTaskCommand(sublime_plugin.WindowCommand):
def run(self):
folders = self.window.folders()
Expand All @@ -20,6 +32,12 @@ def run(self):
self.window.show_quick_panel(items, on_done, sublime.MONOSPACE_FONT)


def initialize_taskfile(window, quick_panel_items, index):
window.run_command(
"exec", args={"shell_cmd": f"task -i", "working_dir": quick_panel_items[index]}
)


def run_task_by_index(window, quick_panel_items, working_dir, index):
if index < 0:
return
Expand Down
3 changes: 2 additions & 1 deletion Taskfile.sublime-commands
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[
{"caption": "Taskfile: Init", "command": "init"},
{"caption": "Taskfile: Run Task", "command": "run_task"}
]
]
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"0.1.0": "messages/0.1.0.md",
"0.1.1": "messages/0.1.1.md",
"0.2.0": "messages/0.2.0.md",
"0.3.0": "messages/0.3.0.md"
"0.3.0": "messages/0.3.0.md",
"0.4.0": "messages/0.4.0.md"
}
3 changes: 3 additions & 0 deletions messages/0.4.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## v0.4.0 - 2021-07-05

- Added `Taskfile: Init` command
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sublime-taskfile"
version = "0.3.4"
version = "0.4.0"
description = "A Sublime Text 4 plugin for running Taskfile tasks"
authors = ["Ivan Elfimov <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 910ffc7

Please sign in to comment.