Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Last active June 10, 2017 17:41
Show Gist options
  • Save caseywatts/a54bea8b93626b99f5ee to your computer and use it in GitHub Desktop.
Save caseywatts/a54bea8b93626b99f5ee to your computer and use it in GitHub Desktop.
Autorefresh Terminal History

Other gists & tricks: http://caseywatts.com/gists-and-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 = histo.map { |h| h[15, h.length] }
histo = histo.join("\n")
system 'clear'
puts histo
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment