|
1 | 1 | -- Copyright (c) 2024 Erich L Foster |
2 | | --- |
| 2 | +-- |
3 | 3 | -- Permission is hereby granted, free of charge, to any person obtaining a copy of |
4 | 4 | -- this software and associated documentation files (the "Software"), to deal in |
5 | 5 | -- the Software without restriction, including without limitation the rights to |
6 | 6 | -- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
7 | 7 | -- of the Software, and to permit persons to whom the Software is furnished to do |
8 | 8 | -- so, subject to the following conditions: |
9 | | --- |
| 9 | +-- |
10 | 10 | -- The above copyright notice and this permission notice shall be included in all |
11 | 11 | -- copies or substantial portions of the Software. |
12 | | --- |
| 12 | +-- |
13 | 13 | -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
14 | 14 | -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
15 | 15 | -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
16 | 16 | -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
17 | 17 | -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
18 | 18 | -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
19 | 19 | -- SOFTWARE. |
20 | | - |
21 | | -local config = require("devcontainer-cli.config") |
22 | 20 | local utils = require("devcontainer-cli.devcontainer_utils") |
| 21 | +local terminal = require("devcontainer-cli.terminal") |
23 | 22 |
|
24 | 23 | local M = {} |
25 | 24 |
|
26 | | -local function define_autocommands() |
27 | | - local au_id = vim.api.nvim_create_augroup("devcontainer.docker.terminal", {}) |
28 | | - vim.api.nvim_create_autocmd("UILeave", { |
29 | | - group = au_id, |
30 | | - callback = function() |
31 | | - -- It connects with the Devcontainer just after quiting neovim. |
32 | | - -- TODO: checks that the devcontainer is not already connected |
33 | | - -- TODO: checks that there is a devcontainer running |
34 | | - vim.schedule( |
35 | | - function() |
36 | | - local command = config.nvim_plugin_folder .. "/bin/connect_to_devcontainer.sh" |
37 | | - vim.fn.jobstart(command, { detach = true }) |
38 | | - end |
39 | | - ) |
40 | | - end, |
41 | | - }) |
42 | | -end |
43 | | - |
44 | 25 | -- executes a given command in the devcontainer of the current project directory |
45 | 26 | ---@param opts (table) options for executing the command |
46 | 27 | function M.exec(opts) |
|
71 | 52 |
|
72 | 53 | -- toggle the current devcontainer window |
73 | 54 | function M.toggle() |
74 | | - utils.toggle() |
| 55 | + terminal.toggle() |
75 | 56 | end |
76 | 57 |
|
77 | 58 | -- bring up the devcontainer in the current project directory |
|
82 | 63 | -- Thanks to the autocommand executed after leaving the UI, after closing the |
83 | 64 | -- neovim window the devcontainer will be automatically open in a new terminal |
84 | 65 | function M.connect() |
85 | | - define_autocommands() |
| 66 | + if not utils.create_connect_cmd() then |
| 67 | + vim.notify("Failed to create autocommand", vim.log.levels.ERROR) |
| 68 | + return |
| 69 | + end |
| 70 | + |
86 | 71 | vim.cmd("wqa") |
87 | 72 | end |
88 | 73 |
|
|
0 commit comments