Class: GitSetup
- Inherits:
-
Object
- Object
- GitSetup
- Defined in:
- lib/git_undo/git_setup.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #alias_exists? ⇒ Boolean
-
#initialize ⇒ GitSetup
constructor
A new instance of GitSetup.
- #run ⇒ Object
- #update_bash_profile ⇒ Object
- #write_to_bash_profile ⇒ Object
Constructor Details
#initialize ⇒ GitSetup
Returns a new instance of GitSetup.
5 6 7 |
# File 'lib/git_undo/git_setup.rb', line 5 def initialize @file = nil end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
3 4 5 |
# File 'lib/git_undo/git_setup.rb', line 3 def file @file end |
Instance Method Details
#alias_exists? ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# 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 ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/git_undo/git_setup.rb', line 24 def update_bash_profile @file = File.open(File.('~' + '/.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 ⇒ Object
48 49 50 51 52 53 |
# 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 |