File src/hstr_history.c changed (mode: 100644) (index 341a7fe..1e01f35) |
... |
... |
int history_mgmt_remove_from_system_history(char *cmd) |
225 |
225 |
HISTORY_STATE *historyState=history_get_history_state(); |
HISTORY_STATE *historyState=history_get_history_state(); |
226 |
226 |
|
|
227 |
227 |
// TODO refactor this code to have this in source exactly once |
// TODO refactor this code to have this in source exactly once |
228 |
|
regex_t regexp; |
|
|
228 |
|
regex_t tsRegexp; |
|
229 |
|
regex_t zshRegexp; |
229 |
230 |
// HISTTIMEFORMAT defined > ^#1234567890$ |
// HISTTIMEFORMAT defined > ^#1234567890$ |
230 |
231 |
const char *histtimeformatTimestamp = "^#[[:digit:]]\\{10,\\}$"; |
const char *histtimeformatTimestamp = "^#[[:digit:]]\\{10,\\}$"; |
231 |
|
regexp_compile(®exp, histtimeformatTimestamp); |
|
|
232 |
|
regexp_compile(&tsRegexp, histtimeformatTimestamp); |
|
233 |
|
|
|
234 |
|
const char *zshTimestamp = "^: [[:digit:]]\\{10,\\}:[[:digit:]];.*"; |
|
235 |
|
regexp_compile(&zshRegexp, zshTimestamp); |
232 |
236 |
|
|
233 |
237 |
while(offset>=0) { |
while(offset>=0) { |
234 |
238 |
l=historyState->entries[offset]->line; |
l=historyState->entries[offset]->line; |
235 |
|
if(offset<historyState->length && !strcmp(cmd, l)) { |
|
236 |
|
occurences++; |
|
237 |
|
free_history_entry(remove_history(offset)); |
|
238 |
|
if(offset>0) { |
|
239 |
|
l=historyState->entries[offset-1]->line; |
|
240 |
|
if(l && strlen(l)) { |
|
241 |
|
if(!regexp_match(®exp, l)) { |
|
242 |
|
// TODO check that this delete doesn't cause mismatch of searched cmd to be deleted |
|
243 |
|
free_history_entry(remove_history(offset-1)); |
|
244 |
|
} |
|
245 |
|
} |
|
246 |
|
} |
|
|
239 |
|
if(offset<historyState->length) { |
|
240 |
|
if(!regexp_match(&zshRegexp, l)) { |
|
241 |
|
l=l+15; //: 1485023566:0;whoami |
|
242 |
|
} |
|
243 |
|
if(!strcmp(cmd, l)) { |
|
244 |
|
occurences++; |
|
245 |
|
free_history_entry(remove_history(offset)); |
|
246 |
|
if(offset>0) { |
|
247 |
|
l=historyState->entries[offset-1]->line; |
|
248 |
|
if(l && strlen(l)) { |
|
249 |
|
if(!regexp_match(&tsRegexp, l)) { |
|
250 |
|
// TODO check that this delete doesn't cause mismatch of searched cmd to be deleted |
|
251 |
|
free_history_entry(remove_history(offset-1)); |
|
252 |
|
} |
|
253 |
|
} |
|
254 |
|
} |
|
255 |
|
} |
247 |
256 |
} |
} |
248 |
257 |
offset=history_search_pos(cmd, 0, ++offset); |
offset=history_search_pos(cmd, 0, ++offset); |
249 |
258 |
} |
} |