class Object

Public Instance Methods

check_if_configuration_exist(configuration_file) click to toggle source
# File bin/dropbox-dotfiles, line 72
def check_if_configuration_exist(configuration_file)
  if File.exists? configuration_file
    unless File.file? configuration_file
      error "'#{configuration_file}' is not a file!"
    end
  else
    error "'#{configuration_file}' doesn't exists!"
    print 'Should I create a new the file with an example configuration? (y/N): '
    response = STDIN.gets.chomp.downcase
    if response == 'y'
      create_example_configuration configuration_file
    else
      exit!
    end
  end
end
check_if_dotfiles_dir_exist() click to toggle source
# File bin/dropbox-dotfiles, line 55
def check_if_dotfiles_dir_exist
  dotfiles_directory = File.expand_path File.join $my_dropbox_directory, 'Dotfiles'
  unless File.directory? dotfiles_directory
    error "'#{dotfiles_directory}' doesn't exists or is not a directory!"
    print 'Should I create the directory for you? (y/N): '
    response = STDIN.gets.chomp.downcase
    if response == 'y'
      begin
        Dir.mkdir dotfiles_directory
      rescue Exception => e
        error e.message
        exit!
      end
    end
  end
end
check_if_dropbox_dir_exist() click to toggle source
# File bin/dropbox-dotfiles, line 47
def check_if_dropbox_dir_exist
  dropbox_directory = File.expand_path $my_dropbox_directory
  unless File.directory? dropbox_directory
    error "'#{dropbox_directory}' doesn't exists or is not a directory!"
    exit!
  end
end
create_example_configuration(configuration_file) click to toggle source
# File bin/dropbox-dotfiles, line 89
def create_example_configuration(configuration_file)
  File.open configuration_file, 'w' do |example|
    example.puts <<CONFIGURATION
DropboxDotfiles.configuration {
  # if you want to create a link for a single file use the command 'file' like this:
  # file '.vimrc'

  # if its a directory you want to link use the command 'dir' like this:
  # dir '.gem'

  # when you use a 'file' or 'dir' command dropbox-dotfiles assumes that the source
  # file or directory are in your home. If you want to link something inside a sub
  # directory without creating a link to the folder itself use the command cd to
  # change the root then use file and dir normally.
  # cd statements can be nested
  # cd('Library') {
  #   dir 'Fonts'
  #   cd('Preferences') {
  #     file 'com.apple.Terminal.plist'
  #   }
  # }
}
CONFIGURATION
  end
rescue Exception => e
  error e.message
  exit!
else
  puts 'File created!'.green
  puts "Now open '#{configuration_file}' in your favourite text editor and edit the configuration."
  puts 'When you\'re done launch dropbox-dotfiles again.'
  exit! 0
end
error(message) click to toggle source
# File bin/dropbox-dotfiles, line 9
def error(message)
  puts "#{message}".red
end
get_dropbox_dir_from_args() click to toggle source
# File bin/dropbox-dotfiles, line 21
def get_dropbox_dir_from_args
  if ARGV.size == 1
    ARGV[0]
  end
end
get_dropbox_dir_from_dotfile() click to toggle source
# File bin/dropbox-dotfiles, line 13
def get_dropbox_dir_from_dotfile
  dotfile = File.expand_path '~/.dropbox-dotfiles'

  if File.exists? dotfile
    File.read dotfile
  end
end
get_dropbox_directory() click to toggle source
# File bin/dropbox-dotfiles, line 27
def get_dropbox_directory
  directory = '~/Dropbox'

  from_dotfile = get_dropbox_dir_from_dotfile
  if from_dotfile.to_s != ''
    directory = from_dotfile
  end

  from_args = get_dropbox_dir_from_args
  if from_args.to_s != ''
    directory = from_args

    File.open(File.expand_path('~/.dropbox-dotfiles'), 'w+') do |f|
      f.write(from_args)
    end
  end

  File.expand_path directory
end