Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I find I do a lot of work on a project in a set directory. Sometimes - a few months down the track, I need to redo something on that project but I can't remember what the hell I did. I use mercurial or git to track changes to files but I want to be able to remember what commands I issued in that directory.

Searching through my shell history is not very informative. I already log everything to my .*_history files, but I want a list of things I did in ~/foo/bar, and not all the other (million) things that I did that week. Hell, I probably can't even remember what month I last worked on that particular project.

Does anyone have any ideas how a project directory log file of all shell commands I've used? I'm envisioning a command something like:

workon myproject

... which would set the shell log file to ~/myproject/.history.log, load the previous history from that logfile, and maybe update my prompt to tell me what directory I'm working on (like e.g. vcprompt to provide version control info).

Is there anything out there like this?

share|improve this question

3 Answers

One trick I use for framework of building sub-packages for a product is to use a sub-shell.

For bash you could create a shell script like this:

#!/bin/bash

export PROJECT_DIRECTORY=$(pwd)

exec bash --rcfile $HOME/.project-bashrc

Then in $HOME/.project-bashrc you put something like this:

source $HOME/.bashrc
export HISTFILE="${PROJECT_DIRECTORY}/.bash_history"
cd "${PROJECT_DIRECTORY}"

This also lets you customize the prompt in the .project-bashrc file, which can be handy.

I'm not sure how to do the same in zsh. You'd have to override the ZDOTDIR variable, I think. But it'd look similar.

Ciao!

share|improve this answer

In bash at least, HISTFILE is only consulted at start of shell instance. The per-dir idea won't work here, unless your 'workon' example above creates a shell instance.

Maybe you can look at something like

alias workon='script ./.history.log'

But script also creates a subshell.

In short, you'll probably need messy levels of subshells to get this to work.

share|improve this answer
Damn, I was hoping it'd be something simple. Thanks anyway! – Simon Jan 14 '12 at 7:26

Take a look at my logging scripts here. Using one of them, you can keep track of what directory you're in when you issue each command. You can grep the log file for the command or other information. I use the long version at home and at work.

share|improve this answer
Thanks - I'll have a look into this. Might do something close to what I need! – Simon Jan 14 '12 at 7:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.