Skip to content

Commit b51d50e

Browse files
JohnJohn
authored andcommitted
[feat] use configuration files
1 parent ae9f663 commit b51d50e

File tree

1 file changed

+54
-19
lines changed

1 file changed

+54
-19
lines changed

asimov

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,60 @@ set -Eeu -o pipefail
1818
# @license MIT
1919

2020
readonly ASIMOV_ROOT=~
21+
readonly ASIMOV_CONFIG_DIR=~/.asimov
22+
readonly ASIMOV_VENDOR_DIR_SENTINELS_FILE=${ASIMOV_CONFIG_DIR}/sentinels
23+
readonly ASIMOV_SKIP_PATHS_FILE=${ASIMOV_CONFIG_DIR}/skip
24+
25+
# create config folder
26+
if [ ! -d "${ASIMOV_CONFIG_DIR}" ]
27+
then
28+
echo "create config folder ${ASIMOV_CONFIG_DIR}"
29+
mkdir ${ASIMOV_CONFIG_DIR}
30+
fi
2131

2232
# Paths to unconditionally skip over. This prevents Asimov from modifying the
2333
# Time Machine exclusions for these paths (and decendents). It has an important
2434
# side-effect of speeding up the search.
25-
readonly ASIMOV_SKIP_PATHS=(
26-
~/.Trash
27-
~/Library
28-
)
35+
if [ ! -f "$ASIMOV_SKIP_PATHS_FILE" ]; then
36+
echo "init config file ${ASIMOV_SKIP_PATHS_FILE}"
37+
echo "~/.Trash" >> ${ASIMOV_SKIP_PATHS_FILE}
38+
echo "~/Library" >> ${ASIMOV_SKIP_PATHS_FILE}
39+
fi
40+
41+
ASIMOV_SKIP_PATHS=()
42+
while IFS= read -r line || [[ "$line" ]]; do
43+
ASIMOV_SKIP_PATHS+=("$(eval echo "$line")")
44+
done < ${ASIMOV_SKIP_PATHS_FILE}
45+
2946

3047
# A list of "directory"/"sentinel" pairs.
3148
#
3249
# Directories will only be excluded if the dependency ("sentinel") file exists.
3350
#
3451
# For example, 'node_modules package.json' means "exclude node_modules/ from the
3552
# Time Machine backups if there is a package.json file next to it."
36-
readonly ASIMOV_VENDOR_DIR_SENTINELS=(
37-
'.build Package.swift' # Swift
38-
'.packages pubspec.yaml' # Pub (Dart)
39-
'.stack-work stack.yaml' # Stack (Haskell)
40-
'.vagrant Vagrantfile' # Vagrant
41-
'Carthage Cartfile' # Carthage
42-
'Pods Podfile' # CocoaPods
43-
'bower_components bower.json' # Bower (JavaScript)
44-
'node_modules package.json' # npm, Yarn (NodeJS)
45-
'target Cargo.toml' # Cargo (Rust)
46-
'target pom.xml' # Maven
47-
'build build.gradle' # Gradle
48-
'vendor composer.json' # Composer (PHP)
49-
'vendor Gemfile' # Bundler (Ruby)
50-
)
53+
if [ ! -f "$ASIMOV_VENDOR_DIR_SENTINELS_FILE" ]
54+
then
55+
echo "init config file ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}"
56+
echo ".build Package.swift # Swift" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
57+
echo ".packages pubspec.yaml # Pub (Dart)" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
58+
echo ".stack-work stack.yaml # Stack (Haskell)" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
59+
echo ".vagrant Vagrantfile # Vagrant" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
60+
echo "Carthage Cartfile # Carthage" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
61+
echo "Pods Podfile # CocoaPods" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
62+
echo "bower_components bower.json # Bower (JavaScript)" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
63+
echo "node_modules package.json # npm, Yarn (NodeJS)" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
64+
echo "target Cargo.toml # Cargo (Rust)" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
65+
echo "target pom.xml # Maven" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
66+
echo "build build.gradle # Gradle" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
67+
echo "vendor composer.json # Composer (PHP)" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
68+
echo "vendor Gemfile # Bundler (Ruby)" >> ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
69+
fi
70+
71+
ASIMOV_VENDOR_DIR_SENTINELS=()
72+
while IFS= read -r line || [[ "$line" ]]; do
73+
ASIMOV_VENDOR_DIR_SENTINELS+=("$line")
74+
done < ${ASIMOV_VENDOR_DIR_SENTINELS_FILE}
5175

5276
# Exclude the given paths from Time Machine backups.
5377
# Reads the newline-separated list of paths from stdin.
@@ -69,12 +93,23 @@ exclude_file() {
6993
# Iterate over the skip directories to construct the `find` expression.
7094
declare -a find_parameters_skip=()
7195
for d in "${ASIMOV_SKIP_PATHS[@]}"; do
96+
# safety against empty lines in the config file
97+
if [ -z "${d}" ]
98+
then
99+
continue
100+
fi
72101
find_parameters_skip+=( -not \( -path "${d}" -prune \) )
73102
done
74103

75104
# Iterate over the directory/sentinel pairs to construct the `find` expression.
76105
declare -a find_parameters_vendor=()
77106
for i in "${ASIMOV_VENDOR_DIR_SENTINELS[@]}"; do
107+
# safety against empty lines in the config file
108+
if [ -z "${i}" ]
109+
then
110+
continue
111+
fi
112+
78113
read -ra parts <<< "${i}"
79114

80115
# Add this folder to the `find` list, allowing a single `find` command to find all

0 commit comments

Comments
 (0)