-
-
Save elijahmanor/b279553c0132bfad7eae23e34ceb593b to your computer and use it in GitHub Desktop.
alias nvim-lazy="NVIM_APPNAME=LazyVim nvim" | |
alias nvim-kick="NVIM_APPNAME=kickstart nvim" | |
alias nvim-chad="NVIM_APPNAME=NvChad nvim" | |
alias nvim-astro="NVIM_APPNAME=AstroNvim nvim" | |
function nvims() { | |
items=("default" "kickstart" "LazyVim" "NvChad" "AstroNvim") | |
config=$(printf "%s\n" "${items[@]}" | fzf --prompt=" Neovim Config " --height=~50% --layout=reverse --border --exit-0) | |
if [[ -z $config ]]; then | |
echo "Nothing selected" | |
return 0 | |
elif [[ $config == "default" ]]; then | |
config="" | |
fi | |
NVIM_APPNAME=$config nvim $@ | |
} | |
bindkey -s ^a "nvims\n" |
For zsh, I refactored the function so you don't need to hardcode the options;
Nice, works well with eza
too.
@wochap I tried your script on my setup and it doesn't seem to detect symlinks. I store all my configs under ~/.dotfiles
and generate respective symlinks using Stow. To work around it, I simply added an extra folder to search.
items=$(
find $HOME/.config -maxdepth 2 -name "init.lua" -type f -execdir sh -c 'pwd | xargs basename' \;
find $HOME/.dotfiles -maxdepth 5 -name "init.lua" -type f -execdir sh -c 'pwd | xargs basename' \;
)
Rather than adding an extra folder to search, the find
command can be altered either with:
find $HOME/.config -maxdepth 2 -name "init.lua" "(" -type f -o -type l ")" -execdir sh -c 'pwd | xargs basename' \;
or
find -L $HOME/.config -maxdepth 2 -name "init.lua" -type f -execdir sh -c 'pwd | xargs basename' \;
Either of those will pickup both plain files and symbolic links.
I also ran into a problem on an Ubuntu 20.04 system with the older version of fzf
in their repo. It did not understand the preview options:
invalid preview window layout: right:border-left:50%:<40(right:border-left:50%:hidden)
I simplified the preview options to get it to work on that system:
selected=$(printf "%s\n" "${items[@]}" | FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS-} --preview-window=right:50% --preview 'lsd -l -A --tree --depth=1 --color=always --blocks=size,name ~/.config/{} | head -200'" fzf )
My turn.
This uses the directory names of existing configurations. Someone else did the same, but my flavor is slightly shorter. Follows symlinks.
function nvims() {
find -L "${XDG_CONFIG_HOME:-$HOME/.config}" -mindepth 2 -maxdepth 2 -name init.lua -o -name init.vim | \
awk -F/ '{print $(NF-1)}' | \
fzf --prompt 'Neovim config' --layout=reverse --border --exit-0 |\
xargs -d$'\n' -n1 bash -c 'NVIM_APPNAME="$1" nvim' --
}
For zsh, I refactored the function so you don't need to hardcode the options; it finds any folder in
~/.config
with an init.lua file in it and considers it a nvim config folder. Additionally, it adds a preview usinglsd
to display the folder contents.Preview: