Skip to content

Commit d5fd47a

Browse files
authored
Merge pull request #17 from erichlf/nvim-server-for-connect
Open NVIM immediately and eliminate extra script
2 parents a8a56de + 2f18cf3 commit d5fd47a

File tree

7 files changed

+207
-232
lines changed

7 files changed

+207
-232
lines changed

bin/connect_to_devcontainer.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

bin/open_shell_in_devcontainer.sh

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,22 @@ local default_config = {
3535
dotfiles_repository = "git@github.com:erichlf/dotfiles",
3636
-- branch to checkout for repositories (this is a feature not supported by
3737
-- devcontainers in general, but we do)
38-
dotfiles_repository = "devcontainer",
38+
dotfiles_branch = "main",
3939
-- directory for the setup environment
4040
dotfiles_targetPath = "~/dotfiles",
4141
-- command that's executed for installed the dependencies from the
4242
-- setup_environment_repo
4343
dotfiles_installCommand = "install.sh",
4444
-- The number of columns to wrap text at
4545
terminal_columns = 80,
46+
-- The particular binary to use for connecting to in the devcontainer
47+
-- Most likely this should remain nvim
48+
nvim_binary = "nvim",
4649
-- The shell to use for executing command. Available sh, bash, zsh or any
4750
-- other that uses '-c' to signify a command is to follow
4851
shell = 'bash',
52+
-- The name of the socket file to use
53+
port = "7777",
4954
}
5055

5156
local options

lua/devcontainer-cli/devcontainer_cli.lua

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,27 @@
11
-- Copyright (c) 2024 Erich L Foster
2-
--
2+
--
33
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
44
-- this software and associated documentation files (the "Software"), to deal in
55
-- the Software without restriction, including without limitation the rights to
66
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
77
-- of the Software, and to permit persons to whom the Software is furnished to do
88
-- so, subject to the following conditions:
9-
--
9+
--
1010
-- The above copyright notice and this permission notice shall be included in all
1111
-- copies or substantial portions of the Software.
12-
--
12+
--
1313
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1414
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1515
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1616
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1717
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
-- SOFTWARE.
20-
21-
local config = require("devcontainer-cli.config")
2220
local utils = require("devcontainer-cli.devcontainer_utils")
21+
local terminal = require("devcontainer-cli.terminal")
2322

2423
local M = {}
2524

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-
4425
-- executes a given command in the devcontainer of the current project directory
4526
---@param opts (table) options for executing the command
4627
function M.exec(opts)
@@ -71,7 +52,7 @@ end
7152

7253
-- toggle the current devcontainer window
7354
function M.toggle()
74-
utils.toggle()
55+
terminal.toggle()
7556
end
7657

7758
-- bring up the devcontainer in the current project directory
@@ -82,7 +63,11 @@ end
8263
-- Thanks to the autocommand executed after leaving the UI, after closing the
8364
-- neovim window the devcontainer will be automatically open in a new terminal
8465
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+
8671
vim.cmd("wqa")
8772
end
8873

0 commit comments

Comments
 (0)