35a6725970167278254ab11a996bf04d2186b009
- Author
- Marc Cornellà <marc@mcornella.com>
- Committer
- Marc Cornellà <marc@mcornella.com>
- Date
Message
fix(history): add warning before deleting command history in `history -c` (#12472)
Diff
1diff --git a/lib/history.zsh b/lib/history.zsh
2index a8431fd5a7eaa6a571216a29a95f9f69fad6685e..b13e1807fc90a67cae9c600e3850e5b2ef0b2afe 100644
3--- a/lib/history.zsh
4+++ b/lib/history.zsh
5@@ -1,14 +1,22 @@
6 ## History wrapper
7 function omz_history {
8 # parse arguments and remove from $@
9- local clear list stamp
10+ local clear list stamp REPLY
11 zparseopts -E -D c=clear l=list f=stamp E=stamp i=stamp t:=stamp
12
13 if [[ -n "$clear" ]]; then
14 # if -c provided, clobber the history file
15- echo -n >| "$HISTFILE"
16+
17+ # confirm action before deleting history
18+ print -nu2 "This action will irreversibly delete your command history. Are you sure? [y/N] "
19+ builtin read -k1
20+ [[ "$REPLY" = $'\n' ]] || print -u2
21+ [[ "$REPLY" != ([nN]|$'\n') ]] || return 0
22+
23+ print -nu2 >| "$HISTFILE"
24 fc -p "$HISTFILE"
25- echo >&2 History file deleted.
26+
27+ print -u2 History file deleted.
28 elif [[ $# -eq 0 ]]; then
29 # if no arguments provided, show full history starting from 1
30 builtin fc $stamp -l 1