News for hackers. Stuff that matters.
Re:How and Why to Log Your Bash History by yomly on Tuesday May 31, 2016 @11:04AM (#11806904)
I'm a big fan of saving history - trying to remember all the shell based commands we use is a nightmare!

If you're using zsh, a tip I picked up from [0] was to alias all your common commands like

    'cd', 'ls' 'fg'...
to:

    ' cd' ' ls' ' fg' ... 
Then add the following line to your zshrc to ignore lines prepended with a space:

    setopt HIST_IGNORE_SPACE
This keeps your history cleaner from any ls, cd, fg inputs you use.

[0] http://chneukirchen.org/blog/archive/2012/02/10-new-zsh-tric...

EDIT: formatting

Re:How and Why to Log Your Bash History by Terretta on Tuesday May 31, 2016 @11:14AM (#11806987)
Dropping the ls, ok. But cd conveys relevant context.

It would be really clever if a series of cd/ls rolled into a final absolute path cd so history shows context for the subsequent batch of commands.

Re:How and Why to Log Your Bash History by kerkeslager on Tuesday May 31, 2016 @11:57AM (#11807284)
If you find yourself doing a series of `cd` and `ls` commands frequently, I feel like you might be using `cd` and tab completion ineffectively.

Instead of doing:

    ls
    cd foo/
    ls
    cd bar/
    ls
    cd baz/
You can do:

    ls
    cd foo/<tab><tab>bar/<tab><tab>baz/
This isn't what it will look like, it's just the key sequence (if this doesn't make sense let me know and I'll try to explain better). <tab><tab> will list all the possible completions, which is equivalent to an ls, without having to type in an ls and then another cd.

You can frequently avoid even more `cd`/`ls` shenanigans by judiciously using `pushd`.

Re:How and Why to Log Your Bash History by NhanH on Tuesday May 31, 2016 @12:23PM (#11807476)
Tab autocomplete will show everything, and showing a screen full of name is not particularly useful. Most of the time I use ls it's something like "ls (asterisk)foo(asterisk)".

How do I escape asterisk on HN? :O

Re:How and Why to Log Your Bash History by joepvd on Tuesday May 31, 2016 @12:33PM (#11807548)
In zsh, you can complete a glob.
Re:How and Why to Log Your Bash History by joombaga on Tuesday May 31, 2016 @01:41PM (#11808356)
bash too
Re:How and Why to Log Your Bash History by throwanem on Tuesday May 31, 2016 @03:34PM (#11809469)
But if there are multiple candidate completions, you don't get a list of them, the way you do from <tab> <tab> with no glob - it just completes unconditionally to the first candidate.
Re:How and Why to Log Your Bash History by schoen on Tuesday May 31, 2016 @12:40PM (#11807612)
Edit: I had a guess about how to escape asterisks here, and it didn't work!
Re:How and Why to Log Your Bash History by nvdk on Tuesday May 31, 2016 @12:41PM (#11807633)
You can so the same with tab . Eg foo/(asterisk)bar<tab><tab>
Re:How and Why to Log Your Bash History by rsamvit on Tuesday May 31, 2016 @01:00PM (#11807820)
I just do:

function cd () { builtin cd "$@" && ls; }

Re:How and Why to Log Your Bash History by superuser2 on Tuesday May 31, 2016 @11:27AM (#11807080)
Can you not set the template line for log entries? Seems like $(pwd) could go alongside time stamp.
Re:How and Why to Log Your Bash History by agumonkey on Tuesday May 31, 2016 @12:09PM (#11807369)
There's a direct parameter to do that in one go.

HISTIGNORE="history:ls:[bf]g:exit:htop:ncdu:pwd:reset:clear:mount:umount:&:^[ \t]*"

Mine might be flawed though.

Re:How and Why to Log Your Bash History by SEJeff on Tuesday May 31, 2016 @08:21PM (#11811310)
So you're saying you just showed me the one feature bash has over zsh!? Bash has an env var named HISTIGNORE that will allow you to not put commonly used boring commands in your history. Mine looks like:

    export HISTIGNORE="ls:exit:history:[bf]g:jobs"
Re:How and Why to Log Your Bash History by guelo on Tuesday May 31, 2016 @12:26PM (#11807497)
A lot of times I want to go back and look in which directory I was executing some command.