Search code examples
shellgit-bashbashportable-applications

Shell (Bash) - Can I have fully portable .bash_profile / .bashrc / .bash_history files?


Background

I'm a Front End Web Developer that has started moving to PortableApps where I can; at least for the desktop machines I use (Windows) after building a machine and having to re-install Windows multiple times.

It's getting more and more important to use the command line with build automation tools, testing software with a CLI etc.

I have just got portable versions of Git (Bash) and ConEmu working from my Dropbox (but ideally this would work from USB too). This means I have access to a Unix shell on Windows with Git, but the .bash_profile (and .bashrc) I have saved I need to manually copy to the '~' (home) directory for each machine I use.

Question

Is there a way to link my portable console with bash files not located in the home directory of the user on each machine used?

For instance when my console opens and looks for these files, can I ask it to check a different directory without setting any config on each machine? And then get the .bash_history to save here too instead?


Solution

  • You can use symbolic links for .bash_profile and .bashrc:

    ln -s /path/to/.bashrc ~/.bashrc
    ln -s /path/to/.bash_profile ~/.bash_profile
    

    And inside your .bashrc you can define where your history file is located:

    export HISTFILE=/path/to/.bash_history
    

    I don't think there's any way around having .bashrc and .bash_profile in your home directory. Unless you start bash with the --rcfile option:

    bash --rcfile /path/to/.bashrc
    

    There is also the system wide file located at /etc/bashrc.