diff --git a/bin/connect_to_devcontainer.sh b/bin/connect_to_devcontainer.sh deleted file mode 100755 index cd8d837..0000000 --- a/bin/connect_to_devcontainer.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -set -e -# The following code creates a new terminal (using gnome-terminal) and it -# connects to the container using the devcontainer built in command. -# TODO: Add a check to see if the container is running. -# TODO: Give the possibility of using multiple terminals, not only gnome-terminal -# TODO: Give the possibility of opening a new tmux page instead of opening a new container - -if [ -n "$TMUX" ]; then - tmux_open="tmux split-window -h -t \"$TMUX_PANE\" " -else - tmux_open="" -fi - -# Execute the command for opening the devcontainer in the following terminal: -if [ -x "$(command -v alacritty)" ]; then - # ALACRITTY TERMINAL EMULATOR - REPOSTORY_NAME=$(basename "$(pwd)") - TERMINAL_TITLE="Devcontainer [${REPOSTORY_NAME}]" - command="alacritty --working-directory . --title "${TERMINAL_TITLE}" -e ${tmux_open}$@ &" -elif [ -x "$(command -v gnome-terminal)" ]; then - # GNOME TERMINAL - command="gnome-terminal -- ${tmux_open}$@" -elif [ "$(uname)" == "Darwin" ] && [ -x "$(command -v iTerm)" ]; then - # MAC ITERM2 TERMINAL EMULATOR - command="open -a iTerm.app ${tmux_open}$@" -elif [ "$(uname)" == "Darwin" ] && [ -x "$(command -v Terminal)" ]; then - # MAC TERMINAL - command="open -a Terminal.app ${tmux_open}$@" -else - # TERMINAL NO DEFINED - echo "ERROR: No compatible emulators found!" - exit 1 -fi - -eval "${command}" diff --git a/lua/devcontainer-cli/devcontainer_utils.lua b/lua/devcontainer-cli/devcontainer_utils.lua index daa133b..c2b7c2c 100644 --- a/lua/devcontainer-cli/devcontainer_utils.lua +++ b/lua/devcontainer-cli/devcontainer_utils.lua @@ -348,7 +348,21 @@ function M.create_connect_cmd() group = au_id, callback = function() - local connect_command = {config.nvim_plugin_folder .. "/bin/connect_to_devcontainer.sh"} + local connect_command = {} + if vim.env.TMUX ~= "" then + connect_command = {"tmux split-window -h -t \"$TMUX_PANE\""} + elseif vim.fn.executable("allacrity") == 1 then + connect_command = {"alacritty --working-directory . --title \"Devcontainer\" -e"} + elseif vim.fn.executable("gnome-terminal") == 1 then + connect_command = {"gnome-terminal --"} + elseif vim.fn.executable("iTerm.app") == 1 then + connect_command = {"iTerm.app"} + elseif vim.fn.executable("Terminal.app") == 1 then + connect_command = {"Terminal.app"} + else + vim.notify("No supported terminal emulator found.", vim.log.levels.ERROR) + end + table.insert(connect_command, dev_command) local command = table.concat(connect_command, " ") vim.schedule(