Skip to content

Instantly share code, notes, and snippets.

@alhoo
Last active June 28, 2019 11:00
Show Gist options
  • Save alhoo/58143d6f420a99e1182de89e6e9d209f to your computer and use it in GitHub Desktop.
Save alhoo/58143d6f420a99e1182de89e6e9d209f to your computer and use it in GitHub Desktop.
function json_double_escape () {
printf '%s' "$1"|python -c 'import json,sys,re; print(re.subn(r"\\", r"\\\\", json.dumps(sys.stdin.read(), ensure_ascii=False))[0])'
}
function command_exec_handler() {
STARTTIME=$(date --iso-8601=seconds)
SECONDS=0
eval $1;
EXIT_VALUE="$?"
CMD=$(json_double_escape $1)
ENDTIME=$(date --iso-8601=seconds)
if [ $SECONDS -gt 30 ]; then
notify-send "valmis" "$CMD\n\n$EXIT_VALUE\n\n";
>&2 echo "(The script took $(($SECONDS / 60))min $(($SECONDS % 60))s)"
fi
echo "{\"start\": \"$STARTTIME\", \"end\": \"$ENDTIME\", \"ppid\": $$, \"cmd\": $CMD, \"pwd\": \"$PWD\", \"return\": $EXIT_VALUE}" >> ~/.zsh_fullhistory.jsonl;
return $EXIT_VALUE
}
# Enhance history search
case "$TERM" in
xterm*|rxvt*)
bindkey "^[[A" history-search-backward
bindkey "^[[B" history-search-forward
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment