-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-setup-filters
99 lines (94 loc) · 3.06 KB
/
git-setup-filters
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
# Canonical : https://github.com/lduran2/git-clean-each-ipynb/blob/master/git-setup-filters
# Configures the filters for Jupyter Notebooks.
# By : Leomar Durán <https://github.com/lduran2/>
# When : 2022-03-04t03:35R
# Where : Temple University
# For : CIS 4526
# Version : 1.3.2
#
# CHANGELOG :
# v1.3.2 - 2022-03-04t03:35R
# the config script in a new process
#
# v1.3.1 - 2022-03-04t03:14R
# sourced the config script
#
# v1.3.0 - 2022-03-04t02:57R
# split from `git-config-filters`
#
# v1.2.8 - 2022-01-31t22:13R
# added blank line before template
#
# v1.2.7 - 2022-01-31t20:57R
# staging configuration files automatically
#
# v1.2.6 - 2022-01-30t20:05R
# restored `git config ...`
#
# v1.2.5 - 2022-01-30t19:42R
# added `.gitattributes` to `tail_templates`
# removed parentheses from `echo 'Done.'`
#
# v1.2.4 - 2022-01-30t19:15R
# put templates in `for` loop
# accidentally removed `git config ...`
#
# v1.2.3 - 2022-01-30t19:01R
# templates copied to root
#
# v1.2.2 - 2022-01-30t17:18R
# filter will call `main` instead of `sed` directly
#
# v1.2.1 - 2021-12-05t03:57
# combined both filters in .gitattribute and renamed the
# combined filter in to `ipynb`
# now filtering successfully
#
# v1.2.0 - 2021-12-05t03:32
# /config-filters -> ./git-config-filters :
# combined both filters
#
# v1.1.2 - 2021-12-05t02:23
# hw4-sklearn_mlp/config-filters -> ../config-filters .
#
# v1.1.1 - 2021-12-05t02:14
# hw4-sklearn_mlp/config-filters :
# fixed typo in range for `cell_id` filter :
# [a-zA-Z0-9-_] -> [a-zA-Z0-9_]
#
# v1.1.0 - 2021-12-05t02:14
# hw4-sklearn_mlp/config-execution_count-filter.sh -> ./config-filters :
# added filter `cell_id` to ignore lines updating cell IDs
#
# v1.0.0 - 2021-12-05t01:55
# hw4-sklearn_mlp/config-execution_count-filter.sh :
# set filter `execution_count` to null out execution_count
# on `git add`
#
# working directories
declare -r SOURCE_DIR=$(dirname $0)
declare -r ROOT_DIR="$SOURCE_DIR/../.."
declare -r TEMPLATES_DIR="$SOURCE_DIR/templates"
# template files to append to root configuration files
declare -a tail_templates=(.gitignore .gitattributes)
# add each tail template to the corresponding config
for config in "${tail_templates[@]}"; do
root_config="$ROOT_DIR/$config"
echo "Adding to and staging $config . . ."
# redirect to the root configuration
{
# blank line before template if the $root_config already exists
if [[ -f "$root_config" ]]; then
echo
fi # [[ -f "$root_config" ]]
# read the tail tempate
cat "$TEMPLATES_DIR/$config"
} >> "$root_config"
# stage the configuration (in case it is not already)
git add "$root_config"
done # for config in "${tail_templates[@]}"
echo 'Configuring *.ipynb clean filter . . .'
$SOURCE_DIR/git-config-filters
# confirm finished
echo 'Done.'