-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup_dotfiles.sh
More file actions
executable file
·107 lines (95 loc) · 2.07 KB
/
setup_dotfiles.sh
File metadata and controls
executable file
·107 lines (95 loc) · 2.07 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
#!/bin/bash
#
# Alex's setup script.
#
# Install the dotfiles in my repository into the current home directory
# using symbolic links.
#
# This script assumes it is in the repository and all dotfiles need
# to go to $HOME
#
# Link a file to an actual dotfile
function link_dotfile
{
orig_file=$1
dot_file=$2
# echo "orig_file: $orig_file: dot_file: $dot_file"
# If the dotfile is already linked we will skip
if [[ $orig_file -ef $dot_file ]] ; then
echo "skipping symlink at $dot_file (linked to $orig_file)"
else
if [ -f $dot_file ] ; then
echo "backing up $dot_file"
mv $dot_file ${dot_file}.orig
fi
# If there is stuff left over then remove it
if [ -e $dot_file ] ; then
rm $dot_file
fi
orig_link=`pwd`/$orig_file
echo "Linking $orig_link to $dot_file"
ln -s $orig_link $dot_file
fi
}
# Links files in a dot directory
function link_dotdir
{
dir=$1
for file in $(find $dir -xtype f)
do
dotfile=`echo $file | sed s#dot#${HOME}/\.#`
destdir=`dirname $dotfile`
mkdir -p $destdir
link_dotfile $file $dotfile
done
}
# Process all files/directories starting with dot:
for x in dot*
do
if [ -f $x ]; then
file=$x
dotfile=`echo $file | sed s/dot/\./`
dotfilepath=$HOME/$dotfile
link_dotfile $file $dotfilepath
elif [[ -d $x && -e $x/setup.sh ]]; then
$x/setup.sh
fi
done
#
# Some hosts may have a subtle different setup for their
# dotfiles. Lets deal with them here
#
host=`hostname`
for file in ${host}_dot*
do
# echo "meep:$file"
if [ -e "$file" ] ; then
dotfile=`echo $file | sed s/${host}_dot/\./`
dotfilepath=$HOME/$dotfile
link_dotfile $file $dotfilepath
fi
done
#
# We also might want slightly different setups for user profiles
#
for file in ${USER}_dot*
do
# echo "meep:$file"
if [ -e "$file" ] ; then
dotfile=`echo $file | sed s/${USER}_dot/\./`
dotfilepath=$HOME/$dotfile
link_dotfile $file $dotfilepath
fi
done
#
# Also deal with scripts
#
mkdir -p $HOME/bin
cd bin
for file in *
do
if [ -e "$file" ] ; then
link_dotfile $file $HOME/bin/${file%%.sh}
fi
done
cd -