Timeline for How can I filter certain commands from multi-line Bash history on logout?
Current License: CC BY-SA 3.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 31, 2017 at 16:36 | vote | accept | ivan | ||
| Jul 31, 2017 at 14:52 | answer | added | Yunus | timeline score: 0 | |
| Jul 31, 2017 at 0:44 | comment | added | Gilles 'SO- stop being evil' | Ah, sorry, I didn't know that an EXIT trap would run after writing the history. If you're doing complex stuff, you may want to switch to zsh, which is generally more flexible. | |
| Jul 30, 2017 at 3:15 | answer | added | ivan | timeline score: 2 | |
| Jul 29, 2017 at 16:16 | comment | added | ivan |
@Gilles It seems that trapping EXIT causes my filter to run too late, i.e. after the history has already been written to disk. I could adjust my script to filter the entire contents of HISTFILE after the fact, but it seems smarter to filter incrementally, i.e. just the contents I want appended to the existing file. Maybe I should trap SIGHUP and unset HISTFILE after manually appending to it?
|
|
| Jul 29, 2017 at 13:22 | comment | added | ivan | Oh good point. I overlooked that because I'm on macOS, where the convention seems to be to use login shells for all interactive sessions. | |
| Jul 29, 2017 at 12:52 | comment | added | Gilles 'SO- stop being evil' |
.bash_logout is only executed in a login shell, it isn't useful here. Run this code from an exit trap instead (trap filter_history EXIT).
|
|
| Jul 29, 2017 at 12:47 | history | edited | ivan | CC BY-SA 3.0 |
added 238 characters in body
|
| Jul 29, 2017 at 5:12 | history | edited | ivan |
edited tags
|
|
| Jul 29, 2017 at 4:59 | history | asked | ivan | CC BY-SA 3.0 |