Files
topgrade/src/vim.rs

52 lines
1.3 KiB
Rust
Raw Normal View History

2018-07-07 09:18:53 +03:00
use super::utils::PathExt;
2018-07-07 02:18:19 +03:00
use directories::BaseDirs;
2018-06-07 08:51:16 +03:00
use std::fs;
use std::path::PathBuf;
#[derive(Debug, Clone, Copy)]
pub enum PluginFramework {
Plug,
Vundle,
NeoBundle,
}
impl PluginFramework {
pub fn detect(vimrc: &PathBuf) -> Option<PluginFramework> {
let content = fs::read_to_string(vimrc).ok()?;
if content.contains("NeoBundle") {
Some(PluginFramework::NeoBundle)
} else if content.contains("Vundle") {
Some(PluginFramework::Vundle)
} else if content.contains("plug#begin") {
Some(PluginFramework::Plug)
} else {
None
}
}
pub fn upgrade_command(self) -> &'static str {
match self {
PluginFramework::NeoBundle => "NeoBundleUpdate",
PluginFramework::Vundle => "PluginUpdate",
PluginFramework::Plug => "PlugUpdate",
}
}
}
2018-07-07 02:18:19 +03:00
pub fn vimrc(base_dirs: &BaseDirs) -> Option<PathBuf> {
2018-07-07 09:18:53 +03:00
base_dirs
.home_dir()
.join(".vimrc")
.if_exists()
.or_else(|| base_dirs.home_dir().join(".vim/vimrc").if_exists())
}
2018-07-07 02:18:19 +03:00
pub fn nvimrc(base_dirs: &BaseDirs) -> Option<PathBuf> {
2018-07-07 09:18:53 +03:00
#[cfg(unix)]
return base_dirs.config_dir().join("nvim/init.vim").if_exists();
2018-07-07 09:18:53 +03:00
#[cfg(windows)]
return base_dirs.cache_dir().join("nvim/init.vim").if_exists();
}