From 9a454a9a351e0dfd181e53f2c53d4c82a7e90b1c Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 2 Oct 2020 17:14:54 +0300 Subject: [PATCH] Print errors on stderr, disallow invalid args for histdb-top --- sqlite-history.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sqlite-history.zsh b/sqlite-history.zsh index 83276f6..193a361 100644 --- a/sqlite-history.zsh +++ b/sqlite-history.zsh @@ -24,7 +24,7 @@ sql_escape () { _histdb_query () { sqlite3 -cmd ".timeout 1000" "${HISTDB_FILE}" "$@" - [[ "$?" -ne 0 ]] && echo "error in $@" + [[ "$?" -ne 0 ]] && print -u2 "error in $@" } _histdb_stop_sqlite_pipe () { @@ -189,12 +189,16 @@ histdb-top () { join='commands.id = history.command_id' table=commands ;;; + *) + print -u2 'error: argument must be one of "cmd" or "dir"' + return 1 + ;;; esac _histdb_query -separator "$sep" \ -header \ "select count(*) as count, places.host, replace($field, ' ', ' -$sep$sep') as ${1:-cmd} from history left join commands on history.command_id=commands.id left join places on history.place_id=places.id group by places.host, $field order by count(*)" | \ +$sep$sep') as ${1} from history left join commands on history.command_id=commands.id left join places on history.place_id=places.id group by places.host, $field order by count(*)" | \ "${HISTDB_TABULATE_CMD[@]}" }