2023-06-12

MacOS-shell-PS1

1. shell
	1.1 查看当前使用的shell
	1.2 查看系统支持那些shell
	1.3 修改默认的shell解释器
2. PS1命令提示符
	2.1 查看当前的PS1
	2.2 临时修改PS1
	2.3 永久修改PS1
	2.4 添加命令序号,时间
	2.5 彩色显示
	2.6 文件类型
	2.7 彩色的命令前缀
3. 其他
	3.1 增加命令历史记录数量
	3.2 意外状况
	3.3. zshrc


1. shell

1.1 查看当前使用的shell

 % echo $SHELL
  /bin/zsh
 % echo $0
  -zsh
 % env | grep SHELL
  SHELL=/bin/zsh

1.2 查看系统支持那些shell

 % cat /etc/shells
 # List of acceptable shells for chpass(1).
 # Ftpd will not allow users to connect who are not using
 # one of these shells.
/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh

1.3 修改默认的shell解释器

 % chsh -s /bin/sh 

2. PS1命令提示符

2.1 查看当前的PS1

 % echo $PS1
%n@%m %1~ %

2.2 临时修改PS1

 % export PS1="%n@%m %1~ %"
tom@tomdeMacBook-Air ~ % 
缩减前缀
 % export PS1="%n %1~ %"
 

2.3 永久修改PS1

直接运行export,仅在当前终端会话期间生效,关闭重开后,刚修改的命令前缀就会失效。
若要保留修改,可将以上命令写入用户的配置文件。
当前使用的shell是zsh,用户目录下相关的隐藏文件有:
 % ls -a |grep zsh 
 .zsh_history 
 .zsh_sessions 
 .zshrc  
 % pwd 
/Users/tom
访达窗口,使用快捷键 [command]+[shift]+[.] 显示隐藏文件
将上面的命令写入配置文件(.zshrc),然后执行下面的命令,刷新当前shell的配置。即刻生效。
 % source ~/.zshrc 

注:/etc/profile系统配置文件:对所有用户都生效,但会被用户的设置覆盖。不建议修改此文件。

2.4 添加命令序号,时间

 % export PS1="%n[%h][%T] %1~ %"
tom[1072][3:34] ~ % 

2.5 彩色显示

当前的zsh开启彩色模式
export CLICOLOR=1
ls,查看目录文件,就能看到不同的类型使用不同的颜色显示
有些shell或许还需要下面的命令指定文件类型的颜色
export LSCOLORS=ExGxFxdaCxDaDahbadeche
这里有详细的字母对照解释

2.6 文件类型

代码 文件类型 说明:
d directory, 目录 目录
l symbolic link,
符号链接
符号链接,ln命令生成的文件
s socket,
套接字
(伪文件) 套接字(sockets), 数据接口文件,通常用在网络数据连接。
可以启动一个程序来监听客户端的要求,客户端就可以通过套接字来进行数据通信。
最常在/var/run
p pipe, 管道 (伪文件) 管道(pipe, FIFO,数据输送文件),
FIFO也是一种特殊的文件类型,
它主要的目的是,解决多个程序同时存取一个文件所造成的错误。
b block special,
块设备
(伪文件) 区块设备(block), 存储数据以供系统存取的接口设备。
比如硬盘分区。/dev/
c character special,
字符设备
(伪文件) 字符设备(character),即串行端口的接口设备。
例如键盘、鼠标等,这些设备的特色就是(一次性读取),不能截断输出。
- regular,
普通文件
普通文件, 纯文本文件(ASCII);二进制文件(binary);
数据格式的文件(data);各种压缩文件.

MacOS的app应用程序在ls命令下显示为和目录一样的d类型。
文件类型 说明:
executable 可执行的
executable with setuid bit set 设置了 setuid 位的可执行文件
executable without setgid bit set 未设置 setgid 位的可执行文件
directory writable to others, with sticky bit 其他人可写的目录,有粘性位
directory writable to others, without sticky bit 其他人可写的目录,没有粘滞位

2.7 彩色的命令前缀

autoload -U colors && colors 
PROMPT="%{$fg_bold[cyan]%}%n%{$reset_color%}[%h] %{$fg_bold[green][%T] %{$fg_bold[yellow]%}%1~ %{$reset_color%}%# "
以上命令添加到用户配置文件即可,这里用的是 source ~/.zshrc 
说明: %n 用户名;[%h] 命令序号;[%T] 时间;%1~ 目录 
$fg的意思为颜色浅一些。$fg_bold意思为颜色深一些。[ ]里的就是颜色。
上面这个命令的写法,可选用的颜色有:
  • 黑 black
  • 红 red
  • 绿 green
  • ⻩ yellow
  • 蓝 blue
  • 紫 magenta
  • ⻘ cyan
  • 白 white

3. 其他

3.1 增加命令历史记录数量

export HISTFILESIZE=20000
export HISTSIZE=10000

3.2 意外状况

tom[1006] [12:19] ~ % brew list    
zsh: command not found: brew 
tom[1007] [12:19] ~ % /opt/homebrew/bin/brew list
修改了前缀后,使用brew命令,提示找不到命令了?但使用完整路径则可以正常运行
查看路径参数,不明白为什么丢失了homebrew的路径,有知道的还请告知。
tom[1007] [12:19] ~ % echo $PATH                 
/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
对比之前的路径
tom@tomdeMacBook-Air ~ % echo $PATH
/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
正好缺少了这2个路径,原因不明,手动添加即可。
/opt/homebrew/bin:/opt/homebrew/sbin:
这里添加到配置文件里,
export PATH=/opt/homebrew/bin:/opt/homebrew/sbin:$PATH
然后刷新配置文件 
 % source ~/.zshrc 

3.3 zshrc

文件总揽
 % cat ~/.zshrc 
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
# export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles
# export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
# export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.cloud.tencent.com/homebrew-bottles
# export HOMEBREW_BOTTLE_DOMAIN=''

export HISTFILESIZE=20000
export HISTSIZE=10000
export PATH=/opt/homebrew/bin:/opt/homebrew/sbin:$PATH
export CLICOLOR=1

autoload -U colors && colors
PROMPT="%{$fg_bold[cyan]%}%n%{$reset_color%}[%h] %{$fg_bold[green][%T] %{$fg_bold[yellow]%}%1~ %{$reset_color%}%# "

补充:参考下文,还有更多选择

Diode

导航 (返回顶部) 1. Diode 1.1 Diode 概述 1.2 肖克利二极管方程 1.3 缩写 Abbreviations 2. 主要功能 2.1 单向电流 (Unidirectional current flow) 2.2 阈值电压 (Threshold...