-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.zsh
80 lines (66 loc) · 2.21 KB
/
git.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
75
76
77
78
79
80
#####################################################################
SETUP__GIT() {
local SOURCES_DIR="${XDG_DATA_HOME:-${HOME}/.local/share}/project-source-code"
SOURCE_DIR="${DOTWRYN_PATH}" \
TARGET_DIR="${SOURCES_DIR}/yage/dotwryn" \
REMOTE_UPSTREAMS=(
'[email protected]:wrynegade/dotwryn.git'
'[email protected]:wrynegade/dotwryn.git'
'[email protected]:wrynegade/dotwryn.git'
) SETUP__GIT__REMOTES '.wryn'
SOURCE_DIR="${DOTWRYN_PATH}/zsh/plugins/code-activator" \
TARGET_DIR="${SOURCES_DIR}/zsh/code-activator" \
REMOTE_UPSTREAMS=(
'[email protected]:zsh/code-activator.git'
'[email protected]:wrynegade/code-activator.git'
) SETUP__GIT__REMOTES 'zsh-plugins/code-activator'
SOURCE_DIR="${DOTWRYN_PATH}/zsh/plugins/scwrypts" \
TARGET_DIR="${SOURCES_DIR}/zsh/scwrypts" \
REMOTE_UPSTREAMS=(
'[email protected]:zsh/scwrypts'
'[email protected]:wrynegade/scwrypts'
) SETUP__GIT__REMOTES 'zsh-plugins/scwrypts'
return 0
}
SETUP__GIT__REMOTES() {
: \
&& [ "${SOURCE_DIR}" ] \
&& [ "${TARGET_DIR}" ] \
&& [[ ${#REMOTE_UPSTREAMS[@]} -gt 0 ]] \
|| return 1
[ "$1" ] && STATUS "updating remotes for '$1'"
git -C "${SOURCE_DIR}" remote rm upstream 2>/dev/null
git -C "${SOURCE_DIR}" remote add upstream ${REMOTE_UPSTREAMS[1]}
local REMOTE_UPSTREAM
for REMOTE_UPSTREAM in ${REMOTE_UPSTREAMS[@]}
do
git -C "${SOURCE_DIR}" remote set-url --add --push upstream "${REMOTE_UPSTREAM}"
case ${REMOTE_UPSTREAM} in
git -C "${SOURCE_DIR}" remote rm github 2>/dev/null
git -C "${SOURCE_DIR}" remote add github "${REMOTE_UPSTREAM}"
;;
git -C "${SOURCE_DIR}" remote rm yage 2>/dev/null
git -C "${SOURCE_DIR}" remote add yage "${REMOTE_UPSTREAM}"
;;
git -C "${SOURCE_DIR}" remote rm bitbucket 2>/dev/null
git -C "${SOURCE_DIR}" remote add bitbucket "${REMOTE_UPSTREAM}"
;;
esac
done
SOURCE_DIR="${SOURCE_DIR}" TARGET_DIR="${TARGET_DIR}" SETUP__GIT__LINK_TO_PROJECTS || {
WARNING "failed to link '${TARGET_DIR}'"
}
return 0
}
SETUP__GIT__LINK_TO_PROJECTS() {
[ "${TARGET_DIR}" ] && [ "${SOURCE_DIR}" ] \
|| return 1
{
mkdir -p "${TARGET_DIR}"
rm "${TARGET_DIR}/code"
ln -s "${SOURCE_DIR}" "${TARGET_DIR}/code"
} &>/dev/null
}