resumable bash sessions with branch maintenance

1

1

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;
SCHNICKENS="Schmoove"
$ 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.

intuited

Posted 2010-06-29T02:52:52.457

Reputation: 2 861

Answers

1

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.

Benjamin Bannier

Posted 2010-06-29T02:52:52.457

Reputation: 13 999

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 – 2010-06-29T03:33:33.763

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 – 2010-06-29T03:36:39.763

@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 – 2010-06-29T04:29:53.150

1Keeping 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 – 2010-06-29T07:26:48.567