Last active
August 7, 2023 19:33
-
-
Save codeitlikemiley/008ef9f319feb798c0b3daa249dcaaca to your computer and use it in GitHub Desktop.
Shell script function To Load different Neovim Configuration depending on your Project Language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# can you alias this to one letter alias ie. `v` | |
# alias v=nvims | |
nvims() { | |
# Set the default XDG_CONFIG_HOME if it's not already set | |
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" | |
# Get the path argument or default to the current directory | |
target_path="${1:-.}" | |
# Determine the project type | |
config="nvim" # default configuration | |
if [ "$(echo "$target_path" | grep '\.rs$')" ] || [ -f "$target_path/Cargo.toml" ]; then | |
config="nvim_rust" | |
elif [ "$(echo "$target_path" | grep '\.php$')" ] || \ | |
[ -f "$target_path/composer.json" ] && [ -d "$target_path/vendor/laravel" ]; then | |
config="nvim_laravel" | |
elif [ "$(echo "$target_path" | grep '\.jsx\?$')" ] || \ | |
[ -f "$target_path/package.json" ] && [ -d "$target_path/node_modules/react" ]; then | |
config="nvim_react" | |
elif [ "$(echo "$target_path" | grep '\.go$')" ]; then | |
config="nvim_go" | |
elif [ "$(echo "$target_path" | grep '\.py$')" ] || \ | |
[ -f "$target_path/requirements.txt" ] || \ | |
[ -f "$target_path/setup.py" ] || \ | |
[ -f "$target_path/Pipfile" ] || \ | |
[ -d "$target_path/.venv" ] || \ | |
[ -d "$target_path/venv" ]; then | |
config="nvim_python" | |
elif [ "$(echo "$target_path" | grep '\.lua$')" ] || [ -f "$target_path/init.lua" ]; then | |
config="nvim_config" | |
elif [ "$(echo "$target_path" | grep '\.dart$')" ] || [ -f "$target_path/pubspec.yaml" ]; then | |
config="nvim_flutter" | |
elif [ "$(echo "$target_path" | grep '\.swift$')" ]; then | |
config="nvim_swift" | |
elif [ "$(echo "$target_path" | grep '\.kt$')" ]; then | |
config="nvim_kotlin" | |
fi | |
NVIM_APPNAME=$config nvim "$target_path" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment