Skip to content

Commit

Permalink
Merge pull request #17 from erichlf/nvim-server-for-connect
Browse files Browse the repository at this point in the history
Open NVIM immediately and eliminate extra script
  • Loading branch information
erichlf authored May 31, 2024
2 parents a8a56de + 2f18cf3 commit d5fd47a
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 232 deletions.
42 changes: 0 additions & 42 deletions bin/connect_to_devcontainer.sh

This file was deleted.

34 changes: 0 additions & 34 deletions bin/open_shell_in_devcontainer.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,22 @@ local default_config = {
dotfiles_repository = "[email protected]:erichlf/dotfiles",
-- branch to checkout for repositories (this is a feature not supported by
-- devcontainers in general, but we do)
dotfiles_repository = "devcontainer",
dotfiles_branch = "main",
-- directory for the setup environment
dotfiles_targetPath = "~/dotfiles",
-- command that's executed for installed the dependencies from the
-- setup_environment_repo
dotfiles_installCommand = "install.sh",
-- The number of columns to wrap text at
terminal_columns = 80,
-- The particular binary to use for connecting to in the devcontainer
-- Most likely this should remain nvim
nvim_binary = "nvim",
-- The shell to use for executing command. Available sh, bash, zsh or any
-- other that uses '-c' to signify a command is to follow
shell = 'bash',
-- The name of the socket file to use
port = "7777",
}

local options
Expand Down
35 changes: 10 additions & 25 deletions lua/devcontainer-cli/devcontainer_cli.lua
Original file line number Diff line number Diff line change
@@ -1,46 +1,27 @@
-- Copyright (c) 2024 Erich L Foster
--
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in
-- the Software without restriction, including without limitation the rights to
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-- of the Software, and to permit persons to whom the Software is furnished to do
-- so, subject to the following conditions:
--
--
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
--
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.

local config = require("devcontainer-cli.config")
local utils = require("devcontainer-cli.devcontainer_utils")
local terminal = require("devcontainer-cli.terminal")

local M = {}

local function define_autocommands()
local au_id = vim.api.nvim_create_augroup("devcontainer.docker.terminal", {})
vim.api.nvim_create_autocmd("UILeave", {
group = au_id,
callback = function()
-- It connects with the Devcontainer just after quiting neovim.
-- TODO: checks that the devcontainer is not already connected
-- TODO: checks that there is a devcontainer running
vim.schedule(
function()
local command = config.nvim_plugin_folder .. "/bin/connect_to_devcontainer.sh"
vim.fn.jobstart(command, { detach = true })
end
)
end,
})
end

-- executes a given command in the devcontainer of the current project directory
---@param opts (table) options for executing the command
function M.exec(opts)
Expand Down Expand Up @@ -71,7 +52,7 @@ end

-- toggle the current devcontainer window
function M.toggle()
utils.toggle()
terminal.toggle()
end

-- bring up the devcontainer in the current project directory
Expand All @@ -82,7 +63,11 @@ end
-- Thanks to the autocommand executed after leaving the UI, after closing the
-- neovim window the devcontainer will be automatically open in a new terminal
function M.connect()
define_autocommands()
if not utils.create_connect_cmd() then
vim.notify("Failed to create autocommand", vim.log.levels.ERROR)
return
end

vim.cmd("wqa")
end

Expand Down
Loading

0 comments on commit d5fd47a

Please sign in to comment.