-
Notifications
You must be signed in to change notification settings - Fork 0
/
add2dotf.sh
executable file
·44 lines (38 loc) · 1.22 KB
/
add2dotf.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
#!/bin/bash
# ADD 2 DOTFiles (add2dotf)
#
# ---
# Move file(s) to dotfiles repository, then add a sym link to the new location
#
# .dotfile --> add2dotf.sh
# ==> $HomeDir/path/to/.dotfile --moved--> $DotfileDir/path/to/.dotfile
# ==> $DotfileDir/path/to/.dotfile --symlink--> $HomeDir/path/to/.dotfile
#
# ...where by default:
# HomeDir=$HOME
# CurrentDir=$(pwd -P)
# DotfileDir="$HomeDir/gitRepos/dotfiles2.0"
set -e # Stop script on any error
if [[ $SUDO_USER ]]; then
echo "Running scripts you find on the internet as root is dangerous. Try again without 'sudo'."
exit 1
fi
HomeDir=$HOME
CurrentDir=$(pwd -P)
DotfileDir=$HomeDir'/gitRepos/dotfiles2.0'
for filepath in $@
do
echo WORKING ON $filepath .................
if [[ -d ${filepath} ]]; then
echo $filepath 'is a directory, skipping'
break
fi
filepath2home=$(realpath --relative-to=$HomeDir $filepath)
filepath2homedir=$(dirname $filepath2home)
mkdir -p $DotfileDir/$filepath2homedir
newfilepath=$DotfileDir/$filepath2home
oldfilepath=$HomeDir/$filepath2home
echo $oldfilepath '--mv-->' $newfilepath
echo $newfilepath '--symlink-->' $oldfilepath
mv -f $oldfilepath $newfilepath && ln -s $newfilepath $oldfilepath
done