-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldfs
executable file
·74 lines (63 loc) · 1.67 KB
/
ldfs
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
#!/bin/bash
#
# Local Development Files Storage
#
# usage:
# ldfs Restore all storaged files to use in development
# ldfs [file] Store file in storage
# git checkout [file] Restore original file managed in remote repository
#
# description:
# store files only to use in local development
# ldfs is enable only in git repository
#
################################################################################
: "Define constant" && {
SEP_CHAR="^"
LDFS_DIR_NAME=".ldfs"
IGNORED_FILE_NAME=".ignored"
}
: "Move current directory to git toplevel" && {
GIT_ROOT=$(git rev-parse --show-toplevel 2> /dev/null)
if [[ $? != 0 || "$GIT_ROOT" == "" ]]; then
echo "ldfs is enable only in git repository"
exit 1
fi
LDFS_DIR=$GIT_ROOT/$LDFS_DIR_NAME
}
create_storage() {
if [[ ! -d $LDFS_DIR ]]; then
mkdir $LDFS_DIR
fi
touch $LDFS_DIR/$IGNORED_FILE_NAME
if [[ ! "$(git ls-files --other --ignored --exclude-standard $GIT_ROOT | grep $LDFS_DIR_NAME)" ]]; then
echo "Warning: Please add \".ldfs/\" to .gitignore"
fi
}
store() {
for f in ${@:1}
do
if [[ "$(echo $f | grep \\$SEP_CHAR)" ]]; then
echo "sorry, $f include \"$SEP_CHAR\", and can't be managed by ldfs"
continue
fi
af=$(echo "$(pwd -P)/$f" | tr / $SEP_CHAR)
cp $f $LDFS_DIR/$af.ldf
echo "store $f"
done
}
restore() {
for f in $LDFS_DIR/*.ldf
do
af=$(basename ${f%.ldf} | tr $SEP_CHAR /)
cp $f $af
done
}
: "Route arguments" && {
create_storage
if [[ $# == 0 ]]; then
restore
exit 0
fi
store $@
}