我刚刚为Windows安装了Git,很高兴看到它安装了Bash。
我想以同样的方式自定义shell,我可以在Linux下(例如设置别名ll为ls -l),但我似乎找不到.bashrc或等效的配置文件。
我应该编辑什么?
我刚刚为Windows安装了Git,很高兴看到它安装了Bash。
我想以同样的方式自定义shell,我可以在Linux下(例如设置别名ll为ls -l),但我似乎找不到.bashrc或等效的配置文件。
我应该编辑什么?
当前回答
使用nodepad++: alias .sh编辑该文件
C:\Program Files\Git\etc\profile.d\aliases.sh
你会看到你需要的一切。
其他回答
在新版本的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版本,它没有。
访问: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!"
我认为这里的问题是如何在Windows上找到。bashrc文件。
由于您使用的是Windows,您可以简单地使用命令,如
start .
OR
explorer .
打开Git Bash安装根目录下的窗口,你会发现.bashrc文件。如果它不存在,您可能需要创建一个。
您可以使用notepad++等Windows工具来编辑文件,而不是在Bash窗口中使用Vim。
如果您使用的是Git for Windows 2.21.0或更高版本(在撰写本文时),则应该在主目录中编辑.bash_profile。
你可以直接将.bash_profile指向.bashrc,但是如果你的.bash_profile发生了什么,那么就不清楚为什么你的.bashrc不能工作。
我把我所有的别名和其他环境的东西放在.bash_profile中,我还添加了这一行:
echo "Sourcing ~/.bash_profile - this version of Git Bash doesn't use .bashrc"
然后,在。bashrc中
echo "This version of Git Bash doesn't use .bashrc. Use .bash_profile instead"
(基于@harsel的回应。我本想发表评论,但我现在还没有观点。)
我必须添加一个用户环境变量,HOME, C:\Users\<你的用户名>,方法是转到系统,高级系统设置,在系统属性窗口,高级选项卡,环境变量…
然后在我的C:\Users\<你的用户名>中,我创建了文件.bashrc,例如,触摸.bashrc并添加所需的别名。