-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdotfiles.plugin.zsh
74 lines (65 loc) · 1.45 KB
/
dotfiles.plugin.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function dotfiles_gitInclude {
pwd=$(pwd)
filepath=".gitinclude"
while IFS= read -r line
do
git add -f "$line"
done < "$filepath"
}
function dotfiles_hasStagedFiles {
diffList=$(git diff --name-only --cached | cat)
[ ! -z ${diffList// } ] && return
false
}
function dotfiles_gitStage {
dotfiles_gitInclude
git add .
if dotfiles_hasStagedFiles;
then
cGreen='\033[0;32m'
cNone='\033[0m'
echo -e "Staged changes:\n${cGreen}$(git diff --name-only --cached | cat)${cNone}"
fi
}
function dotfiles_gitCommit {
if dotfiles_hasStagedFiles;
then
git commit -m "$(date +%Y.%m.%d_%H:%M:%S) from $(whoami)@$(hostname)"
fi
}
function dotfiles_gitStageCommit {
dotfiles_gitStage
dotfiles_gitCommit
}
function dotfiles_gitUpload {
dotfiles_gitStage
dotfiles_gitCommit
git push
}
function dotfiles_gitDownload {
git pull --rebase
}
function dotfiles {
local current_dir=$(pwd)
cd ~
if [ "$1" = "-u" ] || [ "$1" = "--upload" ]
then
dotfiles_gitUpload
elif [ "$1" = "-d" ] || [ "$1" = "--download" ]
then
dotfiles_gitDownload
elif [ "$1" = "-c" ] || [ "$1" = "--commit" ]
then
dotfiles_gitStageCommit
else
echo "\
Dotfiles synchronization tool.
Options:
-c, --commit commit changes in dotfiles
-u, --upload upload dotfiles to remote repository
-d, --download download dotfiles from remote repository
-h, --help print usage interface\
"
fi
cd $current_dir
}