Vim (fixes #17)

This commit is contained in:
Roey Darwish Dror
2018-06-07 08:51:16 +03:00
parent ef69dc01ba
commit c490b2c108
4 changed files with 75 additions and 1 deletions

View File

@@ -22,6 +22,10 @@ Just invoke `topgrade`. It will invoke the following steps:
* *Unix*: Upgrade tmux plugins with [TPM](https://github.com/tmux-plugins/tpm)
* Invoke Cargo [install-update](https://github.com/nabijaczleweli/cargo-update)
* Upgrade Emacs packages
* Upgrade Vim packages. Works with the following plugin frameworks:
* [NeoBundle](https://github.com/Shougo/neobundle.vim)
* [Vundle](https://github.com/VundleVim/Vundle.vim)
* [Plug](https://github.com/junegunn/vim-plug)
* Upgrade NPM globally installed packages
* Upgrade Atom packages
* Upgrade RubyGems globally installed packages

View File

@@ -9,6 +9,7 @@ mod git;
mod report;
mod steps;
mod terminal;
mod vim;
use failure::Error;
use git::Git;
@@ -110,7 +111,18 @@ fn main() -> Result<(), Error> {
let init_file = home_path(".emacs.d/init.el");
if init_file.exists() {
terminal.print_separator("Emacs");
run_emacs(&emacs, &home_path(".emacs.d/init.el")).report("Emacs", &mut reports);
run_emacs(&emacs, &init_file).report("Emacs", &mut reports);
}
}
if let Ok(vim) = which("Vim") {
let vimrc = home_path(".vimrc");
if vimrc.exists() {
if let Some(plugin_framework) = vim::PluginFramework::detect(&vimrc) {
terminal.print_separator(&format!("vim ({:?})", plugin_framework));
run_vim(&vim, &vimrc, plugin_framework.upgrade_command())
.report("Vim", &mut reports);
}
}
}

View File

@@ -48,6 +48,31 @@ pub fn run_emacs(emacs: &PathBuf, init: &PathBuf) -> Result<(), failure::Error>
Ok(())
}
pub fn run_vim(
vim: &PathBuf,
vimrc: &PathBuf,
upgrade_command: &str,
) -> Result<(), failure::Error> {
Command::new(&vim)
.args(&[
"-N",
"-u",
vimrc.to_str().unwrap(),
"-c",
upgrade_command,
"-c",
"quitall",
"-e",
"-s",
"-V1",
])
.spawn()?
.wait()?
.check()?;
Ok(())
}
pub fn run_gem(gem: &PathBuf) -> Result<(), failure::Error> {
Command::new(&gem)
.args(&["update"])

33
src/vim.rs Normal file
View File

@@ -0,0 +1,33 @@
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",
}
}
}