Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a utility that streamlines the storing and restoring of bash sessions? I'd like to be able to do EG

$ KUNG=pao
$ foo commit  # saves the current environment
              # as an anonymous changeset from the previous savepoint
$ SCHNICKENS="What's up, doc?"
$ SCHNICKENS="$(echo Schmoove)"
$ unset KUNG
$ foo diff HEAD  # outputs a $(set) of commands
                 # which comprise the current changeset
unset KUNG;
$ foo branch edit-su-question  # creates a new branch with that name
$ foo merge master  # updates the current environment
                    # with any changes made to ~/.bashrc
                    # since it was branched or last merged
$ function fierce_fist_of_foo {
      cut -f 2 | xargs -I {} bash foo {} '>>' ffof.out;
$ foo checkout master  # switches current branch
                       # to the one checked out by ~/.bashrc
$ foo commit -m "learned the fierce_fist_of_foo technique"
  # new interactive `bash` invocations now load that function

Given its similarity to the git command-set, I'm tempted to use an obscene word, or alternatively a Smashing Pumpkins album title, as the command name in this example. But good ole foo it is.

I'm basing my faith in the workability of this concept largely on the presumption that running set from a bash shell will give you an invokable script which will restore that environment. I'm not sure if this is entirely true.

Anyway, is there something out there that works like this? Extra points if it actually uses git as part of its implementation. Like, I'll accept that answer. Since you're only in it for the points and all.

share|improve this question

I am sure one could come up with something using env and source.

 # "commit"
 env > saved_state

 # "checkout"
 source saved_state

Everything else would be interface sugar. One could even script putting the saved_state files in some git repository somewhere automatically so one could browse it with tig.

I have to admit I am horrified of the potential for extremely messy and confusing workflows this would allow.

share|improve this answer
hmm, maybe it would be that simple. Though if you use env you won't get any function definitions, or some other things that I'm not sure of. Also the checkout would have to do unsets for - lines in the diff. I was imagining parsing the output from set and building the set of assignments, unsets, function statements, etc. that would be necessary to invoke that change. Other things like shopt should be included, too. – intuited Jun 29 '10 at 3:33
As for it being messy and confusing: I was hoping to find something like this to enable avoiding messy and confusing workflows where I have to source and then update a script by piping history into vim and copying the function definitions out of the history into the script. It makes way more sense to do it with prototyping of the shell environment. – intuited Jun 29 '10 at 3:36
@intuited Yes, this doesn't work for functions. Maybe what you really want is a convenient way to store snippets instead of this putting your whole workflow thourgh some VC machinery? – Benjamin Bannier Jun 29 '10 at 4:29
Keeping snippets under version control, with task-oriented branches, seems to me to be the most convenient way to store them. git is actually a bit limited as a working model or implementation base, for two reasons: 1) the branch set is a flat list, meaning that you don't have a convenient way to [re-]organize a lot of them; 2) there's no way to create a "layered branch" that dynamically merges more than one branch. In programming terms, branches are static types, and commits are compiles. – intuited Jun 29 '10 at 7:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .