From 910ffc7406f5396de9cde7db1fb04f1ceb4e2c05 Mon Sep 17 00:00:00 2001 From: Ivan Elfimov Date: Mon, 5 Jul 2021 01:00:32 +0300 Subject: [PATCH] Add Taskfile initialization command --- CHANGELOG.md | 4 ++++ README.md | 3 +++ Taskfile.py | 18 ++++++++++++++++++ Taskfile.sublime-commands | 3 ++- messages.json | 3 ++- messages/0.4.0.md | 3 +++ pyproject.toml | 2 +- 7 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 messages/0.4.0.md diff --git a/CHANGELOG.md b/CHANGELOG.md index e1b53d2..04e68b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index 5e7616f..b222d48 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ 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 @@ -9,6 +11,7 @@ A Sublime Text 4 plugin for running tasks from [Taskfile](https://taskfile.dev). - 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//Library/Application Support/Sublime Text/Packages/pyyaml/st3/yaml')` ## Installation diff --git a/Taskfile.py b/Taskfile.py index a576373..c65a1f2 100644 --- a/Taskfile.py +++ b/Taskfile.py @@ -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() @@ -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 diff --git a/Taskfile.sublime-commands b/Taskfile.sublime-commands index d081b18..a0f82ae 100644 --- a/Taskfile.sublime-commands +++ b/Taskfile.sublime-commands @@ -1,3 +1,4 @@ [ + {"caption": "Taskfile: Init", "command": "init"}, {"caption": "Taskfile: Run Task", "command": "run_task"} -] \ No newline at end of file +] diff --git a/messages.json b/messages.json index f523e9c..953e598 100644 --- a/messages.json +++ b/messages.json @@ -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" } diff --git a/messages/0.4.0.md b/messages/0.4.0.md new file mode 100644 index 0000000..cd253c1 --- /dev/null +++ b/messages/0.4.0.md @@ -0,0 +1,3 @@ +## v0.4.0 - 2021-07-05 + +- Added `Taskfile: Init` command diff --git a/pyproject.toml b/pyproject.toml index 0b0bfc1..af2bc2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "MIT"