-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmanager
executable file
·127 lines (109 loc) · 3.79 KB
/
manager
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
123
124
125
126
127
#!/bin/bash
# Copyright (c) 2012 Michael-Keith Bernard
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Fail fast
set -e
# General directory settings
CURRENT=`pwd`
BUNDLE="$CURRENT/bundle"
DATE=$(date +%d%m%Y)
GIT_REPO="git://github.com/SegFaultAX/vim-dotfiles.git"
GIT_BRANCH="segfaultax-$DATE"
GIT_FETCH_SPEC="+refs/heads/master:refs/heads/$GIT_BRANCH"
function usage() {
echo "Usage: $0"
echo " --help - this help menu"
echo " --fetch-vimrc - download maintainers repo"
echo " --create-symlink - symlink $CURRENT/vimrc to ~/.vimrc"
echo " --update-submodules - fetch newest submodule versions"
echo " --clean-branches - remove all maintainer repo branches"
echo
echo " --init - initialize submodules"
echo " --init-submodules - initialize submodules"
echo
}
function init_submodules() {
# Fetch all the submodules if we're in the root directory
if [ -d $CURRENT/.git ]; then
echo "Running git-submodule commands..."
git submodule update --init --recursive
else
echo "Run this command from the root of the project."
exit 1
fi
}
function update_submodules() {
if [ -d $CURRENT/.git ]; then
echo "Updating all submodules..."
init_submodules
git submodule foreach git pull origin master
fi
}
function create_symlink() {
echo "Creating symlink for vimrc."
VIMRC=$HOME/.vimrc
if [ -e "$VIMRC" ]; then
TIMESTAMP=$(date +%s)
BACKUP="$VIMRC.old.$TIMESTAMP"
echo "Backing up old $VIMRC to $BACKUP"
mv $VIMRC $BACKUP
fi
ln -s $CURRENT/vimrc $VIMRC
}
function fetch_vimrc() {
echo "Fetching maintainer version to $GIT_BRANCH"
git fetch $GIT_REPO $GIT_FETCH_SPEC
echo
echo "You can now run 'git merge $GIT_BRANCH' from master"
echo "You may also want to run 'git submodule init && git submodule update'"
echo "You can remove the branch with 'git branch -D $GIT_BRANCH'"
}
function clean_branches() {
echo "Cleaning up branches that match refs/heads/segfaultax-*"
git for-each-ref --format="%(refname:short)" refs/heads/segfaultax-\* | \
xargs git branch -D
}
echo "Manager by Michael-Keith Bernard"
# Section configuration
vimrc=
symlink=
submodules=
clean=
init_submodules=
if [ "$#" -eq 0 ]; then usage; fi
while [ "$#" -gt 0 ]; do
opt="$1"
shift
case "$opt" in
--help) usage; exit;;
--fetch-vimrc) vimrc="yes";;
--create-symlink) symlink="yes";;
--update-submodules) submodules="yes";;
--clean-branches) clean="yes";;
--init) init_submodules="yes";;
--init-submodules) init_submodules="yes";;
*) echo "Unknown option $opt"; exit 1;;
esac
done
if [ "$vimrc" = "yes" ]; then fetch_vimrc; fi
if [ "$symlink" = "yes" ]; then create_symlink; fi
if [ "$submodules" = "yes" ]; then update_submodules; fi
if [ "$clean" = "yes" ]; then clean_branches; fi
if [ "$init_submodules" = "yes" ]; then init_submodules; fi