Rev 3 | Rev 5 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3 | Rev 4 | ||
---|---|---|---|
1 | #!/bin/bash |
1 | #!/bin/bash |
2 | 2 | ||
3 | # Get the directory of this script (also works with symlinks) |
3 | # Get the directory of this script (also works with symlinks) |
4 | # http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in |
4 | # http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in |
5 | SOURCE="${BASH_SOURCE[0]}" |
5 | SOURCE="${BASH_SOURCE[0]}" |
6 | while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink |
6 | while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink |
7 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
7 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
8 | SOURCE="$(readlink "$SOURCE")" |
8 | SOURCE="$(readlink "$SOURCE")" |
9 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located |
9 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located |
10 | done |
10 | done |
11 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
11 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
12 | 12 | ||
13 | # ToDo for Future: Implement getopt |
13 | # ToDo for Future: Implement getopt |
14 | if [[ "$1" == "--batchmode" ]]; then |
14 | if [[ "$1" == "--batchmode" ]]; then |
15 | IS_BATCHMODE=1 |
15 | IS_BATCHMODE=1 |
16 | else |
16 | else |
17 | IS_BATCHMODE=0 |
17 | IS_BATCHMODE=0 |
18 | fi |
18 | fi |
19 | 19 | ||
20 | # Read in the system identifier |
20 | # Read in the system identifier |
21 | if [ $IS_BATCHMODE -eq 0 ]; then |
21 | if [ $IS_BATCHMODE -eq 0 ]; then |
22 | echo "Terminal Stackman 2.3" |
22 | echo "Terminal Stackman 2.4" |
23 | echo "(C) 2013-2017 ViaThinkSoft" |
23 | echo "(C) 2013-2019 ViaThinkSoft" |
24 | echo "" |
24 | echo "" |
25 | 25 | ||
26 | if [ -f ~/".autorun" ]; then |
26 | if [ -f ~/".autorun" ]; then |
27 | echo "Starting autorun script..." |
27 | echo "Starting autorun script..." |
28 | ~/".autorun" |
28 | ~/".autorun" |
29 | echo "" |
29 | echo "" |
30 | fi |
30 | fi |
31 | 31 | ||
32 | sysid=$( "$DIR"/sysname ) |
32 | sysid=$( "$DIR"/sysname ) |
33 | echo "System ID: lta:$sysid" |
33 | echo "System ID: lta:$sysid" |
34 | echo "" |
34 | echo "" |
35 | echo "Enter '-help' for available commands." |
35 | echo "Enter '-help' for available commands." |
36 | echo "" |
36 | echo "" |
37 | fi |
37 | fi |
38 | 38 | ||
39 | # Check MySQL config |
39 | # Check MySQL config |
40 | "$DIR"/check_db_conn -q |
40 | "$DIR"/check_db_conn -q |
41 | if [ $? -ne 0 ]; then |
41 | if [ $? -ne 0 ]; then |
42 | # TODO: fragen ob man write_stam_config aufrufen möchte |
42 | # TODO: fragen ob man write_stam_config aufrufen möchte |
43 | exit 1 |
43 | exit 1 |
44 | fi |
44 | fi |
45 | 45 | ||
46 | DEFAULTCAT="." |
46 | DEFAULTCAT="." |
47 | 47 | ||
48 | CURCAT="$DEFAULTCAT" |
48 | CURCAT="$DEFAULTCAT" |
49 | PREV_CAT="$DEFAULTCAT" |
49 | PREV_CAT="$DEFAULTCAT" |
50 | LAST_ID=-1 |
50 | LAST_ID=-1 |
51 | 51 | ||
52 | echo_yellow() { |
52 | echo_yellow() { |
53 | echo -ne "\033[1;33;40m" |
53 | echo -ne "\033[1;33;40m" |
54 | echo "$*" |
54 | echo "$*" |
55 | echo -ne "\033[0m" |
55 | echo -ne "\033[0m" |
56 | } |
56 | } |
57 | 57 | ||
58 | echo_red() { |
58 | echo_red() { |
59 | echo -ne "\033[1;31;40m" |
59 | echo -ne "\033[1;31;40m" |
60 | echo "$*" |
60 | echo "$*" |
61 | echo -ne "\033[0m" |
61 | echo -ne "\033[0m" |
62 | } |
62 | } |
63 | 63 | ||
64 | echo_cyan() { |
64 | echo_cyan() { |
65 | echo -ne "\033[1;36;40m" |
65 | echo -ne "\033[1;36;40m" |
66 | echo "$*" |
66 | echo "$*" |
67 | echo -ne "\033[0m" |
67 | echo -ne "\033[0m" |
68 | } |
68 | } |
69 | 69 | ||
70 | echo_green() { |
70 | echo_green() { |
71 | echo -ne "\033[1;32;40m" |
71 | echo -ne "\033[1;32;40m" |
72 | echo "$*" |
72 | echo "$*" |
73 | echo -ne "\033[0m" |
73 | echo -ne "\033[0m" |
74 | } |
74 | } |
75 | 75 | ||
76 | # Main menu |
76 | # Main menu |
77 | while (( 1 )); do |
77 | while (( 1 )); do |
78 | # Warning if category does not exist yet. |
78 | # Warning if category does not exist yet. |
79 | "$DIR"/exists1 "$CURCAT" |
79 | "$DIR"/exists1 "$CURCAT" |
80 | if [ $? -eq 1 ]; then |
80 | if [ $? -eq 1 ]; then |
81 | SIGN="*" |
81 | SIGN="*" |
82 | else |
82 | else |
83 | SIGN="+" |
83 | SIGN="+" |
84 | fi |
84 | fi |
85 | 85 | ||
86 | # "-r" übernimmt alle "\". gut für z.B. "\\netbios\", schlecht für "\" am zeilenende, um weiterzuschreiben |
86 | # "-r" übernimmt alle "\". gut für z.B. "\\netbios\", schlecht für "\" am zeilenende, um weiterzuschreiben |
87 | read -erp "<$CURCAT> $SIGN " inp |
87 | read -erp "<$CURCAT> $SIGN " inp |
88 | if [[ $? -gt 0 ]]; then |
88 | if [[ $? -gt 0 ]]; then |
89 | # For example end of stream -- exit |
89 | # For example end of stream -- exit |
90 | break |
90 | break |
91 | fi |
91 | fi |
92 | 92 | ||
93 | # Log to journal |
93 | # Log to journal |
94 | echo "$inp" >> ~/.stam_history |
94 | echo "$inp" >> ~/.stam_history |
95 | if [ -f ~/.stam_history_mir ]; then |
95 | if [ -f ~/.stam_history_mir ]; then |
96 | echo "$inp" >> ~/.stam_history_mir |
96 | echo "$inp" >> ~/.stam_history_mir |
97 | fi |
97 | fi |
- | 98 | "$DIR"/weblog_add "$inp" |
|
98 | 99 | ||
99 | # Split command and (single combined) argument |
100 | # Split command and (single combined) argument |
100 | cmd=$( echo "$inp" | cut -d " " -f 1 ) |
101 | cmd=$( echo "$inp" | cut -d " " -f 1 ) |
101 | arg=$( echo "$inp" | cut -s -d " " -f 2- ) |
102 | arg=$( echo "$inp" | cut -s -d " " -f 2- ) |
102 | 103 | ||
103 | # Commands begin with '-'. The first character can be escaped by using '--' |
104 | # Commands begin with '-'. The first character can be escaped by using '--' |
104 | echo "$cmd" | grep -E "^-" > /dev/null |
105 | echo "$cmd" | grep -E "^-" > /dev/null |
105 | COMMANDMODE=$? |
106 | COMMANDMODE=$? |
106 | echo "$cmd" | grep -E "^--" > /dev/null |
107 | echo "$cmd" | grep -E "^--" > /dev/null |
107 | if [ $? -eq 0 ]; then |
108 | if [ $? -eq 0 ]; then |
108 | cmd="${cmd:1}" |
109 | cmd="${cmd:1}" |
109 | # 1=nein, 0=ja |
110 | # 1=nein, 0=ja |
110 | COMMANDMODE=1 |
111 | COMMANDMODE=1 |
111 | fi |
112 | fi |
112 | 113 | ||
113 | # Category will be changed with '#'. The first character can be escaped by using '##' |
114 | # Category will be changed with '#'. The first character can be escaped by using '##' |
114 | echo "$cmd" | grep -E "^#" > /dev/null |
115 | echo "$cmd" | grep -E "^#" > /dev/null |
115 | CATCHANGE=$? |
116 | CATCHANGE=$? |
116 | echo "$cmd" | grep -E "^##" > /dev/null |
117 | echo "$cmd" | grep -E "^##" > /dev/null |
117 | if [ $? -eq 0 ]; then |
118 | if [ $? -eq 0 ]; then |
118 | cmd="${cmd:1}" |
119 | cmd="${cmd:1}" |
119 | # 1=nein, 0=ja |
120 | # 1=nein, 0=ja |
120 | CATCHANGE=1 |
121 | CATCHANGE=1 |
121 | fi |
122 | fi |
122 | 123 | ||
123 | if [ $CATCHANGE -eq 0 ]; then |
124 | if [ $CATCHANGE -eq 0 ]; then |
124 | PREV_CAT="$CURCAT" |
125 | PREV_CAT="$CURCAT" |
125 | 126 | ||
126 | # Change category: "#<cat>" |
127 | # Change category: "#<cat>" |
127 | cmd="-" |
128 | cmd="-" |
128 | arg=$( echo "$inp" | sed 's/^#//' ) |
129 | arg=$( echo "$inp" | sed 's/^#//' ) |
129 | 130 | ||
130 | # Do not allow empty category (reserved for '*') |
131 | # Do not allow empty category (reserved for '*') |
131 | if [[ "$arg" == "" ]]; then |
132 | if [[ "$arg" == "" ]]; then |
132 | # echo_red "[!] FATAL ERROR: Category cannot be empty!" |
133 | # echo_red "[!] FATAL ERROR: Category cannot be empty!" |
133 | # continue |
134 | # continue |
134 | arg="$DEFAULTCAT" |
135 | arg="$DEFAULTCAT" |
135 | fi |
136 | fi |
136 | 137 | ||
137 | # change category |
138 | # change category |
138 | CURCAT="$arg" |
139 | CURCAT="$arg" |
139 | 140 | ||
140 | # if [ $IS_BATCHMODE -eq 0 ]; then |
141 | # if [ $IS_BATCHMODE -eq 0 ]; then |
141 | # echo_green "Your category is now '$CURCAT'" |
142 | # echo_green "Your category is now '$CURCAT'" |
142 | # fi |
143 | # fi |
143 | 144 | ||
144 | # Warning if category does not exist yet. |
145 | # Warning if category does not exist yet. |
145 | "$DIR"/exists1 "$CURCAT" |
146 | "$DIR"/exists1 "$CURCAT" |
146 | if [ $? -eq 1 ]; then |
147 | if [ $? -eq 1 ]; then |
147 | echo_yellow "(i) Note: The category does not exist and will be created if you continue:" |
148 | echo_yellow "(i) Note: The category does not exist and will be created if you continue:" |
148 | echo_yellow " $CURCAT" |
149 | echo_yellow " $CURCAT" |
149 | fi |
150 | fi |
150 | elif [ $COMMANDMODE -eq 0 ]; then |
151 | elif [ $COMMANDMODE -eq 0 ]; then |
151 | # Command mode: "-<cmd> [<arg>]" |
152 | # Command mode: "-<cmd> [<arg>]" |
152 | cmd="${cmd:1}" |
153 | cmd="${cmd:1}" |
153 | 154 | ||
154 | # Kommando verarbeiten |
155 | # Kommando verarbeiten |
155 | if [[ "$cmd" == "listcat" || "$cmd" == "ls" || "$cmd" == "lc" ]]; then |
156 | if [[ "$cmd" == "listcat" || "$cmd" == "ls" || "$cmd" == "lc" ]]; then |
156 | # List categories |
157 | # List categories |
157 | "$DIR"/listcat "$arg" | less |
158 | "$DIR"/listcat "$arg" | less |
158 | elif [[ "$cmd" == "strike" || "$cmd" == "str" ]]; then |
159 | elif [[ "$cmd" == "strike" || "$cmd" == "str" ]]; then |
159 | # Strike entry |
160 | # Strike entry |
160 | if [[ "$arg" == "last" ]]; then |
161 | if [[ "$arg" == "last" ]]; then |
161 | arg=$LAST_ID |
162 | arg=$LAST_ID |
162 | fi |
163 | fi |
163 | "$DIR"/str "$arg" |
164 | "$DIR"/str "$arg" |
164 | elif [[ "$cmd" == "unstrike" || "$cmd" == "unstr" ]]; then |
165 | elif [[ "$cmd" == "unstrike" || "$cmd" == "unstr" ]]; then |
165 | # Un-Strike entry |
166 | # Un-Strike entry |
166 | if [[ "$arg" == "last" ]]; then |
167 | if [[ "$arg" == "last" ]]; then |
167 | arg=$LAST_ID |
168 | arg=$LAST_ID |
168 | fi |
169 | fi |
169 | "$DIR"/unstr "$arg" |
170 | "$DIR"/unstr "$arg" |
170 | elif [[ "$cmd" == "singleadd" || "$cmd" == "sa" || "$cmd" == "as" || "$cmd" == "appendsingle" || "$cmd" == "aps" ]]; then |
171 | elif [[ "$cmd" == "singleadd" || "$cmd" == "sa" || "$cmd" == "as" || "$cmd" == "appendsingle" || "$cmd" == "aps" ]]; then |
171 | array=(${arg// / }) |
172 | array=(${arg// / }) |
172 | CAT="${array[0]}" |
173 | CAT="${array[0]}" |
173 | TXT="${array[@]:1}" |
174 | TXT="${array[@]:1}" |
174 | 175 | ||
175 | # Warning if category does not exist yet. |
176 | # Warning if category does not exist yet. |
176 | "$DIR"/exists1 "$CAT" |
177 | "$DIR"/exists1 "$CAT" |
177 | if [ $? -eq 1 ]; then |
178 | if [ $? -eq 1 ]; then |
178 | echo_yellow "(i) Note: Category '$CAT' will be created." |
179 | echo_yellow "(i) Note: Category '$CAT' will be created." |
179 | fi |
180 | fi |
180 | 181 | ||
181 | OUT=$( "$DIR"/aps "$CAT" "$TXT" ) |
182 | OUT=$( "$DIR"/aps "$CAT" "$TXT" ) |
182 | EC=$? |
183 | EC=$? |
183 | echo -n "$OUT" |
184 | echo -n "$OUT" |
184 | if [ $EC -ne 0 ]; then |
185 | if [ $EC -ne 0 ]; then |
185 | echo_red "[!] FATAL ERROR: Could not append the entry!" 1>&2 |
186 | echo_red "[!] FATAL ERROR: Could not append the entry!" 1>&2 |
186 | else |
187 | else |
187 | LAST_ID=$( echo "$OUT" | sed -r 's/^.*OK! ([[:digit:]]+).*$/\1/g' ) |
188 | LAST_ID=$( echo "$OUT" | sed -r 's/^.*OK! ([[:digit:]]+).*$/\1/g' ) |
188 | fi |
189 | fi |
189 | elif [[ "$cmd" == "movefromid" || "$cmd" == "mfi" ]]; then |
190 | elif [[ "$cmd" == "movefromid" || "$cmd" == "mfi" ]]; then |
190 | # Move ID $arg to category $CURCAT |
191 | # Move ID $arg to category $CURCAT |
191 | if [[ "$arg" == "last" ]]; then |
192 | if [[ "$arg" == "last" ]]; then |
192 | arg=$LAST_ID |
193 | arg=$LAST_ID |
193 | fi |
194 | fi |
194 | "$DIR"/id_move "$CURCAT" "$arg" |
195 | "$DIR"/id_move "$CURCAT" "$arg" |
195 | elif [[ "$cmd" == "movefromcat" || "$cmd" == "mfc" ]]; then |
196 | elif [[ "$cmd" == "movefromcat" || "$cmd" == "mfc" ]]; then |
196 | # Move CAT $arg to category $CURCAT |
197 | # Move CAT $arg to category $CURCAT |
197 | "$DIR"/cat_move "$CURCAT" "$arg" |
198 | "$DIR"/cat_move "$CURCAT" "$arg" |
198 | elif [[ "$cmd" == "listent" || "$cmd" == "le" ]]; then |
199 | elif [[ "$cmd" == "listent" || "$cmd" == "le" ]]; then |
199 | # List entries |
200 | # List entries |
200 | "$DIR"/listent "$arg" | less |
201 | "$DIR"/listent "$arg" | less |
201 | elif [[ "$cmd" == "listcurent" || "$cmd" == "lce" ]]; then |
202 | elif [[ "$cmd" == "listcurent" || "$cmd" == "lce" ]]; then |
202 | # List current entries |
203 | # List current entries |
203 | "$DIR"/listent "$CURCAT" | less |
204 | "$DIR"/listent "$CURCAT" | less |
204 | elif [[ "$cmd" == "clear" || "$cmd" == "cls" ]]; then |
205 | elif [[ "$cmd" == "clear" || "$cmd" == "cls" ]]; then |
205 | clear |
206 | clear |
206 | elif [[ "$cmd" == "batch" || "$cmd" == "bat" ]]; then |
207 | elif [[ "$cmd" == "batch" || "$cmd" == "bat" ]]; then |
207 | TMPFIL=$( mktemp --suffix=.stam ) |
208 | TMPFIL=$( mktemp --suffix=.stam ) |
208 | # TODO: can the .nanorc file be enforced? |
209 | # TODO: can the .nanorc file be enforced? |
209 | nano -Y stam -- "$TMPFIL" |
210 | nano -Y stam -- "$TMPFIL" |
210 | if [ -f "$TMPFIL" ]; then |
211 | if [ -f "$TMPFIL" ]; then |
211 | echo_cyan "Processing batch script..." |
212 | echo_cyan "Processing batch script..." |
212 | "$0" --batchmode < "$TMPFIL" |
213 | "$0" --batchmode < "$TMPFIL" |
213 | rm "$TMPFIL" |
214 | rm "$TMPFIL" |
214 | echo_cyan "Batch finished!" |
215 | echo_cyan "Batch finished!" |
215 | else |
216 | else |
216 | echo_yellow "No data entered in batch mode editor. Cancelled." |
217 | echo_yellow "No data entered in batch mode editor. Cancelled." |
217 | fi |
218 | fi |
218 | elif [[ "$cmd" == "sub" || "$cmd" == "su" ]]; then |
219 | elif [[ "$cmd" == "sub" || "$cmd" == "su" ]]; then |
219 | # At the moment, we do not use '--subshell' |
220 | # At the moment, we do not use '--subshell' |
220 | "$0" --subshell |
221 | "$0" --subshell |
221 | elif [[ "$cmd" == "back" || "$cmd" == "b" ]]; then |
222 | elif [[ "$cmd" == "back" || "$cmd" == "b" ]]; then |
222 | X_PREV_CAT="$CURCAT" |
223 | X_PREV_CAT="$CURCAT" |
223 | 224 | ||
224 | # change category |
225 | # change category |
225 | CURCAT="$PREV_CAT" |
226 | CURCAT="$PREV_CAT" |
226 | 227 | ||
227 | # if [ $IS_BATCHMODE -eq 0 ]; then |
228 | # if [ $IS_BATCHMODE -eq 0 ]; then |
228 | # echo_green "Your category is now '$CURCAT'" |
229 | # echo_green "Your category is now '$CURCAT'" |
229 | # fi |
230 | # fi |
230 | 231 | ||
231 | # Warning if category does not exist yet. |
232 | # Warning if category does not exist yet. |
232 | "$DIR"/exists1 "$CURCAT" |
233 | "$DIR"/exists1 "$CURCAT" |
233 | if [ $? -eq 1 ]; then |
234 | if [ $? -eq 1 ]; then |
234 | echo_yellow "(i) Note: The category does not exist and will be created if you continue:" |
235 | echo_yellow "(i) Note: The category does not exist and will be created if you continue:" |
235 | echo_yellow " $CURCAT" |
236 | echo_yellow " $CURCAT" |
236 | fi |
237 | fi |
237 | 238 | ||
238 | # Special ability: Allow that you can go forward again |
239 | # Special ability: Allow that you can go forward again |
239 | PREV_CAT="$X_PREV_CAT" |
240 | PREV_CAT="$X_PREV_CAT" |
240 | elif [[ "$cmd" == "showhistory" || "$cmd" == "shi" ]]; then |
241 | elif [[ "$cmd" == "showhistory" || "$cmd" == "shi" ]]; then |
241 | # Leider enthält das nicht die Ausgaben :-( |
242 | # Leider enthält das nicht die Ausgaben :-( |
242 | cat ~/.stam_history | less |
243 | cat ~/.stam_history | less |
243 | elif [[ "$cmd" == "help" || "$cmd" == "h" || "$cmd" == "?" ]]; then |
244 | elif [[ "$cmd" == "help" || "$cmd" == "h" || "$cmd" == "?" ]]; then |
244 | echo_cyan "#<cat>" |
245 | echo_cyan "#<cat>" |
245 | echo -e "\tChange category. Parameter: Category" |
246 | echo -e "\tChange category. Parameter: Category" |
246 | echo -e "\tUse '##' at the beginning, if you want to create an entry beginning with '#'." |
247 | echo -e "\tUse '##' at the beginning, if you want to create an entry beginning with '#'." |
247 | echo_cyan "-(back|b)" |
248 | echo_cyan "-(back|b)" |
248 | echo -e "\tSwitch to previous used category" |
249 | echo -e "\tSwitch to previous used category" |
249 | echo_cyan "-(strike|str) <id>" |
250 | echo_cyan "-(strike|str) <id>" |
250 | echo -e "\tStrike entry <id>" |
251 | echo -e "\tStrike entry <id>" |
251 | echo -e "\t<id> can have ranges using '<min>-<max>' or be 'last' for the last inserted ID." |
252 | echo -e "\t<id> can have ranges using '<min>-<max>' or be 'last' for the last inserted ID." |
252 | echo_cyan "-(singleadd|sa|as|appendsingle|aps) <cat> <entry>" |
253 | echo_cyan "-(singleadd|sa|as|appendsingle|aps) <cat> <entry>" |
253 | echo -e "\tAdd <entry> to category <cat> without changing the category." |
254 | echo -e "\tAdd <entry> to category <cat> without changing the category." |
254 | echo -e "\t<cat> may not contain a white space" |
255 | echo -e "\t<cat> may not contain a white space" |
255 | echo_cyan "-(unstrike|unstr) <id>" |
256 | echo_cyan "-(unstrike|unstr) <id>" |
256 | echo -e "\tUn-Strike entry <id>" |
257 | echo -e "\tUn-Strike entry <id>" |
257 | echo -e "\t<id> can have ranges using '<min>-<max>' or be 'last' for the last inserted ID." |
258 | echo -e "\t<id> can have ranges using '<min>-<max>' or be 'last' for the last inserted ID." |
258 | echo_cyan "-(movefromid|mfi) <id>" |
259 | echo_cyan "-(movefromid|mfi) <id>" |
259 | echo -e "\tMove ID <id> to the current selected category" |
260 | echo -e "\tMove ID <id> to the current selected category" |
260 | echo -e "\t<id> can have ranges using '<min>-<max>' or be 'last' for the last inserted ID." |
261 | echo -e "\t<id> can have ranges using '<min>-<max>' or be 'last' for the last inserted ID." |
261 | echo_cyan "-(movefromcat|mfc) <cat>" |
262 | echo_cyan "-(movefromcat|mfc) <cat>" |
262 | echo -e "\tMove all entries of category <cat> to the current selected category" |
263 | echo -e "\tMove all entries of category <cat> to the current selected category" |
263 | echo -e "\t<cat> can have wildcards (*)" |
264 | echo -e "\t<cat> can have wildcards (*)" |
264 | echo_cyan "-(listent|le) [<cat>]" |
265 | echo_cyan "-(listent|le) [<cat>]" |
265 | echo -e "\tShow all entries. Optional parameter: Category" |
266 | echo -e "\tShow all entries. Optional parameter: Category" |
266 | echo -e "\t<cat> can have wildcards (*)" |
267 | echo -e "\t<cat> can have wildcards (*)" |
267 | echo_cyan "-(listcurent|lce)" |
268 | echo_cyan "-(listcurent|lce)" |
268 | echo -e "\tShow all entries of the selected category." |
269 | echo -e "\tShow all entries of the selected category." |
269 | echo_cyan "-(listcat|ls|lc) [<cat>]" |
270 | echo_cyan "-(listcat|ls|lc) [<cat>]" |
270 | echo -e "\tShow all categories. Optional parameter: Category" |
271 | echo -e "\tShow all categories. Optional parameter: Category" |
271 | echo -e "\t<cat> can have wildcards (*)" |
272 | echo -e "\t<cat> can have wildcards (*)" |
272 | echo_cyan "-(clear|cls)" |
273 | echo_cyan "-(clear|cls)" |
273 | echo -e "\tClears the screen" |
274 | echo -e "\tClears the screen" |
274 | echo_cyan "-(batch|bat)" |
275 | echo_cyan "-(batch|bat)" |
275 | echo -e "\tEnters batch mode (opens a subshell, without keeping your current category!)" |
276 | echo -e "\tEnters batch mode (opens a subshell, without keeping your current category!)" |
276 | echo_cyan "-(sub|su)" |
277 | echo_cyan "-(sub|su)" |
277 | echo -e "\tEnters subshell mode" |
278 | echo -e "\tEnters subshell mode" |
278 | echo_cyan "-(showhistory|shi)" |
279 | echo_cyan "-(showhistory|shi)" |
279 | echo -e "\tShow history of all entered commands" |
280 | echo -e "\tShow history of all entered commands" |
280 | echo_cyan "-(help|h|?)" |
281 | echo_cyan "-(help|h|?)" |
281 | echo -e "\tThis help screen" |
282 | echo -e "\tThis help screen" |
282 | echo_cyan "-(exit|quit|x|q)" |
283 | echo_cyan "-(exit|quit|x|q)" |
283 | echo -e "\tExits the program" |
284 | echo -e "\tExits the program" |
284 | elif [[ "$cmd" == "exit" || "$cmd" == "quit" || "$cmd" == "x" || "$cmd" == "q" ]]; then |
285 | elif [[ "$cmd" == "exit" || "$cmd" == "quit" || "$cmd" == "x" || "$cmd" == "q" ]]; then |
285 | # Exit the program |
286 | # Exit the program |
286 | break |
287 | break |
287 | else |
288 | else |
288 | # Unknown command |
289 | # Unknown command |
289 | echo_red "[!] FATAL ERROR: Unknown command '$cmd'. Use '-help' for available commands." 1>&2 |
290 | echo_red "[!] FATAL ERROR: Unknown command '$cmd'. Use '-help' for available commands." 1>&2 |
290 | echo_red " If you want to add an entry, Use '--' to escape the first character." 1<&2 |
291 | echo_red " If you want to add an entry, Use '--' to escape the first character." 1<&2 |
291 | fi |
292 | fi |
292 | else |
293 | else |
293 | # (Blind) appender mode |
294 | # (Blind) appender mode |
294 | 295 | ||
295 | # Keine leeren Zeilen (ist das OK?) |
296 | # Keine leeren Zeilen (ist das OK?) |
296 | if [[ "$inp" == "" ]]; then |
297 | if [[ "$inp" == "" ]]; then |
297 | continue |
298 | continue |
298 | fi |
299 | fi |
299 | 300 | ||
300 | # Add single entry (aps) |
301 | # Add single entry (aps) |
301 | OUT=$( "$DIR"/aps "$CURCAT" "$inp" ) |
302 | OUT=$( "$DIR"/aps "$CURCAT" "$inp" ) |
302 | EC=$? |
303 | EC=$? |
303 | echo -n "$OUT" |
304 | echo -n "$OUT" |
304 | if [ $EC -ne 0 ]; then |
305 | if [ $EC -ne 0 ]; then |
305 | echo_red "[!] FATAL ERROR: Could not append the entry!" 1>&2 |
306 | echo_red "[!] FATAL ERROR: Could not append the entry!" 1>&2 |
306 | else |
307 | else |
307 | LAST_ID=$( echo "$OUT" | sed -r 's/^.*OK! ([[:digit:]]+).*$/\1/g' ) |
308 | LAST_ID=$( echo "$OUT" | sed -r 's/^.*OK! ([[:digit:]]+).*$/\1/g' ) |
308 | fi |
309 | fi |
309 | fi |
310 | fi |
310 | done |
311 | done |
311 | 312 | ||
312 | if [ $IS_BATCHMODE -eq 0 ]; then |
313 | if [ $IS_BATCHMODE -eq 0 ]; then |
313 | echo "" |
314 | echo "" |
314 | echo "Goodbye." |
315 | echo "Goodbye." |
315 | fi |
316 | fi |
316 | 317 |