Module: Dotstrap

Defined in:
lib/dotstrap.rb,
lib/dotstrap/git.rb,
lib/dotstrap/shell.rb,
bin/dotstrap

Defined Under Namespace

Classes: Cli, Configuration, Git, Shell

Constant Summary collapse

NAME =
'dotstrap'
EXE_NAME =
'dotstrap'
VERSION =
'0.3.0'
AUTHOR =
'William Myers'
HOMEPAGE =
'http://github.com/mkwmms/dotstrap'
SOURCE_URL =
'http://github.com/mkwmms/dotstrap'
DOC_URL =
'http://www.rubydoc.info/github/mkwmms/dotstrap/master/Dotstrap'
SUMMARY =
'bootstrap your shell dotfiles in parallel from GitHub repos'
DESCRIPTION =
'bootstrap your shell dotfiles in parallel from GitHub repos'

Class Method Summary collapse

Class Method Details

.config_file(shell = shell_name) ⇒ Object



79
80
81
# File 'lib/dotstrap.rb', line 79

def config_file(shell = shell_name)
  File.join(config_home, "config.#{shell}")
end

.config_homeObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/dotstrap.rb', line 25

def config_home
  return ENV['DOTSTRAP_CONFIG_HOME'] if ENV.has_key?('DOTSTRAP_CONFIG_HOME')

  config_dir = ENV.fetch('XDG_CONFIG_HOME', Dir.home)
  if config_dir == Dir.home
    File.join(config_dir, '.config', 'dotstrap')
  else
    File.join(config_dir, 'dotstrap')
  end
end

.installed_repo_pathsObject



83
84
85
# File 'lib/dotstrap.rb', line 83

def installed_repo_paths
  Dir[File.join(config_home, '**')]
end

.installed_reposObject



87
88
89
90
91
92
93
94
95
# File 'lib/dotstrap.rb', line 87

def installed_repos
  repos = []
  installed_repo_paths.each do |repo_path|
    # next unless repo_path.include?('-') && File.directory?(repo_path)
    repo = File.basename(repo_path)
    repos << repo.sub(/-/,'/')
  end
  repos
end

.shell_config_home(shell = shell_name) ⇒ Object



73
74
75
76
77
# File 'lib/dotstrap.rb', line 73

def shell_config_home(shell = shell_name)
  h = Pathname.new(shell_profile(shell)).parent
  $LOG.debug { "SHELL_CONFIG_HOME:#{h}" }
  h
end

.shell_nameObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dotstrap.rb', line 36

def shell_name
  # FIXME: bad to rely on SHELL environment variable to determine shell?
  shell =
    case ENV['SHELL']
    when %r{/(ba)?sh} then
      'bash'
    when %r{/zsh} then
      'zsh'
    when %r{/fish} then
      'fish'
    else
      raise RuntimeError, ENV['SHELL']
    end
  $LOG.debug { "SHELL_NAME:#{shell}" }
  shell
end

.shell_profile(shell = shell_name) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dotstrap.rb', line 53

def shell_profile(shell = shell_name)
  profile =
    case shell
    when 'bash' then
      bash_profile = ''
      ['.bash_profile' '.profile'].each do |file|
        bash_profile = File.join(Dir.home, file)
        break if File.exist?(bash_profile)
      end
      bash_profile
    when 'zsh' then
      File.join(Dir.home, '.zshrc')
    when 'fish' then
      File.join(Dir.home, '.config', 'fish', 'config.fish')
      # File.exist?(file) ? file : fail ShellProfileError, "Fish shell config file not found
    end
  $LOG.debug { "SHELL_PROFILE:#{profile}" }
  profile.strip unless profile.nil?
end