class GitSetup
Attributes
file[R]
Public Class Methods
new()
click to toggle source
# File lib/git_undo/git_setup.rb, line 5 def initialize @file = nil end
Public Instance Methods
alias_exists?()
click to toggle source
# File lib/git_undo/git_setup.rb, line 34 def alias_exists? alias_exists = false file.readlines.each do |line| if /\A[\s]*alias/.match line if /\A[\s]*alias git-undo="HISTFILE=\$HISTFILE git-undo"\n\z/.match line alias_exists = true end end end return alias_exists end
run()
click to toggle source
# File lib/git_undo/git_setup.rb, line 9 def run puts "It looks like you haven't run the initial setup. Would you like to do so now? (y/N)" if gets.chomp.downcase == 'y' puts "This will involve appending an alias to your .bash_profile. Okay to proceed? (y/N)" if gets.chomp.downcase == 'y' puts "Thanks!" update_bash_profile else puts "Goodbye!" end else puts "Goodbye!" end end
update_bash_profile()
click to toggle source
# File lib/git_undo/git_setup.rb, line 24 def update_bash_profile @file = File.open(File.expand_path('~' + '/.bash_profile'),'r+') unless alias_exists? write_to_bash_profile puts "Please run `source ~/.bash_profile && cd .` to reload configuration" end file.close end
write_to_bash_profile()
click to toggle source
# File lib/git_undo/git_setup.rb, line 48 def write_to_bash_profile file.write("# Git Undo\n") file.write("alias git-undo=\"HISTFILE=$HISTFILE git-undo\"\n") file.write("# Flush history immediately") file.write("export PROMPT_COMMAND='history -a") end