.bash_profile/.bashrc/.zshrc
灾难性事件,电脑硬盘挂了。那么近几天我所做的是恢复之前的配置
需求如上图:
terminal 中显示 git 分支,当前路径,主机及用户名
几个 bash 配置文件的说明
-
/etc/profile
为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行,并从/etc/profile.d
目录的配置文件中搜集 shell 的设置 -
/etc/bashrc
为每个运行 bash shell 的用户执行此文件,当 bash shell 被打开时,该文件被读取 -
~/.bash_profile
每个用户可以使用该文件输入专用于自己使用的 shell 信息,当用户登录时 该文件仅仅执行一次。默认情况下,他设置一些环境变量,执行用户的 .bashrc 文件 -
~/.bashrc
该文件包含专用于你的 bash shell 的 bash 信息,当登录时以及每次打开新的 shell 时,该文件读取
另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是”父子”关系.
login shell
通过终端输入用户名和密码,进入 terminal 的 shell 环境,ssh 进入远程主机
。
no-login shell 环境
无需用户名和密码进入的 shell 环境,从桌面终端进入
的 shell 环境就是 no-login shell。
想通过 login shell 运行的命令放在
.bash_profile
中,想通过 no login shell 运行的命令则放入 .bashrc 中
Mac OS 中,运行 termianl 时系统默认运行 login shell。所以 $home 中没 .bashrc
.bashrc 配置图片需求
terminal 中显示 git 分支,当前路径,主机及用户名
1 | find_git_branch() { |
.bash_profile
1 | #.bash_profile 文件中添加如下代码 |
运行
source .bash_profil
使配置生效。目前这种方式仅一次有效
.zshrc
zsh mac 下最好用的终端,新建 ~/.zshrc
,添加 source ~/.bash_profile
使 .bashrc
下的配置永久有效
1 | zshrc 下配置 |
ERROR 切换分支后,分支号没有实时更新
1 | # ~/.zshrc |