From 6430640d28dcba2b63c4b19abc2ef599b5590364 Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 16 Apr 2020 14:32:28 -0400 Subject: [PATCH] Extract more generic shell class --- lib/vagrant/util/install_cli_autocomplete.rb | 28 ++++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/vagrant/util/install_cli_autocomplete.rb b/lib/vagrant/util/install_cli_autocomplete.rb index bd94d7335..ea7cee3e5 100644 --- a/lib/vagrant/util/install_cli_autocomplete.rb +++ b/lib/vagrant/util/install_cli_autocomplete.rb @@ -1,14 +1,13 @@ module Vagrant module Util - class ZSHShell - PREPEND = "# >>>> Vagrant zsh completion (start)".freeze - STRING_INSERT = """fpath=(#{File.join(Vagrant.source_root, "contrib", "zsh")} $fpath)\ncompinit""".freeze - APPEND = "# <<<< Vagrant zsh completion (end)".freeze - - CONFIG_PATHS = [".zshrc"].freeze + class Shell + PREPEND = "".freeze + STRING_INSERT = "".freeze + APPEND = "".freeze + CONFIG_PATHS = [""].freeze def self.shell_installed(home) - CONFIG_PATHS.each do |path| + self::CONFIG_PATHS.each do |path| config_file = File.join(home, path) if File.exists?(config_file) return config_file @@ -19,7 +18,7 @@ module Vagrant def self.is_installed(path) File.foreach(path) do |line| - if line.include?(PREPEND) + if line.include?(self::PREPEND) return true end end @@ -31,17 +30,24 @@ module Vagrant if path && !is_installed(path) File.open(path, "a") do |f| f.write("\n") - f.write(PREPEND) + f.write(self::PREPEND) f.write("\n") - f.write(STRING_INSERT) + f.write(self::STRING_INSERT) f.write("\n") - f.write(APPEND) + f.write(self::APPEND) f.write("\n") end end end end + class ZSHShell < Shell + PREPEND = "# >>>> Vagrant zsh completion (start)".freeze + STRING_INSERT = """fpath=(#{File.join(Vagrant.source_root, "contrib", "zsh")} $fpath)\ncompinit""".freeze + APPEND = "# <<<< Vagrant zsh completion (end)".freeze + CONFIG_PATHS = [".zshrc"].freeze + end + # Install autocomplete script for supported shells class InstallCLIAutocomplete SUPPORTED_SHELLS = {