dotfile_linker 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +7 -0
- data/LICENSE +22 -0
- data/README.md +30 -0
- data/Rakefile +4 -0
- data/bin/link_dotfiles +6 -0
- data/dotfile_linker.gemspec +19 -0
- data/lib/dotfile_linker/version.rb +3 -0
- data/lib/dotfile_linker.rb +69 -0
- data/spec/dotfile_linker_spec.rb +53 -0
- metadata +75 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Dillon Kearns
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# DotfileLinker
|
2
|
+
|
3
|
+
A simple script to help you symlink your dotfiles to your home directory.
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
This gem aims to provide a simple, unopinionated solution to managing symlinking your dotfiles, allowing you to save
|
8
|
+
them in an isolated, versioned directory and keep your home directory clean. Similar tools exist, but tend to impose a
|
9
|
+
structure on how you manage your dotfiles.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Download the source, then run:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
$ rake install
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Run `link_dotfiles` from your dotfiles directory. The script will then run through each file that isn't already
|
21
|
+
symlinked in your home directory and ask if you want to symlink it. The `-d` option cycles through existing symlinks in
|
22
|
+
your home directory and asks if you'd like to remove them.
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/link_dotfiles
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/dotfile_linker/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Dillon Kearns"]
|
6
|
+
gem.email = ["dillon@dillonkearns.com"]
|
7
|
+
gem.description = "This gem aims to provide a simple, unopinionated solution to managing symlinking your " \
|
8
|
+
"dotfiles, allowing you to save them in an isolated, versioned directory and keep your home " \
|
9
|
+
"directory clean. Similar tools exist, but tend to impose a structure on how you manage your dotfiles."
|
10
|
+
gem.summary = "A simple script to help you symlink your dotfiles to your home directory."
|
11
|
+
gem.homepage = "https://github.com/dillonkearns/dotfile-linker"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.name = "dotfile_linker"
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
gem.version = DotfileLinker::VERSION
|
19
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'dotfile_linker/version'
|
2
|
+
require 'optparse'
|
3
|
+
require 'colorize'
|
4
|
+
|
5
|
+
class String
|
6
|
+
def human_filename
|
7
|
+
self.gsub(%r{^(/[^/]+){2}}, '~')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module DotfileLinker
|
12
|
+
BLACKLIST = %w{ .git }
|
13
|
+
@@options = {}
|
14
|
+
|
15
|
+
def self.parse_options
|
16
|
+
optparse = OptionParser.new do |opts|
|
17
|
+
opts.on('-d', '--delete', 'Delete symlinks') { @@options[:delete_mode] = true }
|
18
|
+
opts.on_tail('-v', '--version', 'Show version') { puts VERSION; exit }
|
19
|
+
opts.on_tail('-h', '--help', 'Show this message') { puts opts; exit }
|
20
|
+
end
|
21
|
+
optparse.parse!
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.exclude_file?(filename)
|
25
|
+
filename =~ /^\.\.?$/ or BLACKLIST.include?(filename)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.positive_user_response?
|
29
|
+
case gets.strip
|
30
|
+
when /^y/i
|
31
|
+
true
|
32
|
+
when /^n/i
|
33
|
+
false
|
34
|
+
else
|
35
|
+
puts 'Exiting'
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.link_file(filename)
|
41
|
+
unless exclude_file?(filename)
|
42
|
+
symlink_file = File.expand_path("~/#{ filename }")
|
43
|
+
actual_file = File.expand_path(filename)
|
44
|
+
if @@options[:delete_mode]
|
45
|
+
if File.symlink?(symlink_file)
|
46
|
+
puts "delete symlink #{ symlink_file.human_filename.magenta }? (y/n)"
|
47
|
+
File.delete(symlink_file) if positive_user_response?
|
48
|
+
end
|
49
|
+
else
|
50
|
+
unless File.symlink?(symlink_file)
|
51
|
+
puts "link %s -> %s? (y/n)" % [symlink_file.human_filename.magenta, actual_file.human_filename.cyan]
|
52
|
+
File.symlink(actual_file, symlink_file) if positive_user_response?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.link_files
|
59
|
+
Dir.foreach(Dir.pwd) { |filename| link_file(filename) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.start
|
63
|
+
parse_options
|
64
|
+
link_files
|
65
|
+
puts 'Done'
|
66
|
+
rescue Interrupt
|
67
|
+
# do nothing
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'dotfile_linker'
|
3
|
+
|
4
|
+
describe DotfileLinker do
|
5
|
+
describe ".exclude_file?" do
|
6
|
+
it "excludes files in blacklist" do
|
7
|
+
%w{ . .. .git }.each { |filename| DotfileLinker.exclude_file?(filename).should be }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "doesn't exclude files prefixed with dot" do
|
11
|
+
%w{ .bash_profile .emacs .gitconfig .tmux.conf }.each { |filename| DotfileLinker.exclude_file?(filename).should_not be }
|
12
|
+
end
|
13
|
+
|
14
|
+
it "doesn't exclude files that aren't prefixed with dot" do
|
15
|
+
['my_script' 'sample.rb'].each { |filename| DotfileLinker.exclude_file?(filename).should_not be }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".link_file when symlink doesn't already exist" do
|
20
|
+
before do
|
21
|
+
DotfileLinker.stub!(:positive_user_response?).and_return(true)
|
22
|
+
File.stub!(:symlink?).and_return(false)
|
23
|
+
|
24
|
+
@bad_filenames = %w{ . .. .git }
|
25
|
+
@good_filenames = %w{.bash_profile .bashrc .dotrc .emacs .gemrc .gitconfig .gitignore_global .irbrc .oh-my-zsh
|
26
|
+
.pryrc .rvmrc .ssh .tmux.conf .zshrc .zshrc.pre-oh-my-zsh}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "links accepted files to home directory" do
|
30
|
+
@good_filenames.each do |filename|
|
31
|
+
File.should_receive(:symlink).with("#{ Dir.pwd }/#{ filename }", "#{ Dir.home }/#{ filename }")
|
32
|
+
DotfileLinker.link_file(filename)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "doesn't link blacklisted files" do
|
37
|
+
@bad_filenames.each do |filename|
|
38
|
+
File.should_not_receive(:symlink)
|
39
|
+
DotfileLinker.link_file(filename)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "String#human_filename" do
|
45
|
+
it "replaces home dir for short path" do
|
46
|
+
File.expand_path("~/.bash_rc").human_filename.should == '~/.bash_rc'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "replaces home dir for long path" do
|
50
|
+
File.expand_path("#{ Dir.home }/some/test/dir/.gitignore").human_filename.should == '~/some/test/dir/.gitignore'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dotfile_linker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dillon Kearns
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-09-25 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: This gem aims to provide a simple, unopinionated solution to managing symlinking your dotfiles, allowing you to save them in an isolated, versioned directory and keep your home directory clean. Similar tools exist, but tend to impose a structure on how you manage your dotfiles.
|
22
|
+
email:
|
23
|
+
- dillon@dillonkearns.com
|
24
|
+
executables:
|
25
|
+
- link_dotfiles
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- LICENSE
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- bin/link_dotfiles
|
37
|
+
- dotfile_linker.gemspec
|
38
|
+
- lib/dotfile_linker.rb
|
39
|
+
- lib/dotfile_linker/version.rb
|
40
|
+
- spec/dotfile_linker_spec.rb
|
41
|
+
homepage: https://github.com/dillonkearns/dotfile-linker
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.24
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: A simple script to help you symlink your dotfiles to your home directory.
|
74
|
+
test_files:
|
75
|
+
- spec/dotfile_linker_spec.rb
|