Sha256: c7bb4a2d603a93a95a7298d42877fadab99aacf2ab5d80dee12be131463eac56

Contents?: true

Size: 930 Bytes

Versions: 2

Compression:

Stored size: 930 Bytes

Contents

module BinInstall
  module Shell
    def self.yes?(value)
      %w[y yes].include?(value.downcase)
    end

    def self.default_yes?(value)
      ['', 'y', 'yes'].include?(value.downcase)
    end

    def self.no?(value)
      %w[n no].include?(value.downcase)
    end

    def self.default_no?(value)
      ['', 'n', 'no'].include?(value.downcase)
    end

    def self.executable_exists?(executable)
      system("which #{executable}")
    end

    def self.append_to_profiles(value)
      profile_paths.each do |path|
        file = File.open(path, 'a+')

        if file.read.include?(value)
          puts "Value already exist in #{path}. Skipping.".blue
        else
          puts "Writing to #{path}:\n#{value.to_s.cyan}"
          file << value.to_s
        end

        file.close
      end
    end

    def self.profile_paths
      [File.expand_path('~/.zshrc'), File.expand_path('~/.bash_profile')]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bin_install-0.0.12 lib/bin_install/shell.rb
bin_install-0.0.11 lib/bin_install/shell.rb