-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.zsh
executable file
·60 lines (49 loc) · 1.76 KB
/
install.zsh
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
#!/bin/zsh
## Install critical packages
which apt-get && sudo apt-get install zsh vim git ack-grep -y
###
# Install symlinks to the files in this repo into the current user's $HOME
###
#REPO_DIR=$(pwd);
#DEST_DIR=/tmp/home
REPO_DIR=$(git rev-parse --show-toplevel)
DEST_DIR=$HOME
# Don't link this script or the .git subdirectory
excludes=(
"\.git.*"
"install\.zsh"
"etc/*"
)
# OR-together the subpatterns
exclude_pattern="\(${(j:\|:)excludes}\)"
#echo EXCLUDE: $exclude_pattern
echo "$REPO_DIR --> $DEST_DIR"
echo "This will install symlinks to all the regular files in this repository into $DEST_DIR"
echo "Any existing files will be backed up, with an underscore prefix."
echo "Afterwards, you probably want to diff any backups to see if there was anything important in them."
echo "Proceed? (type okeydoke)"
read proceed
[[ $proceed != "okeydoke" ]] && exit 1
for file in $( find $REPO_DIR -type f | grep -v "$exclude_pattern" );
do;
#echo sed -e \"s:$REPO_DIR::\"
relpath=`echo $file | sed -e "s:$REPO_DIR::" `
linkpath=$DEST_DIR$relpath
echo "$file --> $linkpath"
# Make the directory if it doesn't exist.
if [[ ! -d `dirname $linkpath` ]]; then
mkdir -p `dirname $linkpath`
fi
# if the file already exists, make an underscore-prefixed backup of it
if [[ -e $linkpath && ! -d $linkpath ]]; then
echo "FILE EXISTS. BACKING UP: $linkpath"
cp $linkpath `dirname $linkpath`/_`basename $linkpath`
fi
# if $file is a regular file, create the symlink
[[ -f $file ]] && ln -f -s $file $linkpath
done;
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
# create controlmasters directory if it does not exist
if ! [[ -e $HOME/.ssh/controlmasters ]]; then
mkdir $HOME/.ssh/controlmasters
fi