Files
nvim/install.sh
2026-05-19 11:19:06 +02:00

85 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
PACKAGEFILE="packages.txt"
# Ensure we are in the correct directory
pushd "$(dirname "$(realpath "$0")")" &> /dev/null
# Check if commands are available
command -v yay &> /dev/null && CMD_YAY=true || CMD_YAY=false
# Read packages.txt and install packages on system using yay
function install_packages {
local install
for pkg in $(sed -E -e 's/\s*#.*$//g' -e 's/^\s+//g' "$PACKAGEFILE" | sed -E ':a;N;$!ba;s/\s+/\n/g'); do
# check if package is installed
local installed
$CMD_YAY && yay -Q "$(echo "$pkg")" &> /dev/null && installed=1 || installed=0
if [ $installed -eq 0 ]; then
# needs to be installed
install="$install"$'\n'"$pkg"
fi
done
[ -z "$install" ] || {
if $CMD_YAY; then
echo "Packages to be installed: "
echo "$install"
yay -S $install
else
echo "Yay package manager is not available"
echo "Please make sure that the following tools"
echo "are available in your system"
echo ""
echo "$install"
echo ""
read -p "Press Enter to continue" < /dev/tty
fi
}
}
# Try to install the language given in arguments
# - arg1 language name
# - arg2 github repository
function install_treesitter_language {
local language="$1"
local repository="$2"
local directory=$(basename "$repository")
# Clone the repository or update it
if [ ! -d "tree-sitter-source" ]; then
mkdir tree-sitter-source
fi
if [ ! -d "tree-sitter-source/$directory" ]; then
git clone --depth=1 "$repository" "tree-sitter-source/$directory"
fi
pushd "tree-sitter-source/$directory" &> /dev/null
git reset --hard
git clean -dfqx
git pull --ff-only
popd &> /dev/null
# Copy queries
if [ ! -d "queries/$language" ]; then
mkdir -p "queries/$language"
fi
find "tree-sitter-source/$directory" -iname '*.scm' -exec cp "{}" "queries/$language/" \;
# Make the parser
pushd "tree-sitter-source/$directory" &> /dev/null
tree-sitter build
popd &> /dev/null
# Copy parser
if [ ! -d "parser" ]; then
mkdir "parser"
fi
find "tree-sitter-source/$directory" -iname '*.so' -exec cp "{}" "parser/" \;
}
install_packages
install_treesitter_language "bash" "https://github.com/tree-sitter/tree-sitter-bash"
popd &> /dev/null