我刚刚为Windows安装了Git,很高兴看到它安装了Bash。
我想以同样的方式自定义shell,我可以在Linux下(例如设置别名ll为ls -l),但我似乎找不到.bashrc或等效的配置文件。
我应该编辑什么?
我刚刚为Windows安装了Git,很高兴看到它安装了Bash。
我想以同样的方式自定义shell,我可以在Linux下(例如设置别名ll为ls -l),但我似乎找不到.bashrc或等效的配置文件。
我应该编辑什么?
当前回答
访问: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!"
其他回答
请使用以下命令,
cat /etc/bash.bashrc > ~/.bashrc
这将生成一个具有默认值的新bashrc文件。请使用vi ~/。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文件系统上)
在Windows上:
你可以在C:\Users\[YourUserName]目录下找到。bashrc
使用nodepad++: alias .sh编辑该文件
C:\Program Files\Git\etc\profile.d\aliases.sh
你会看到你需要的一切。
如果您使用的是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的回应。我本想发表评论,但我现在还没有观点。)