Module: BinInstall::Shell
- Defined in:
- lib/bin_install/shell.rb
Class Method Summary collapse
- .append_to_profiles(value) ⇒ Object
- .default_no?(value) ⇒ Boolean
- .default_yes?(value) ⇒ Boolean
- .executable_exists?(executable) ⇒ Boolean
- .no?(value) ⇒ Boolean
- .profile_paths ⇒ Object
- .wait(seconds = 10) ⇒ Object
- .yes?(value) ⇒ Boolean
Class Method Details
.append_to_profiles(value) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bin_install/shell.rb', line 23 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 file injection.".blue else puts "Writing to #{path}:\n#{value.to_s.purple}" file << value.to_s end file.close end end |
.default_no?(value) ⇒ Boolean
15 16 17 |
# File 'lib/bin_install/shell.rb', line 15 def self.default_no?(value) ['', 'n', 'no'].include?(value.downcase) end |
.default_yes?(value) ⇒ Boolean
7 8 9 |
# File 'lib/bin_install/shell.rb', line 7 def self.default_yes?(value) ['', 'y', 'yes'].include?(value.downcase) end |
.executable_exists?(executable) ⇒ Boolean
19 20 21 |
# File 'lib/bin_install/shell.rb', line 19 def self.executable_exists?(executable) system("which #{executable}") end |
.no?(value) ⇒ Boolean
11 12 13 |
# File 'lib/bin_install/shell.rb', line 11 def self.no?(value) %w[n no].include?(value.downcase) end |
.profile_paths ⇒ Object
38 39 40 |
# File 'lib/bin_install/shell.rb', line 38 def self.profile_paths [File.('~/.zshrc'), File.('~/.bash_profile')] end |
.wait(seconds = 10) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bin_install/shell.rb', line 42 def self.wait(seconds = 10) print 'Please wait: '.purple seconds.downto(1) do |i| print i.to_s.purple 3.times do sleep(0.25) print '.'.purple end sleep(0.25) end print "\n" end |
.yes?(value) ⇒ Boolean
3 4 5 |
# File 'lib/bin_install/shell.rb', line 3 def self.yes?(value) %w[y yes].include?(value.downcase) end |