Class: Profile::Shell
- Includes:
- Bashman
- Defined in:
- lib/bashman/shell.rb
Constant Summary collapse
- CONFIG =
self.get_config('shell')
- BASEPATH =
CONFIG.key?("basepath") ? File.(CONFIG["basepath"]) : File.("~/")
- BLOCKSIZE =
1024
Constants included from Bashman
Bashman::CONFIG_PATH, Bashman::VERSION
Instance Attribute Summary collapse
-
#dotfiles ⇒ Object
readonly
Returns the value of attribute dotfiles.
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
Instance Method Summary collapse
- #get_dotfiles ⇒ Object
-
#initialize ⇒ Shell
constructor
A new instance of Shell.
- #save_dotfiles(tarfile, timestamp = nil, overwrite = false) ⇒ Object
Methods included from Bashman
Methods inherited from JSONable
#from_json!, #to_hash, #to_json
Constructor Details
#initialize ⇒ Shell
Returns a new instance of Shell.
12 13 14 |
# File 'lib/bashman/shell.rb', line 12 def initialize @shell = self.get_current end |
Instance Attribute Details
#dotfiles ⇒ Object (readonly)
Returns the value of attribute dotfiles.
10 11 12 |
# File 'lib/bashman/shell.rb', line 10 def dotfiles @dotfiles end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
9 10 11 |
# File 'lib/bashman/shell.rb', line 9 def shell @shell end |
Instance Method Details
#get_dotfiles ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bashman/shell.rb', line 16 def get_dotfiles exc = [] inc = [] if CONFIG.include?('exclude') exc = CONFIG['exclude'].split(',').map {|x| x.strip} end if CONFIG.include?('include') inc = CONFIG['include'].split(',').map {|x| x.strip} else inc = ["\.[a-zA-Z0-9-_]*"] end files = self.add_includes(inc) files = self.remove_excludes(exc, files) files.delete_if {|f| /\.bashman\/profiles/ =~ f} @dotfiles = files end |
#save_dotfiles(tarfile, timestamp = nil, overwrite = false) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bashman/shell.rb', line 37 def save_dotfiles(tarfile, = nil, overwrite = false) require 'fileutils' savefile = File.(tarfile) if File.exists?(savefile) if not overwrite = File.mtime(savefile).to_i if .nil? bakfile = "#{savefile}.#{}" File.delete(bakfile) if File.exists?(bakfile) FileUtils.mv(savefile, bakfile) end end begin self.tar_gz(BASEPATH, savefile, *@dotfiles) rescue => e puts "Error saving dotfiles: #{e.}" puts e.backtrace File.delete(savefile) if File.exists?(savefile) if not bakfile.nil? and File.exists?(bakfile) FileUtils.mv(bakfile, savefile) end return 1 end end |