Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Add an option to force vim plug update (#795)
Browse files Browse the repository at this point in the history
* Add an option to force vim plug update (fix #751)

* Rustfmt

* Update src/config.rs

Co-authored-by: M*C*O <mcofficer@gmx.de>

Co-authored-by: M*C*O <mcofficer@gmx.de>
  • Loading branch information
r-darwish and MCOfficer committed Dec 9, 2021
1 parent 90ee156 commit 536a08b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ pub struct Composer {
self_update: Option<bool>,
}

#[derive(Deserialize, Default, Debug)]
#[serde(deny_unknown_fields)]
pub struct Vim {
force_plug_update: Option<bool>,
}

#[derive(Deserialize, Default, Debug)]
#[serde(deny_unknown_fields)]
/// Configuration file
Expand Down Expand Up @@ -244,6 +250,7 @@ pub struct ConfigFile {
git: Option<Git>,
windows: Option<Windows>,
npm: Option<NPM>,
vim: Option<Vim>,
firmware: Option<Firmware>,
vagrant: Option<Vagrant>,
flatpak: Option<Flatpak>,
Expand Down Expand Up @@ -626,6 +633,15 @@ impl Config {
.unwrap_or(false)
}

/// Whether to force plug update in Vim
pub fn force_vim_plug_update(&self) -> bool {
self.config_file
.vim
.as_ref()
.and_then(|c| c.force_plug_update)
.unwrap_or_default()
}

/// Whether to send a desktop notification at the beginning of every step
#[allow(dead_code)]
pub fn notify_each_step(&self) -> bool {
Expand Down
6 changes: 5 additions & 1 deletion src/steps/upgrade.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ endif
if exists(":PlugUpgrade")
echo "Plug"
PlugUpgrade
PlugUpdate
if $TOPGRADE_FORCE_PLUGUPDATE
PlugUpdate!
else
PlugUpdate
endif
endif

if exists(":PackerUpdate")
Expand Down
17 changes: 11 additions & 6 deletions src/steps/vim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn vimrc(base_dirs: &BaseDirs) -> Result<PathBuf> {

fn nvimrc(base_dirs: &BaseDirs) -> Result<PathBuf> {
#[cfg(unix)]
let base_dir =
let base_dir =
// Bypass directories crate as nvim doesn't use the macOS-specific directories.
std::env::var_os("XDG_CONFIG_HOME").map_or_else(|| base_dirs.home_dir().join(".config"), PathBuf::from);

Expand All @@ -45,14 +45,19 @@ fn upgrade(vim: &Path, vimrc: &Path, ctx: &ExecutionContext) -> Result<()> {
tempfile.write_all(UPGRADE_VIM.replace('\r', "").as_bytes())?;
debug!("Wrote vim script to {:?}", tempfile.path());

let output = ctx
.run_type()
.execute(&vim)
let mut command = ctx.run_type().execute(&vim);

command
.args(&["-u"])
.arg(vimrc)
.args(&["-U", "NONE", "-V1", "-nNesS"])
.arg(tempfile.path())
.output()?;
.arg(tempfile.path());

if ctx.config().force_vim_plug_update() {
command.env("TOPGRADE_FORCE_PLUGUPDATE", "true");
}

let output = command.output()?;

if let ExecutorOutput::Wet(output) = output {
let status = output.status;
Expand Down

0 comments on commit 536a08b

Please sign in to comment.