forked from duzun/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·73 lines (60 loc) · 1.8 KB
/
init.sh
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
#!/bin/bash
# @author Dumitru Uzun (DUzun.Me)
# @version 1.3.0
# A method to move existing .profile to .extend.profile or .profile.bak
function toextend() {
local name=$1
if [ -s ~/".$name" ] && [ ! -L ~/".$name" ]; then
local extend=.extend.$name
if [ -s ~/"$extend" ]; then
[ -s ~/".$name.bak" ] && echo "Overwriting ~/.$name.bak"
mv ~/".$name" ~/".$name.bak"
else
# Old .profile becomes .extend.profile
mv ~/".$name" ~/"$extend"
# Avoid recursive sourcing
sed -ri "s/((^|^[^#]*\s)(\.|source)\s+(\~|\\\$HOME)\/$extend)/#\\1/" ~/$extend
fi
fi
}
toextend profile
toextend aliasrc
unset -f toextend
p="$(dirname "$0")"
# Make sure there is `realpath` command, if not, compile it
_e=
if ! command -v realpath > /dev/null; then
. "$p/src/realpath/.realpath"
fi
p="$(realpath "$p")/~"
ln -sf "$p/.profile" ~/
ln -sf "$p/.aliasrc" ~/
ln -s "$p/.gitignore" ~/
ln -s "$p/.curlrc" ~/
ln -s "$p/.vimrc" ~/
ls -a "$p" | grep '^\.extend\.' | while read -r i; do
_mark="#dotfiles: $i";
if [ -e ~/"$i" ] && grep "$_mark" ~/"$i" > /dev/null; then
echo "$i not updated"
else
echo "Updating $i ..."
{
echo "";
cat "$p/$i";
echo "";
echo "$_mark";
} >> ~/"$i";
fi
done
. ~/.profile
# Try to take care of sourcing .profile automatically
if [ -n "$SHELL" ] && [ -f ~/".${SHELL##*/}rc" ]; then
_rc=~/".${SHELL##*/}rc";
if ! grep ". ~/.profile" "$_rc" > /dev/null && ! grep "source ~/.profile" "$_rc" > /dev/null; then
echo "Adding '. ~/.profile' to $_rc ..."
echo "" >> "$_rc"
echo ". ~/.profile" >> "$_rc"
fi
fi
"$p"/../init_git.sh
[ ! -z "$_e" ] && [ "$_e" -eq "1" ] && shopt -u expand_aliases