-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall
More file actions
executable file
·58 lines (46 loc) · 1.65 KB
/
Copy pathinstall
File metadata and controls
executable file
·58 lines (46 loc) · 1.65 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
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BACKUP_DIR=$HOME/dotfiles_backup
LOCAL_DOTFILES_DIR=$HOME/local_dotfiles
IGNORE_LIST="$(basename $0) README.md"
run_git_submodule_update()
{
cd $DIR
git submodule update --init --recursive
if [[ $? != 0 ]]; then
echo "Can't install git repository's submodules."
cd - > /dev/null
return 1
fi
cd - > /dev/null
}
if [[ -d $BACKUP_DIR && $1 != "-f" ]]; then
echo "Backup direcory ($BACKUP_DIR) already exist. use -f to force (and delete it)."
exit 1
fi
mkdir -p $LOCAL_DOTFILES_DIR
run_git_submodule_update
echo "Creating symbolic links to your dotfiles."
if [[ -d $BACKUP_DIR ]]; then
rm -rf $BACKUP_DIR # not removing with * and using else to mkdir cause dotfiles won't be deleted.
fi
mkdir $BACKUP_DIR
for file in $(ls $DIR); do
if [[ $IGNORE_LIST != *$file* ]]; then # not linking files in the ignore list (like this script)
if [[ -L $HOME/.$file ]]; then # if file is a link then delete it.
rm $HOME/.$file
elif [[ -a $HOME/.$file ]]; then # if a real existing file, then back it up.
mv $HOME/.$file $BACKUP_DIR/
fi
ln -s $DIR/$file $HOME/.$file # create link to repository dotfiles.
fi
done
if [[ $(ls -A $BACKUP_DIR | wc -l) = 0 ]]; then # clear backup dir if still empty
rmdir $BACKUP_DIR
else
echo "Backup dotfiles were created at: $BACKUP_DIR"
fi
curl -o ~/.git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
echo "Runing vim to download plugins."
yes | vim -c "q"