1

I have Git Bash on Windows and want to customize things with dotfiles. I'm new to all of this so thank you for any help and patience.

I am trying to follow the answers from Git for Windows: .bashrc or equivalent configuration files for Git Bash shell, but I think they are outdated with respect to the default install folder/file structure; for example, I can't find any .bashrc or .bash_profile files (except for the Shell file in screenshot below, maybe that is it?). I think the pertinent files are in profile.d I have git version 2.36.0.windows.1

An example entry in the .alias file might be something like alias mydir='C:/Users/name/Documents', and I'd like to be able to type cd mydir into the Git Bash prompt.

This is what the installed folder looks like:

enter image description here

And this is what the ~/profile.d folder looks like:

enter image description here

Open to recommendations, but after researching, I think I want to set up a folder called ".dotfiles" with a text file called ".alias" and another text file called ".functions" (i.e., ~/.dotfiles/.alias and ~/.dotfiles/.function). I want to have these as separate files rather than editing the text files from the installation in C:\Program Files\Git\etc\profile.d.

I have two questions on this:

  1. Where should the ~/.dotfiles folder be located? In C:\Program Files\Git?

  2. How do I add/activate all of the text files in my ~/.dotfiles folder automatically in every session? I don't understand the syntax nor where this would go (maybe in C:\Program Files\Git\etc\profile.d\bash_profile.sh?)

EDIT This is the content of C:\Program Files\Git\etc\profile.d\bash_profile.sh:

# add ~/.bash_profile if needed for executing ~/.bashrc
if [ -e ~/.bashrc -a ! -e ~/.bash_profile -a ! -e ~/.bash_login -a ! -e ~/.profile ]; then
  printf "\n\033[31mWARNING: Found ~/.bashrc but no ~/.bash_profile, ~/.bash_login or ~/.profile.\033[m\n\n"
  echo "This looks like an incorrect setup."
  echo "A ~/.bash_profile that loads ~/.bashrc will be created for you."
  cat >~/.bash_profile <<-\EOF
    # generated by Git for Windows
    test -f ~/.profile && . ~/.profile
    test -f ~/.bashrc && . ~/.bashrc
    EOF
fi
torek
  • 448,244
  • 59
  • 642
  • 775
a11
  • 3,122
  • 4
  • 27
  • 66
  • ~, or your home directory, is `C:/Users/yourusername/`, so create/edit your .bashrc there – Andrew Mascillaro Jul 26 '22 at 22:00
  • Don't think of git-bash as having anything to do with Git, because it doesn't. It's just *included with* Git-for-Windows because Git needs bash (well, any shell, but bash was there). – torek Jul 27 '22 at 05:48
  • @torek definitely! Git Bash is just my way of using Bash on Windows b/c I have to use Windows for work. I don't like Windows command line or PowerShell, but I like Bash and want to set up customizations (functions, etc.) to be more efficient. Is there a better way (not Git Bash) to get Bash on Windows? – a11 Jul 27 '22 at 17:56
  • There are multiple bash ports. I've only personally used the one that came with Cygwin, back when I was forced to use Windows for a bit and had a (work provided) machine with Cygwin installed. I have no idea which one is best (if there is even a linear way to rank goodness in the first place). – torek Jul 27 '22 at 19:47
  • (My vague understanding is that there are two competing ecosystems, msys2 and mingw64, at this point. Apparently they don't work very well with each other, some kind of bad library / DLL-hell thing or something.) – torek Jul 27 '22 at 19:51

1 Answers1

0

Indeed, this was the case, as my MINGW64 based Bash shell was started by an external windows app, and in a funny way, it was dumping me into a different directory.

The only way out was to do cd ~; pwd and put your .bashrc in there.

If that still doesn't work, try looking for changes in the .bash_history file. To find it, use:

cd /c/
find ./ -iname ".bash_history" 2>/dev/null
not2qubit
  • 14,531
  • 8
  • 95
  • 135