regenerate .bashrc from current shell

One thing you can try is to recover your .bashrc from the memory of a running instance of bash. On Linux, run gcore PID to make a memory dump of a process specified by its PID. Whether this has a chance of working depends on how bash manages its memory; I haven't checked the source code to see if it's at all possible. It doesn't work for me on Debian jessie amd64.

If that doesn't work, you can save your current settings, but you can't recover the way they got set, so a lot of information will be lost. If you had configuration that depends on the machine, on the terminal type, etc. then you'll only recover the settings for whatever instances of bash are still running.

  • Print out all variables in a form that can be read back. This includes a lot of noise that you'll have to sort out. Environment variables (marked with declare -x) shouldn't be defined in your .bashrc but you might have done so anyway. Remove variables that bash sets automatically (check the manual and look at the output of declare -p in bash --norc).

    declare -p
    
  • Print out all functions. This includes functions not defined by you, for example functions defined by the completion system (for which you want . /etc/bash_completion instead).

    declare -f
    
  • Print out aliases. These can probably be used as they are.

    alias
    
  • Print out shell options. Compare with the output of shopt in bash --norc to see what you changed.

    shopt
    
  • Print out completion settings (if you use the context-sensitive completion system). Most of these probably come from the completion system; finding the ones you've tuned might be a little difficult.

    complete
    
  • Print out key bindings, if you've defined key bindings in your .bashrc rather than in .inputrc. This includes default bindings.

    bind -p
    

From now on, back up all your files, and put your configuration files under version control.


You can get the default .bashrc from /etc/skel/.bashrc .
Also there is a way to recover files opened by a certain process from /proc/PID/fd/<files>, but it is not the case for .bashrc as it is not permanently opened by the bash process.

Tags:

Bash

Bashrc