-
Notifications
You must be signed in to change notification settings - Fork 0
/
cplatex.sh
executable file
·52 lines (38 loc) · 1003 Bytes
/
cplatex.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
#/bin/sh
#
# Copy LaTeX project to another directory
# (only .tex, .bib, .cls files and figures in the Images directory)
#
# Example:
# cd /path/to/my/latex_project
# /path/to/cplatex.sh /path/to/parent/dst
#
declare -a masks=("*.tex" "*.cls" "*.bib")
if [ -z "$1" ]; then # checks for empty string
echo "Parent directory is empty. Using $HOME/Desktop"
parent_dir="$HOME/Desktop"
else
parent_dir=$1
fi
current_dir_name=${PWD##*/} # top-level name of the current directory
out_dir="$parent_dir/$current_dir_name"
if [ -d "$out_dir" ]; then # if the directory exists
echo "Directory $out_dir already exists. Exiting"
exit 1
fi
mkdir $out_dir
for mask in "${masks[@]}"
do
if ls $mask 1> /dev/null 2>&1; then
cp -r $mask $out_dir
fi
done
mkdir "$out_dir/Images"
for fig_file in Images/*
do
# Copy files, not directories
if [ -f "$fig_file" ]; then
cp "$fig_file" "$out_dir/Images"
fi
done
echo "Done: copied the project to $out_dir"