Class: Homebrew::DevCmd::Sh

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/sh.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'dev-cmd/sh.rb', line 28

def run
  ENV.activate_extensions!(env: args.env)

  ENV.deps = Formula.installed.select { |f| f.keg_only? && f.opt_prefix.directory? } if superenv?(args.env)
  ENV.setup_build_environment
  if superenv?(args.env)
    # superenv stopped adding brew's bin but generally users will want it
    ENV["PATH"] = PATH.new(ENV.fetch("PATH")).insert(1, HOMEBREW_PREFIX/"bin").to_s
  end

  ENV["VERBOSE"] = "1" if args.verbose?

  preferred_shell = Utils::Shell.preferred_path(default: "/bin/bash")

  if args.cmd.present?
    safe_system(preferred_shell, "-c", args.cmd)
  elsif args.named.present?
    safe_system(preferred_shell, args.named.first)
  else
    shell_type = Utils::Shell.preferred
    subshell = case shell_type
    when :zsh
      "PS1='brew %B%F{green}%~%f%b$ ' #{preferred_shell} -d -f"
    when :bash
      "PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{preferred_shell} --noprofile --norc"
    else
      "PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{preferred_shell}"
    end
    puts <<~EOS
      Your shell has been configured to use Homebrew's build environment;
      this should help you build stuff. Notably though, the system versions of
      gem and pip will ignore our configuration and insist on using the
      environment they were built under (mostly). Sadly, scons will also
      ignore our configuration.
      When done, type `exit`.
    EOS
    $stdout.flush
    safe_system subshell
  end
end