-
Notifications
You must be signed in to change notification settings - Fork 4
/
vscode.sh
executable file
·63 lines (49 loc) · 1.25 KB
/
vscode.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
#!/bin/sh
LOCAL="$1"
REMOTE="$2"
# Sanitize LOCAL path
if [[ ! "$LOCAL" =~ ^/ ]]; then
LOCAL=$(echo "$LOCAL" | sed -e 's/^\.\///')
LOCAL="$PWD/$LOCAL"
fi
# Sanitize REMOTE path
if [[ ! "$REMOTE" =~ ^/ ]]; then
REMOTE=$(echo "$REMOTE" | sed -e 's/^\.\///')
REMOTE="$PWD/$REMOTE"
fi
MERGING="$4"
BACKUP="/tmp/$(date +"%Y%d%m%H%M%S")"
CMD=$(which code)
if [ ! $CMD ] >/dev/null; then
if [ -e '/usr/local/bin/code' ]; then
CMD='/usr/local/bin/code'
fi
fi
if [ ! -x "$CMD" ]; then
echo "Visual Studio Code command line tool 'code' could not be found. Please make sure it has been installed in /usr/local/bin/." >&2
exit 128
fi
if [ -n "$MERGING" ]; then
MERGE="$4"
# Sanitize MERGE path
if [[ ! "$MERGE" =~ ^/ ]]; then
MERGE=$(echo "$MERGE" | sed -e 's/^\.\///')
MERGE="$PWD/$MERGE"
if [ ! -f "$MERGE" ]; then
# For conflict "Both Added", Git does not pass the merge param correctly in current versions
MERGE=$(echo "$LOCAL" | sed -e 's/\.LOCAL\.[0-9]*//')
fi
fi
sleep 1 # required to create different modification timestamp
touch "$BACKUP"
"$CMD" --wait "$MERGE"
else
"$CMD" --wait --diff "$LOCAL" "$REMOTE"
fi
if [ -n "$MERGING" ]; then
# Check if the merged file has changed
if [ "$MERGE" -ot "$BACKUP" ]; then
exit 1
fi
fi
exit 0