Created
August 18, 2026 09:08
-
-
Save lopesivan/34a59e8683cf483ae65c1b747a68f6fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -e | |
| set -u | |
| set -o pipefail | |
| NVIM_CONFIG_NAME=nvim-pde | |
| _d=/tmp/neovim | |
| test -d "$_d" || mkdir -p "$_d" | |
| REAL_NVIM=/home/linuxbrew/.linuxbrew/bin/nvim | |
| std_socket=$_d/neovim.socket | |
| new_socket=$_d/$(uuidgen).nvim.socket | |
| socket=$std_socket | |
| ATTACH_MODE=false | |
| ARGS=() | |
| for arg in "$@"; do | |
| case $arg in | |
| -a | --attach) | |
| ATTACH_MODE=true | |
| ;; | |
| *) | |
| ARGS+=("$arg") | |
| ;; | |
| esac | |
| done | |
| clean() { | |
| # Remove apenas o socket se ele existir e o processo dele já tiver morrido | |
| if test -S "${socket:-}" && ! lsof "$socket" >/dev/null 2>&1; then | |
| rm -f "$socket" | |
| fi | |
| } | |
| trap clean EXIT SIGINT SIGTERM | |
| export NVIM_APPNAME="${NVIM_CONFIG_NAME}" | |
| export NDE_APP_CONFIG="/home/ivan/.config/${NVIM_CONFIG_NAME}" | |
| # Modo de reconexão via -a / --attach | |
| if [ "$ATTACH_MODE" = true ]; then | |
| if test -S "$std_socket" && lsof "$std_socket" >/dev/null 2>&1; then | |
| echo "Reconectando ao servidor Neovim em $std_socket..." | |
| exec "$REAL_NVIM" --server "$std_socket" --remote-ui "${ARGS[@]}" | |
| else | |
| echo "Erro: Nenhum servidor Neovim ativo encontrado em $std_socket" >&2 | |
| exit 1 | |
| fi | |
| fi | |
| # Seleção de socket para novas sessões | |
| if test -S "$std_socket"; then | |
| if lsof "$std_socket" >/dev/null 2>&1; then | |
| socket=$new_socket | |
| else | |
| rm -f "$std_socket" | |
| socket=$std_socket | |
| fi | |
| fi | |
| # Inicia o servidor do Neovim | |
| exec "$REAL_NVIM" --listen "$socket" "${ARGS[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment