forked from SciRooPlot/SciRooPlot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.plotrc
174 lines (152 loc) · 4.77 KB
/
.plotrc
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
# add some global symbols
if [[ "${BASH_SOURCE[0]}" != "" ]]; then
__PLOTTING_FRAMEWORK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
else
__PLOTTING_FRAMEWORK_DIR="$( cd "$( dirname "${0}" )" >/dev/null 2>&1 && pwd )"
fi
export __PLOTTING_FRAMEWORK_DIR
__PLOTTING_BUILD_DIR="${__PLOTTING_FRAMEWORK_DIR}/build"
export __PLOTTING_BUILD_DIR
if [[ -d "${__PLOTTING_BUILD_DIR}" ]]; then
function plot() {
if [[ "${1}" == "cd" ]]; then
cd ${__PLOTTING_BUILD_DIR}
return 0
fi
local USER_EXEC=$(${__PLOTTING_BUILD_DIR}/plot-config get executable)
local USER_BUILD_DIR=$(dirname ${USER_EXEC})
if [[ -d ${USER_BUILD_DIR} ]]; then
local USER_PLOTDEF=$(${__PLOTTING_BUILD_DIR}/plot-config get plotDefinitions)
(
cd ${USER_BUILD_DIR};
(make 1> /dev/null) || exit 1
if [[ ! -f ${USER_PLOTDEF} || -z $(find ${USER_EXEC} -mmin +1) ]]; then
${USER_EXEC}
fi
) || return 1
else
return 1
fi
"${__PLOTTING_BUILD_DIR}/plot" ${1} ${2} ${3}
return 0
}
function plot-config() {
"${__PLOTTING_BUILD_DIR}/plot-config" ${1} ${2} ${3} ${4}
}
fi
_plot_completions_zsh() {
local modes=('interactive' 'pdf' 'eps' 'svg' 'png' 'gif' 'file' 'find' 'macro')
local groups
local groupsAndCategories
local names
local AUTOCOMPFILE="${__PLOTTING_BUILD_DIR}/plots_$(${__PLOTTING_BUILD_DIR}/plot-config get active).csv"
${__PLOTTING_FRAMEWORK_DIR}/scripts/prepare_autocomplete.sh $AUTOCOMPFILE
if [[ ! -f "$AUTOCOMPFILE" ]]; then
return
fi
# first find groups and groups including categories
while IFS="," read -r plotName figureGroup figureCategory
do
groups+=("${figureGroup}")
[ -n "$figureCategory" ] && groupsAndCategories+=("${figureGroup}/${figureCategory}")
done < $AUTOCOMPFILE
unset plotName figureGroup figureCategory
updatePlotNames() {
local groupAndCat=$1
IFS="/" read -r group category <<< "$groupAndCat"
names=()
while IFS="," read -r plotName figureGroup figureCategory
do
if [[ "${group}" == "${figureGroup}" ]]; then
if [[ -n "${category}" && ! ( "${category}" == "${figureCategory}" || "${figureCategory}" == "${category}/"* ) ]]; then
continue
fi
names+=("${plotName}")
fi
done < $AUTOCOMPFILE
}
_arguments \
'1: :->group'\
'2: :->name'\
'3: :->mode'
case $state in
group)
if [[ "${words[2]}" == *"/"* ]]; then
_arguments '1:profiles:(${groupsAndCategories})'
else
_arguments '1:profiles:(${groups})'
fi
;;
name)
if [[ "${words[2]}" == "cd" ]]; then
_arguments '2:profiles:()'
else
updatePlotNames $words[2]
_arguments '2:profiles:(${names})'
fi
;;
mode)
_arguments '3:profiles:(${modes})'
;;
esac
unset -f updatePlotNames
}
_plot_completions_bash() {
local modes=('interactive pdf eps svg png gif file find macro')
local groups
local groupsAndCategories
local names
local AUTOCOMPFILE="${__PLOTTING_BUILD_DIR}/plots_$(${__PLOTTING_BUILD_DIR}/plot-config get active).csv"
${__PLOTTING_FRAMEWORK_DIR}/scripts/prepare_autocomplete.sh $AUTOCOMPFILE
if [[ ! -f "$AUTOCOMPFILE" ]]; then
return
fi
# first find groups and groups including categories
while IFS="," read -r plotName figureGroup figureCategory
do
groups+=" ${figureGroup}"
[ -n "$figureCategory" ] && groupsAndCategories+=" ${figureGroup}/${figureCategory}"
done < $AUTOCOMPFILE
unset plotName figureGroup figureCategory
updatePlotNames() {
local groupAndCat=$1
IFS="/" read -r group category <<< "$groupAndCat"
names=()
while IFS="," read -r plotName figureGroup figureCategory
do
if [[ "${group}" == "${figureGroup}" ]]; then
if [[ -n "${category}" && ! ( "${category}" == "${figureCategory}" || "${figureCategory}" == "${category}/"* ) ]]; then
continue
fi
names+=" ${plotName}"
fi
done < $AUTOCOMPFILE
}
case $COMP_CWORD in
1)
if [[ "${COMP_WORDS[COMP_CWORD]}" == *"/"* ]]; then
COMPREPLY=( $(compgen -W "${groupsAndCategories}" -- "${COMP_WORDS[COMP_CWORD]}") )
else
COMPREPLY=( $(compgen -W "${groups}" -- "${COMP_WORDS[COMP_CWORD]}") )
fi
;;
2)
if [[ "${COMP_WORDS[COMP_CWORD-1]}" == "cd" ]]; then
COMPREPLY=( )
else
updatePlotNames "${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=( $(compgen -W "${names}" -- "${COMP_WORDS[COMP_CWORD]}") )
fi
;;
3)
COMPREPLY=( $( compgen -W "${modes}" -- "${COMP_WORDS[COMP_CWORD]}" ) )
;;
esac
unset -f updatePlotNames
}
if command -v compdef &> /dev/null; then
compdef _plot_completions_zsh plot
elif command -v complete &> /dev/null; then
complete -F _plot_completions_bash plot
fi