1

I'm trying to add timestamps to my history output. I am running Z Shell on a Mac (Monterey v12.2).

I have the following in my .zprofile regarding history.

export HISTSIZE=5000
export HISTFILE=~/.zsh_history
export SAVEHIST=5000
export HISTFILESIZE=5000
export HISTTIMEFORMAT='%F %T '
setopt appendhistory
alias hist="history 1"

I know my .zprofile is being loaded since other variables and alias statements are working. However my history does not include any timestamp currently.

It looks like this:

$ hist
 1008  ls -lah
 1009  npm install
 1010  clear
 1011  git status
 1012  npm install
 1013  npm start
 1014  clear
 1015  git status
 1016  vim .gitignore
 1017  git status
 1018  git add .gitignore

How can I make sure my history makes use of the HISTTIMEFORMAT?

1 Answers1

0

If you want history (same as fc -l) to display timestamps according to a strftime-like format stored in the $HISTTIMEFORMAT variable, you need to call it with -t "$HISTTIMEFORMAT":

alias 'hist=fc -lt "$HISTTIMEFORMAT" 1'