module WinAlias

Constants

VERSION

Public Class Methods

add_to_path() click to toggle source
# File lib/win_alias/util.rb, line 20
def self.add_to_path
  return true if in_path?
  warn("About to add win-alias/bin to PATH. A backup of your paths will be saved @ #{File.join(base_path, 'path_backup.txt')} in case something goes wrong.")
  error("NOTE: It is recommdned you verify your PATH in another shell after this is run. Some versions of Windows can cause the PATH to be truncated at 1024 characters.")
  backup_path_variable
  ENV['PATH'] = ENV['PATH'] + ";#{path}"
  `setx /M PATH "#{ENV['PATH']}"`
  in_path?
end
backup_path_variable() click to toggle source
# File lib/win_alias/util.rb, line 30
def self.backup_path_variable
  backup = File.join(base_path, 'path_backup.txt')
  lines = File.exist?(backup) ? File.read(backup).split("\n") : []
  lines += ENV['PATH'].split(';')
  lines.uniq.join("\n").to_file(backup, mode: 'w')
end
base_path() click to toggle source
# File lib/win_alias/util.rb, line 8
def self.base_path
  ENV['WIN_ALIAS_HOME'] || File.join(Dir.home, 'win_alias')
end
in_path?() click to toggle source
# File lib/win_alias/util.rb, line 16
def self.in_path?
  ENV['PATH'].include?(path)
end
path() click to toggle source
# File lib/win_alias/util.rb, line 12
def self.path
  File.join(base_path, 'bin')
end