-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_csv.sh
36 lines (29 loc) · 1018 Bytes
/
make_csv.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
#!/bin/bash
# Usage: ./make_csv.sh <path_to_source_code> <path_to_csv_csv_file>
mk_alias_csv_file_from_alias_source_code() {
local alias_source_code_file_path=$1
local alias_csv_file_path=$2
# Remove lines starting with '#'
grep -v '^#' $alias_source_code_file_path | \
# Remove 'alias ' at the start of each line
perl -pe 's/^alias //' | \
# Replace '=' with ','
perl -pe "s/='/,/" | \
# Remove trailing quote
perl -pe "s/'$//" | \
# Remove blank lines
grep -v '^$' > "$alias_csv_file_path"
}
function main(){
# Get all alias files and insert them into a array
files=(`ls .zsh/*/alias.zsh`)
for source_code_file_path in "${files[@]}"; do
# Get alias csv file path
csv_file_path="${source_code_file_path#.zsh/}" # remove the prefix
csv_file_path="${csv_file_path%/alias.zsh}" # remove the suffix
csv_file_path=".zsh/doc/alias/${csv_file_path}.csv"
# Make csv file
mk_alias_csv_file_from_alias_source_code $source_code_file_path $csv_file_path
done
}
main