Skip to content

Instantly share code, notes, and snippets.

@mikeslattery
Created January 9, 2025 21:19
Show Gist options
  • Save mikeslattery/df1d35fad3491103eaa10a6e5b8a18ce to your computer and use it in GitHub Desktop.
Save mikeslattery/df1d35fad3491103eaa10a6e5b8a18ce to your computer and use it in GitHub Desktop.
Neovim configuration selector
#!/bin/bash
set -euo pipefail
# Neovim configuration selection
# Provides a fuzzy search for all directories under ~/.config for init.lua
# Usage: nvims
# Requires:
# fzf
# optional: eza or lsd or tree
# optional: mdcat or bat
# Example distro installs
# git clone --depth 1 https://github.com/NvChad/starter ~/.config/nvchad
# git clone --depth 1 https://github.com/LazyVim/starter ~/.config/lazy
# git clone --depth 1 https://github.com/AstroNvim/template ~/.config/astro
# git clone --depth 1 git@github.com:mattleong/CosmicNvim.git ~/.config/cosmic
# Example personal config installs
# git clone --depth 1 https://github.com/ThePrimeagen/neovimrc ~/.config/prime
# git clone --depth 1 https://github.com/folke/dot.git; mv dot/nvim ~/.config/folke; rm dot -rf
# git clone --depth 1 https://github.com/ayamir/nvimdots ~/.config/nvimdots
# Support Vim config as a choice
if [[ ! -f ~/.config/vimrc/init.vim ]] && [[ -f ~/.vimrc ]]; then
mkdir -p ~/.config/vimrc
ln -sfn ~/.vimrc ~/.config/vimrc/init.vim
fi
configs() {
find ~/.config -mindepth 2 -maxdepth 2 -name 'init.lua' -o -name 'init.vim' |
awk -F/ '{print $(NF-1)}'
}
preview() {
has() {
command -v "$1" &>/dev/null
}
dir="$HOME/.config/$1"
file="${dir}/README.md"
if [[ -f "$file" ]]; then
if has mdcat; then
mdcat "$file"
elif has bat; then
bat -p "$file" --color=always
else
cat "$file"
fi
else
if has eza; then
eza -T "$dir" --color=always
elif has lsd; then
lsd --tree "$dir" --color=always
elif has tree; then
tree -C "$dir"
else
ls -R "$dir"
fi
fi
}
export -f preview
choice="$(configs Install Uninstall |
fzf --prompt 'Neovim Configs> ' --preview 'bash -c "preview {}"')"
echo "NVIM_APPNAME=$choice nvim $*" >&2
export NVIM_APPNAME="$choice"
exec nvim "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment