Live data from Hacker News

How and Why to Log Your Bash History

spin.atomicobject.com

21–30 of 139 posts

Re: How and Why to Log Your Bash History

#21
post #19
post #9

Earlier quoted context omitted.

Another problem for me is the ephemeral nature of many of the boxes I work on - Vagrant boxes, spot instances on AWS. I suppose I could do this and then export the bash history as part of the teardown process. At the moment, I get around this by storing as much as I can in searchable scratch files, but this relies on me knowing what to copy. I'm sure there's a better way.

Work through ansible and manage your local ansible.log however you wish.

Any way I can do it with Puppet?

Re: How and Why to Log Your Bash History

#22
Just for those out there using zsh or fish I used to following in my .zshrc to get this working:

    precmd() {
        eval 'if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history | tail -n 1)" >>! ~/Dropbox/Logs/Bash/Macbook/bash-history-$(date "+%Y-%m-%d").log; fi'
    }
I Store my logs in dropbox but you can put them wherever

Re: How and Why to Log Your Bash History

#23
I used to do the same thing to figure out which commands I should create short aliases for. Sounded like a good idea at the time but then I realized that I'm creating a file with an awful lot of interesting information in it and I not getting a lot in return. So I set my HISTSIZE to 1000 which is more than enough for interactive shell use and I don't have to worry about having stuff like "youtube-dl fuckmesilly.com/${insane_porn_title}" lying around on servers I have access to. (Or which server you can connect to with my private key -- you might as well remove HashKnownHosts from your ssh config if you log it all yourself.)

TLDR: Overwriting history is a feature.

Re: How and Why to Log Your Bash History

#24

This looks like quite a dirty hack, but I'll try it. I wish bash history wasn't so broken. I suppose once upon a time it was ok to assume people only had one shell session at a time.

I'm curious as to why you consider it so broken.

As far as I can tell, bash deals with multiple shell sessions exactly how I'd expect (and want) it to: an individual terminal doesn't have access to the live session from other terminals, but when you close it it appends it's session to the shared history file, so each session ends up a continuous block in that file.

Re: How and Why to Log Your Bash History

#26
Doing the same. Also including the git branch (if applicable)

It's not obvious, but with this mechanism commands are only logged once they complete. So the log file does not include commands while they are still running. Run into that from time to time.

Re: How and Why to Log Your Bash History

#27
Don't go overloading `require()` just because you can - the modules API has been locked down for a couple of years now, messing with the semantics causes all sort of fallout. - https://nodejs.org/api/modules.html (I'm looking at you webpack, babel)

Instead better would've been to use a custom method; internally the `require.resolve()` API can still be used to get the same semantics as `require()`

Re: How and Why to Log Your Bash History

#30
post #11
post #3

Earlier quoted context omitted.

For better history across different terminal (on the same computer) you may want to try zsh

For better pretty much everything, one may wish to try zsh. It's pretty much a strict superset of bash, but better. There is one aspect in which it's significantly worse, though: it's fiendishly difficult to configure and understand. I just use configs provided by others, which is not ideal but works.

bash (with all features) is also a strict superset of bash (with default configuration that people think is all there is to it, especially if they use macs [1]), but better.

[1] If you are using a mac and haven't installed a newer copy of bash you're using a version that's nearing on 10 years old and does indeed mostly suck.

Post reply on HN