lib/mux_tf/cli/mux.rb in mux_tf-0.3.0 vs lib/mux_tf/cli/mux.rb in mux_tf-0.3.1

- old
+ new

@@ -1,14 +1,31 @@ # frozen_string_literal: true +require "bundler" + module MuxTf module Cli module Mux extend PiotrbCliUtils::Util extend PiotrbCliUtils::ShellHelpers class << self + def with_clean_env + backup = {} + Bundler.with_original_env do + ENV.keys.grep(/^(RBENV_|RUBYLIB)/).each do |key| + backup[key] = ENV[key] + ENV.delete(key) + end + yield + end + ensure + backup.each do |k, v| + ENV[k] = v + end + end + def run(_args) Dotenv.load(".env.mux") log "Enumerating folders ..." dirs = enumerate_terraform_dirs @@ -36,13 +53,17 @@ log "Killing existing session ..." Tmux.kill_session(project) end log "Starting new session ..." - Tmux.new_session project + with_clean_env do + Tmux.new_session project + end Tmux.select_pane "initial" + # Tmux.set "remain-on-exit", "on" + Tmux.set_hook "pane-exited", "select-layout tiled" Tmux.set_hook "window-pane-changed", "select-layout tiled" Tmux.set "mouse", "on" @@ -65,9 +86,11 @@ initial_pane = Tmux.find_pane("initial") Tmux.kill_pane initial_pane[:id] Tmux.tile! puts "\e]0;tmux: #{project}\007" + + sleep 5 log "Attaching ..." Tmux.attach(project, cc: !!ENV["MUXP_CC_MODE"]) log "Done!" end