显示标签为“bash”的博文。显示所有博文
显示标签为“bash”的博文。显示所有博文

2020-10-12

arch-bash

 
1. 提示符生成器
2. 自定义命令补全
3. 历史补全
4. 更近的历史记录
5. 找不到命令
6. history
7. 彩色的man
8. 有关LESS_TERMCAP_ *变量的文档?
	8.1 Terminfo和Termcap(详细信息)
9. 更多有用的.bashrc命令

 

本文介绍笔者认为有必要的bash基本设置。

https://wiki.archlinux.org/index.php/Bash

1. 提示符生成器

PS1生成器-使用拖放界面生成.bashrc / PS1 bash提示

http://bashrcgenerator.com/
比如: 方括号时间,路径,换行,上一条命令的返回码,标准提示符,空格
PS1="[\A]\w\n\$?\\$ \[$(tput sgr0)\]"
下面是彩色版本:
PS1="[\[$(tput sgr0)\]\[$(tput bold)\]\[\033[38;5;208m\]\A\[$(tput sgr0)\]]\[$(tput sgr0)\]\[\033[38;5;81m\]\w\[$(tput sgr0)\]\n\$?\\$ \[$(tput sgr0)\]"

返回码放到时间后面:
PS1="[\[$(tput sgr0)\]\[$(tput bold)\]\[\033[38;5;202m\]\A\[$(tput sgr0)\]]\[$(tput sgr0)\]\[\033[38;5;205m\]\$?\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;87m\]\w\[$(tput sgr0)\]\n\\$ \[$(tput sgr0)\]"

2. 自定义命令补全

注意: 使用 complete 功能可能与 bash-completion 冲突。
通常来讲,Bash 中按下 tab 只会补全命令后的文件名。通过complete -c命令,Bash 可以规定某些命令后的补全形式为命令,比如:
或通过-cf命令,规定补全形式为命令和文件,比如:
complete -cf sudo

3. 历史补全

您可以绑定上下键来在 Bash 的历史中查找(请参考 Readline (简体中文)#历史 and Readline 启动文件语法):
~/.bash
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
或者所有 Readline 程序:
~/.inputrc
"\e[A": history-search-backward
"\e[B": history-search-forward

4. 更近的历史记录

HISTCONTROL变量可以避免历史记录记录特定的命令,比如不记录重复的命令

~/.bashrc
export HISTCONTROL=ignoredups

HISTCONTROL,和 HISTIGNORE 类似,也是用来忽略某些历史记录。
HISTCONTROL=ignoredups:忽略连续重复的命令
HISTCONTROL=ignorespace:忽略以空白字符开头的命令
HISTCONTROL=ignoreboth:同时忽略以上两种
HISTCONTROL=erasedups:忽略所有历史命令中的重复命令

5. 找不到命令

pkgfile 提供了一个"找不到命令"的钩子,可以在输入未知命令后自动查找官方的软件包。
你需要加载这个钩子来启用它,如下:
~/.bashrc
source /usr/share/doc/pkgfile/command-not-found.bash

6. history

export HISTFILESIZE=20000
export HISTSIZE=10000

$ echo $HISTFILE
/home/tom/.bash_history
注: 可以直接修改这个文件,改变历史记录
$ echo $HISTFILESIZE
20000
$ echo $HISTSIZE
10000

7. 彩色的man

export LESS_TERMCAP_mb=$(tput bold; tput setaf 2) # green
export LESS_TERMCAP_md=$(tput bold; tput setaf 6) # cyan
export LESS_TERMCAP_me=$(tput sgr0)
export LESS_TERMCAP_so=$(tput bold; tput setaf 3; tput setab 4) # yellow on blue
export LESS_TERMCAP_se=$(tput rmso; tput sgr0)
export LESS_TERMCAP_us=$(tput smul; tput bold; tput setaf 7) # white
export LESS_TERMCAP_ue=$(tput rmul; tput sgr0)
export LESS_TERMCAP_mr=$(tput rev)
export LESS_TERMCAP_mh=$(tput dim)
export LESS_TERMCAP_ZN=$(tput ssubm)
export LESS_TERMCAP_ZV=$(tput rsubm)
export LESS_TERMCAP_ZO=$(tput ssupm)
export LESS_TERMCAP_ZW=$(tput rsupm)
export GROFF_NO_SGR=1         # For Konsole and Gnome-terminal

一些简称对照,更多可参阅 $ man terminfo

termcap	terminfo	des…	cn
ks	smkx	make the keypad send commands	使键盘发送命令
ke	rmkx	make the keypad send digits	使键盘发送数字
vb	flash	emit visual bell		发出视觉铃声
mb	blink	start blink			开始闪烁
md	bold	start bold			开始粗体
me	sgr0	turn off bold, blink and underline	关闭粗体,闪烁和下划线
so	smso	start standout (reverse video)	开始突出(反向视频)
se	rmso	stop standout			停止突出
us	smul	start underline			开始下划线
ue	rmul	stop underline			停止下划线

8. 有关LESS_TERMCAP_ *变量的文档?

https://unix.stackexchange.com/questions/108699/documentation-on-less-termcap-variables
翻译: https://qastack.cn/unix/108699/documentation-on-less-termcap-variables
https://unix.stackexchange.com/questions/119/colors-in-man-pages/147#147

8.1 Terminfo和Termcap(详细信息)

https://tldp.org/HOWTO/Text-Terminal-HOWTO-16.html
Terminfo(以前的Termcap)是一个包含终端功能及更多功能的数据库。对于终端的每个(几乎)模型,它告诉应用程序终端能够做什么。它会告诉发送到终端的哪些转义序列(或控制字符),以执行诸如将光标移至新位置,擦除屏幕的一部分,滚动屏幕,更改模式,更改外观(颜色,亮度,闪烁,下划线,倒转视频等)。大约在1980年以后,许多终端都支持一百多种不同的命令(其中一些带有数字参数)。

terminfo缩写通常比termcap的缩写长,因此更容易猜测它们的含义。terminfo的手册页更加详细(并包括旧的termcap缩写)。而且,termcap条目具有对terminfo不存在的大小限制。因此,除非您已经致力于使用termcap,否则建议您使用terminfo。

要查看您现在正在使用的终端(包括PC监视器)的数据库显示,请键入“ infocmp”,并且您应该看到它的源terminfo“文件”。
$ infocmp

 1 $ infocmp
 2 #    Reconstructed via infocmp from file: /usr/share/terminfo/x/xterm-256color
 3 xterm-256color|xterm with 256 colors,
 4     am, bce, ccc, km, mc5i, mir, msgr, npc, xenl,
 5     colors#0x100, cols#80, it#8, lines#24, pairs#0x10000,
 6     acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
 7     bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, civis=\E[?25l,
 8     clear=\E[H\E[2J, cnorm=\E[?12l\E[?25h, cr=\r,
 9     csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
10     cud=\E[%p1%dB, cud1=\n, cuf=\E[%p1%dC, cuf1=\E[C,
11     cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
12     cvvis=\E[?12;25h, dch=\E[%p1%dP, dch1=\E[P, dim=\E[2m,
13     dl=\E[%p1%dM, dl1=\E[M, ech=\E[%p1%dX, ed=\E[J, el=\E[K,
14     el1=\E[1K, flash=\E[?5h$<100/>\E[?5l, home=\E[H,
15     hpa=\E[%i%p1%dG, ht=^I, hts=\EH, ich=\E[%p1%d@,
16     il=\E[%p1%dL, il1=\E[L, ind=\n, indn=\E[%p1%dS,
17     initc=\E]4;%p1%d;rgb\:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\,
18     invis=\E[8m, is2=\E[!p\E[?3;4l\E[4l\E>, kDC=\E[3;2~,
19     kEND=\E[1;2F, kHOM=\E[1;2H, kIC=\E[2;2~, kLFT=\E[1;2D,
20     kNXT=\E[6;2~, kPRV=\E[5;2~, kRIT=\E[1;2C, ka1=\EOw,
21     ka3=\EOy, kb2=\EOu, kbs=^H, kc1=\EOq, kc3=\EOs, kcbt=\E[Z,
22     kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA,
23     kdch1=\E[3~, kend=\EOF, kent=\EOM, kf1=\EOP, kf10=\E[21~,
24     kf11=\E[23~, kf12=\E[24~, kf13=\E[1;2P, kf14=\E[1;2Q,
25     kf15=\E[1;2R, kf16=\E[1;2S, kf17=\E[15;2~, kf18=\E[17;2~,
26     kf19=\E[18;2~, kf2=\EOQ, kf20=\E[19;2~, kf21=\E[20;2~,
27     kf22=\E[21;2~, kf23=\E[23;2~, kf24=\E[24;2~,
28     kf25=\E[1;5P, kf26=\E[1;5Q, kf27=\E[1;5R, kf28=\E[1;5S,
29     kf29=\E[15;5~, kf3=\EOR, kf30=\E[17;5~, kf31=\E[18;5~,
30     kf32=\E[19;5~, kf33=\E[20;5~, kf34=\E[21;5~,
31     kf35=\E[23;5~, kf36=\E[24;5~, kf37=\E[1;6P, kf38=\E[1;6Q,
32     kf39=\E[1;6R, kf4=\EOS, kf40=\E[1;6S, kf41=\E[15;6~,
33     kf42=\E[17;6~, kf43=\E[18;6~, kf44=\E[19;6~,
34     kf45=\E[20;6~, kf46=\E[21;6~, kf47=\E[23;6~,
35     kf48=\E[24;6~, kf49=\E[1;3P, kf5=\E[15~, kf50=\E[1;3Q,
36     kf51=\E[1;3R, kf52=\E[1;3S, kf53=\E[15;3~, kf54=\E[17;3~,
37     kf55=\E[18;3~, kf56=\E[19;3~, kf57=\E[20;3~,
38     kf58=\E[21;3~, kf59=\E[23;3~, kf6=\E[17~, kf60=\E[24;3~,
39     kf61=\E[1;4P, kf62=\E[1;4Q, kf63=\E[1;4R, kf7=\E[18~,
40     kf8=\E[19~, kf9=\E[20~, khome=\EOH, kich1=\E[2~,
41     kind=\E[1;2B, kmous=\E[<, knp=\E[6~, kpp=\E[5~,
42     kri=\E[1;2A, mc0=\E[i, mc4=\E[4i, mc5=\E[5i, meml=\El,
43     memu=\Em, mgc=\E[?69l, oc=\E]104\007, op=\E[39;49m, rc=\E8,
44     rep=%p1%c\E[%p2%{1}%-%db, rev=\E[7m, ri=\EM,
45     rin=\E[%p1%dT, ritm=\E[23m, rmacs=\E(B, rmam=\E[?7l,
46     rmcup=\E[?1049l\E[23;0;0t, rmir=\E[4l, rmkx=\E[?1l\E>,
47     rmm=\E[?1034l, rmso=\E[27m, rmul=\E[24m,
48     rs1=\Ec\E]104\007, rs2=\E[!p\E[?3;4l\E[4l\E>, sc=\E7,
49     setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m,
50     setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m,
51     sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p5%t;2%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
52     sgr0=\E(B\E[m, sitm=\E[3m, smacs=\E(0, smam=\E[?7h,
53     smcup=\E[?1049h\E[22;0;0t,
54     smglr=\E[?69h\E[%i%p1%d;%p2%ds, smir=\E[4h,
55     smkx=\E[?1h\E=, smm=\E[?1034h, smso=\E[7m, smul=\E[4m,
56     tbc=\E[3g, u6=\E[%i%d;%dR, u7=\E[6n,
57     u8=\E[?%[;0123456789]c, u9=\E[c, vpa=\E[%i%p1%dd,
View Code

 

https://en.wikipedia.org/wiki/Termcap
https://en.wikipedia.org/wiki/Terminfo
Terminfo是一个库和数据库,可让程序以独立于设备的方式使用显示终端。
terminfo数据库可以描述数百个不同显示终端的功能。这使外部程序能够具有基于字符的显示输出,而与终端的类型无关。一些配置是:

  • 屏幕上的行数
  • 单声道模式 抑制颜色
  • 使用可见的铃铛代替蜂鸣声

Terminfo数据库由一个或多个终端描述组成。

 

https://wiki.archlinux.org/index.php/Readline#Editing_mode
Readline是GNU Project的库,Bash和其他CLI界面程序使用它来编辑命令行并与之交互。有关更多信息,请参见readline(3)。

9. 更多有用的.bashrc命令

https://serverfault.com/questions/3743/what-useful-things-can-one-add-to-ones-bashrc
https://ubuntuforums.org/showthread.php?t=679762

 

2019-08-27

shell-Startup-Files

shell-Startup-Files

1. 相关阅读
2. 主流shell
3. shell实例类型
4. Shell启动文件的必要元素
 4.1 路径: 命令路径, 
 4.2 提示符
5. 主流shell的配置文件
6. 默认的bash
 6.1 手册
 6.2 bash启动文件
 6.3 提示符
7. 友好的fish
 7.1 简介
 7.2 查看帮助文档
 7.3 fish的配置
8. zsh

1. 相关阅读


https://www.cnblogs.com/sztom/p/11349159.html
shell脚本

https://szosoft.blogspot.com/2019/07/console-terminal-tty-shell-kernel.html
https://www.cnblogs.com/sztom/p/11247883.html
Console-terminal-tty-shell-kernel
Shell在计算机系统中的位置

http://hyperpolyglot.org/unix-shells
常用shell语法对照(Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh)

https://en.wikipedia.org/wiki/Comparison_of_command_shells

https://opensource.com/business/16/3/top-linux-shells
Linux的前5个开源命令shell

https://www.ibm.com/developerworks/cn/aix/library/au-spunix_fish/index.html
Friendly Interactive Shell(fish)对于 UNIX 新手和专家都很适合

https://wiki.archlinux.org/index.php/Command-line_shell
https://wiki.archlinux.org/index.php/Command-line_shell#POSIX_compliant
https://wiki.archlinux.org/index.php/Command-line_shell#Alternative_shells

https://en.wikipedia.org/wiki/Unix_shell
https://en.wikipedia.org/wiki/Unix_shell#Configuration_files

https://wiki.gentoo.org/wiki/Shell
https://wiki.gentoo.org/wiki/Shell#Available_software

https://en.wikibooks.org/wiki/Bash_Shell_Scripting

https://developer.ibm.com/tutorials/l-linux-shells/


2. 主流shell

Name Description POSIX License user
bash
(默认)
The Bourne Again Shell, is the default shell on Gentoo. It is used by Portage, Gentoo's default package manager. 符合 compliant GPLv3 54%
fish
(友好)
The Friendly Interactive Shell. (2005) Alternative 替代 GPLv2… 12%
zsh
(极客)
An advanced shell that is the chosen interactive shell for many users. 符合 compliant MIT, GPL 23%
tcsh an enhanced version of the Berkeley C Shell (csh). Alternative 替代 BSD 3%
ksh The Original Korn Shell, 1993 revision (ksh93). 符合 compliant Eclipse Public 3%
Other


5%


https://developer.ibm.com/tutorials/l-linux-shells/#unix-shells-since-1977
https://developer.ibm.com/developer/tutorials/l-linux-shells/images/figure1.gif

3. shell实例类型


大类 小类 系统配置文件 用户配置文件
交互式 登录shell (初始shell) /etc/profile .bash_profile;
.bash_login;
.profile …
交互式 非登录shell /etc/bash.bashrc .bashrc
非交互式 运行shell脚本的shell等 通常不读取启动文件

4. Shell启动文件的必要元素

路径,提示符,别名alias,权限掩码(077;022)

4.1 路径: 命令路径,

/usr/local/bin
/usr/bin
/bin
这个顺序可以确保/usr/local中的特定变体覆盖默认程序。
大多数Linux发行版中,几乎所有软件包都会被安装到/usr/bin中。也有少数情况(游戏: /usr/games; 图形应用还有另外的地方)
可以将一些分散程序的符号链接放到/usr/local/bin中。

若对系统工具感兴趣(traceroute,ping,lsmod...),可以为路径加上sbin目录。
/usr/local/sbin
/usr/sbin
/sbin

帮助手册的路径: 建议不要修改。
传统的帮助手册路径来自环境变量MANPATH. /etc/manpath.config

4.2 提示符

PS1='[\u@\h \w]\n\A \!-\#\$ '


5. 主流shell的配置文件


files bash sh ksh zsh tcsh
/etc/.login



login
/etc/csh.login



login
~/.login



login
~/.logout



login
/etc/csh.cshrc



yes
~/.tcshrc ; ~/.cshrc



yes[a]
~/etc/ksh.kshrc

int.

/etc/sh.shrc
int.[b]


$ENV (typically ~/.kshrc) int.[e] int.[c][d] int.

~/.bashrc int.+n/login



~/.bash_profile login[g]



~/.bash_login login[g]



~/.bash_logout login



~/.profile login[g] login login login[f]
/etc/profile login login login login[f]
/etc/zshenv


yes
/etc/zprofile


login
/etc/zlogin


login
/etc/zlogout


login
/etc/zshrc


int.
~/.zshenv


yes
~/.zprofile


login
~/.zlogin


login
~/.zshrc


int.


n/login 表示如果shell不是登录shell,则读取文件。
login 表示如果shell是登录shell,则读取文件。
int. 表示如果shell是交互式的,则读取文件。
yes 表示shell在启动时始终读取文件。
" " 空白表示shell根本不读取文件。


[a] 仅在找不到~/.tcshrc时
[b] 仅限Bourne Shell的较新版本
[c] 适用于支持"用户可移植性实用程序"选项的系统; 变量的值必须是绝对路径,如果用户的真实有效用户ID或真实有效的组ID不同,则忽略它。
[d] $ENV是在Bourne Shell中的较新版本$HOME/.shrc
[e] 与 sh相同的行为,但仅在调用为 sh(bash 2+)或者自bash 4.2时,如果在POSIX兼容模式中显式调用(使用选项 --posix或 -o posix).
[f] a,b仅在sh/ksh兼容模式下(当调用为bash,sh,ksh时)
[g] 实际上是b,c,~/ .bash_profile的第一个可读,~/ .bash_login和~/ .profile ; 并且只有~/ .profile如果被调用为sh或者,至少在Bash 4.2中,如果在POSIX兼容模式中显式调用(带有选项--posix或-o posix)

6. 默认的bash

Bash主页是 http://www.gnu.org/software/bash/
https://wiki.archlinux.org/index.php/Bash
https://wiki.archlinux.org/index.php/Bash#Configuration_files

https://wiki.gentoo.org/wiki/Bash

6.1 手册

https://www.gnu.org/software/bash/manual/bash.html
file:///usr/share/doc/bash/bashref.html

6.2 bash启动文件

https://www.gnu.org/software/bash/manual/bash.html#Bash-Startup-Files

文件 描述 登录shell 交互,
非登录shell
/etc/profile 来源在应用程序设置/etc/profile.d/*.sh和/etc/bash.bashrc。 Yes No
~/.bash_profile 用户,之后/etc/profile。如果这个文件不存在,~/.bash_login并~/.profile按照此顺序检查。骨架文件/etc/skel/.bash_profile也来源~/.bashrc。 Yes No
~/.bash_logout 退出登录shell后。 Yes No
/etc/bash.bashrc 取决于-DSYS_BASHRC="/etc/bash.bashrc"编译标志。来源/usr/share/bash-completion/bash_completion。 No Yes
~/.bashrc 每用户,之后/etc/bash.bashrc。 No Yes

https://zhuanlan.zhihu.com/p/33833752
如何列出所有的 Bash Shell 内置命令


6.3 提示符

PS1='[\u@\h \w]\n\A \!-\#\$ '

PS1='\e[0;36m\][\u@\h \w]\e[0m\] \e[0;32m\]\n\A \!-\#\$\e[0m\] '
PS1='\e[0;36m\][\u@\h \w] \e[0;32m\]\n\A \!-\#\$\e[0m\] '

Code Color
\e[0;30m\] Black
\e[0;31m\] Red
\e[0;32m\] Green
\e[0;33m\] Yellow
\e[0;34m\] Blue
\e[0;35m\] Magenta 品红
\e[0;36m\] Cyan 青色
\e[0;37m\] White
\e[0m\] Reset to standard colors 重置为标准色

7. 友好的fish

7.1 简介

https://en.wikipedia.org/wiki/Friendly_interactive_shell
https://zh.wikipedia.org/wiki/Fish
fish的设计目标是以易于发现,记忆和使用的方式为用户提供丰富的强大功能。
它的语法既不来自Bourne shell(ksh,bash,zsh)也不是C shell(csh,tcsh)。
与以前的shell(默认情况下禁用某些功能以节省系统资源)不同,fish默认启用所有功能。

https://wiki.archlinux.org/index.php/Fish
https://wiki.archlinux.org/index.php/Fish_(简体中文)
fish被有意设计成不完全与POSIX兼容。
fish的作者们认为POSIX中存在一些缺陷和矛盾,并通过fish简化的或不同的语法解决这些问题。
因此,即使简单的POSIX兼容的脚本也可能需要较多的修改,甚至完全重写,才能在fish中运行。
https://wiki.archlinux.org/index.php/Fish#Setting_fish_as_interactive_shell_only
只把fish设为交互式shell

https://wiki.gentoo.org/wiki/Fish
fish是OS X,Linux和其他家族的智能且用户友好的命令行shell。
fish包含语法突出显示,自动提示类型和精美的选项卡完成等功能,无需配置。
Fish不是POSIX 1003.1兼容的shell。它不读取/etc/profile,/etc/profile.env或/etc/profile.d/*目录。
建议不要将fish设置为默认登录shell.
这里有其中一位鱼类开发者和Arch wiki建议的技巧。这使得fish shell能够继承bash环境(写入并应该由bash shell 执行)
详见: https://wiki.gentoo.org/wiki/Fish#.bashrc_safety_net

https://github.com/fish-shell/fish-shell

7.2 查看帮助文档

$ help
file:///usr/share/doc/fish/index.html#docs
与其他shell不同,这里直接打开web页面文档,更方便查看,还能使用网页翻译。与下方官网页面相同。
https://fishshell.com/docs/current/index.html

官网的教学及常见问题
https://fishshell.com/docs/current/tutorial.html
https://fishshell.com/docs/current/faq.html

7.3 fish的配置

$ fish_config
Web config started at 'file:///home/toma/.cache/fish/web_config-S2EKS6.html'. Hit enter to stop.
不需要编写脚本,不需要手动修改配置文件,使用 fish_config 命令打开网页即可。
比如: http://localhost:8000/6d9de3bf1bf313e974c9738471da505c/#/colors
  • colors 配色模式 (我选择了省电的黑色背景,彩色文字模式)
  • prompt 提示符号 (我选择了完整路径显示加时间,加换行模式)
  • functions 功能
  • variables 变量
  • history 历史 (这里可以看到所有已经使用过的历史命令,可以手动删除不需要的命令)
  • bindings 绑定
  • abbreviations 缩写

8. zsh

这个可以吧shell玩的很酷炫,有非常多的插件可以选择。
也要话时间适应研究,这里就直接跳过了。
网络上有非常多的相关文章可共参考。

Sound

导航 (返回顶部) 1. Sound 1.1 声-音 1.2 声波的性质及特性 2. 声音频率 2.1 听力范围 2.2 VF-语音频率 2.3 人声基本频率 2.4 8度音阶表 2.5 综合表 3. 声波 3.1 Compression and she...