check nvim version before neovide alias

This commit is contained in:
pika 2024-08-22 17:12:44 +00:00
parent 70eb4de6d3
commit bc5acd9ecf

34
.zshrc
View file

@ -244,18 +244,50 @@ _coding_() {
export EDITOR="codium" export EDITOR="codium"
fi fi
# ─< neovide, the best frontend for any neovim-config >─────────────────────────────────── # ─< neovide, the best frontend for any neovim-config >───────────────────────────────────
# 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 if [ -d "$HOME/.local/share/neovide/" ]; then
if command_exists 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' alias nvim='neovide --fork'
else else
if [ -n "$neovide_path" ]; then if [ -n "$neovide_path" ]; then
alias nvim="$neovide_path --fork" alias nvim="$neovide_path --fork"
else else
neovide_path=$(find "$HOME/" -name "*neovide*.appimage" 2>/dev/null) neovide_path=$(find "$HOME/" -name "*neovide*.appimage" 2>/dev/null)
if [ -n "$neovide_path" ]; then
alias nvim="$neovide_path --fork" alias nvim="$neovide_path --fork"
else
echo "Neovide not found. Please install Neovide or set neovide_path."
fi fi
fi fi
fi fi
else
# Neovim version is below 0.10.0, use default nvim
alias nvim='nvim'
fi
else
# Neovide directory does not exist
echo "Neovide directory not found. Skipping Neovide alias setup."
fi
}
# Ensure to call the function to apply the alias setup
setup_nvim_alias
# Function to get the IP address # Function to get the IP address
get_ip() { get_ip() {
ip a | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d/ -f1 | head -n 1 ip a | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d/ -f1 | head -n 1