我刚刚为Windows安装了Git,很高兴看到它安装了Bash。

我想以同样的方式自定义shell,我可以在Linux下(例如设置别名ll为ls -l),但我似乎找不到.bashrc或等效的配置文件。

我应该编辑什么?


当前回答

如果你想在打开Git Bash时有项目选择列表:

编辑代码头中的ppath到你的Git项目路径,把这段代码放在。bashrc文件中,并复制到你的$HOME目录中(在Windows Vista / Windows 7中通常是C:\Users\$YOU)

.

#!/bin/bash
ppath="/d/-projects/-github"
cd $ppath
unset PROJECTS
PROJECTS+=(".")
i=0

echo
echo -e "projects:\n-------------"

for f in *
do
    if [ -d "$f" ]
    then
        PROJECTS+=("$f")
        echo -e $((++i)) "- \e[1m$f\e[0m"
    fi
done


if [ ${#PROJECTS[@]} -gt 1 ]
then
    echo -ne "\nchoose project: "
    read proj
    case "$proj" in
        [0-`expr ${#PROJECTS[@]} - 1`]) cd "${PROJECTS[proj]}" ;;
        *) echo " wrong choice" ;;
    esac
else
    echo "there is no projects"
fi
unset PROJECTS

你可能想在Git Bash chmod +x .bashrc中将这个文件设置为可执行文件(但这可能是多余的,因为这个文件存储在NTFS文件系统上)

其他回答

有时文件实际上位于~/。以下是我在Visual Studio Code/Windows 10上启动Zsh作为默认终端的步骤。

cd ~ / vim . bashrc 粘贴下面的…

如果test -t 1;然后 exec zsh fi

保存/关闭Vim。 重启终端

请使用以下命令,

cat /etc/bash.bashrc > ~/.bashrc

这将生成一个具有默认值的新bashrc文件。请使用vi ~/。Bashrc来编辑此文件。

我认为这里的问题是如何在Windows上找到。bashrc文件。

由于您使用的是Windows,您可以简单地使用命令,如

start .

OR

explorer .

打开Git Bash安装根目录下的窗口,你会发现.bashrc文件。如果它不存在,您可能需要创建一个。

您可以使用notepad++等Windows工具来编辑文件,而不是在Bash窗口中使用Vim。

访问:C:\Program Files\Git\etc\profile.你在里面找到你需要的一切。 或者在您的主目录中创建.bashrc和.bash_profile。

. bash_profile

# generated by Git for windows
test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc

. bashrc

echo "Hello World!"

在新版本的Git for Windows中,Bash以——login启动,这导致Bash不能直接读取.bashrc。相反,它读取.bash_profile。

如果~ /。Bash_profile文件不存在,按照如下内容创建Bash_profile文件:

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

这将导致Bash读取.bashrc文件。根据我对这个问题的理解,Git for Windows应该自动完成这个任务。但是,我刚刚安装了2.5.1版本,它没有。