From bc5acd9ecfa4389277591e8a21c438716f43cd89 Mon Sep 17 00:00:00 2001 From: pika Date: Thu, 22 Aug 2024 17:12:44 +0000 Subject: [PATCH] check nvim version before neovide alias --- .zshrc | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/.zshrc b/.zshrc index 055f7e2..c11dd68 100644 --- a/.zshrc +++ b/.zshrc @@ -244,18 +244,50 @@ _coding_() { export EDITOR="codium" fi # ─< neovide, the best frontend for any neovim-config >─────────────────────────────────── - if [ -d "$HOME/.local/share/neovide/" ]; then - if command_exists neovide; then - alias nvim='neovide --fork' +# Function to check Neovim version and set up Neovide alias accordingly +setup_nvim_alias() { + # Check if Neovide directory exists + if [ -d "$HOME/.local/share/neovide/" ]; then + # Get the current Neovim version + version=$(nvim --version | head -n 1 | awk '{print $2}') + + # Define the required version + required_version="0.10.0" + + # Use awk to compare versions + if awk -v v1="$version" -v v2="$required_version" 'BEGIN { + split(v1, a, "."); split(v2, b, "."); + if (a[1] > b[1] || (a[1] == b[1] && a[2] > b[2]) || (a[1] == b[1] && a[2] == b[2] && a[3] >= b[3])) exit(0); + exit(1); + }'; then + # Neovim version is 0.10.0 or higher, use Neovide + if command -v neovide > /dev/null; then + alias nvim='neovide --fork' + else + if [ -n "$neovide_path" ]; then + alias nvim="$neovide_path --fork" + else + neovide_path=$(find "$HOME/" -name "*neovide*.appimage" 2>/dev/null) + if [ -n "$neovide_path" ]; then + alias nvim="$neovide_path --fork" + else + echo "Neovide not found. Please install Neovide or set neovide_path." + fi + fi + fi + else + # Neovim version is below 0.10.0, use default nvim + alias nvim='nvim' + fi else - if [ -n "$neovide_path" ]; then - alias nvim="$neovide_path --fork" - else - neovide_path=$(find "$HOME/" -name "*neovide*.appimage" 2>/dev/null) - alias nvim="$neovide_path --fork" - fi + # Neovide directory does not exist + echo "Neovide directory not found. Skipping Neovide alias setup." fi - fi +} + +# Ensure to call the function to apply the alias setup +setup_nvim_alias + # Function to get the IP address get_ip() { ip a | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d/ -f1 | head -n 1