forked from Schoonology/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·122 lines (104 loc) · 3.06 KB
/
install
File metadata and controls
executable file
·122 lines (104 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env node
var fs = require('fs')
, path = require('path')
, exec = require('child_process').exec
, sh
// Normalize HOME environment variable.
process.env.HOME = process.env.HOME || process.env.HOMEDRIVE + process.env.HOMEPATH
if (!process.env.HOME) {
console.error(
'No HOME environment variables available. Dotfiles cannot be installed.'
)
process.exit(1)
}
// Handle ~ as Bash does.
function aTarget(file) {
return path.normalize(file.replace(/~/g, process.env.HOME))
}
// Absolute source file paths.
function aSource(file) {
return path.resolve(__dirname, file)
}
// HOME-relative source file paths
function rSource(file) {
return path.relative(process.env.HOME, aSource(file))
}
// CWD-relative source file paths
function lSource(file) {
return path.relative(process.cwd(), aSource(file))
}
// Detects the complete list of file paths that should be included or linked.
function detectSources(file) {
var sources = []
if (sh.test('-f', aSource(file))) {
sources.push(file)
}
if (sh.test('-f', aSource(file + '_' + process.platform))) {
sources.push(file + '_' + process.platform)
}
return sources
}
// Call each function in the given array in order. Each function is given
// a function that, when called, calls the next function in the list.
function step(arr) {
if (!arr.length) {
return
}
arr[0](function () {
step(arr.slice(1))
})
}
step([
// Install our dependencies if necessary, calling `callback` upon successful
// completion.
function bootstrap(callback) {
try {
sh = require('shelljs')
return callback()
} catch (e) {}
exec('npm install --no-bin-links', {
cwd: __dirname
}, function (err) {
if (err) {
console.error('Failed to install shelljs.')
console.error('Error:', err.message)
process.exit(1)
}
sh = require('shelljs')
return callback()
})
},
// Link all the dotfiles, and install all the things.
function install() {
// Bash
sh.rm('-f', aTarget('~/.bashrc'))
detectSources('bash/.bashrc')
.reduce(function (str, file) {
return str + 'source ~/' + rSource(file) + '\n'
}, '')
.to(aTarget('~/.bashrc'))
// Git
sh.rm('-f', aTarget('~/.gitconfig'))
detectSources('git/.gitconfig')
.reduce(function (str, file) {
return str + '[include]\n path = ' + rSource(file) + '\n'
}, '')
.to(aTarget('~/.gitconfig'))
sh.ln('-sf', lSource('git/.gitignore_global'), aTarget('~/.gitignore_global'))
// SSH
sh.mkdir('-p', aTarget('~/.ssh'))
sh.ln('-sf', lSource('ssh/config'), aTarget('~/.ssh/config'))
// Vim
sh.rm('-f', aTarget('~/.vimrc'))
detectSources('vim/.vimrc')
.reduce(function (str, file) {
return str + 'source ~/' + rSource(file) + '\n'
}, '')
.to(aTarget('~/.vimrc'))
// iTerm
if (process.platform === 'darwin') {
sh.rm('-f', aTarget('~/.iterm/com.googlecode.iterm2.plist'))
sh.ln('-sf', lSource('iterm/config.plist'), aTarget('~/.iterm/com.googlecode.iterm2.plist'))
}
}
])