Skip to content

Instantly share code, notes, and snippets.

Last active June 10, 2017 17:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Autorefresh Terminal History

Other gists & tricks:

#Autorefresh Terminal History For giving presentations.

I've been trying to find a way to show an audience the recent terminal commands I've been calling. I can easily imagine doing this in a separate terminal window that just auto-refreshes showing the history of commands recently called.

I decided to try a ruby script! (Bash would be fine too, just comfort)

###Obtaining the history history is the best because it formats it beautifully However, history is a "shell builtin" so we can't access it from ruby or bash scripts. cat ~/.zsh_history does work, but it's littered with timestamps

###Cleaning zsh_history I like timestamps in my zsh_history, so I'm using Ruby code to manually clean it up.

###Looking Ahead If you do, how do you do this?

I bet there's an easier way that works out of the box for more people. I'm just not sure what/where it is.

while true
histo = %x(tail -n 20 ~/.zsh_history)
# Clean Up, remove timestamps
histo = histo.split(/\n/)
histo = { |h| h[15, h.length] }
histo = histo.join("\n")
system 'clear'
puts histo
sleep 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment