我将rxvt-unicode, version9.22用作终端模拟器,并使用文件~/.Xresources.
当我修改配置文件时,为了立即查看效果,我执行命令:
xrdb ~/.Xresources
Run Code Online (Sandbox Code Playgroud)
来自man xrdb:
以感叹号 (!) 开头的行将被忽略并可用作注释。
在我的机器上,使用xrdbversion 1.1.0,当注释行包含奇数个单引号时,例如! it's a comment,会xrdb报错,例如:
/home/user/.Xresources:1:5: warning: missing terminating ' character
! it's a comment
^
Run Code Online (Sandbox Code Playgroud)
目前,我将单引号加倍以避免此错误:
! it''s a comment
Run Code Online (Sandbox Code Playgroud)
我想我也可以使用/* */, 而不是!,因为它是 Vim 默认使用的注释字符串(在 中定义$VIMRUNTIME/ftplugin/xdefaults.vim)。但我更喜欢使用!,因为我发现用它来评论更具可读性。
有没有办法要求xrdb忽略注释行内的单引号~/.Xresources?
我试图了解这个zsh小部件的工作原理:
expand-aliases() {\n unset \'functions[_expand-aliases]\'\n functions[_expand-aliases]=$BUFFER\n (($+functions[_expand-aliases])) &&\n BUFFER=${functions[_expand-aliases]#$\'\\t\'} &&\n CURSOR=$#BUFFER\n}\n\nzle -N expand-aliases\nbindkey \'\\e^E\' expand-aliases\nRun Code Online (Sandbox Code Playgroud)\n\n我在这个答案中找到了代码。它的目的是当您点击 时展开命令行上的所有别名C-M-e。
它有效,但代码中有几件事我不明白。
\n\n这是我认为我理解的和我不理解的:
\n\nzle -N expand-aliases\nRun Code Online (Sandbox Code Playgroud)\n\n此行安装一个名为的小部件expand-aliases,它将调用具有相同名称的函数。
bindkey \'\\e^E\' expand-aliases\nRun Code Online (Sandbox Code Playgroud)\n\n该行将小部件绑定到关键和弦C-M-e。
unset \'functions[_expand-aliases]\'\nRun Code Online (Sandbox Code Playgroud)\n\n我不明白这一行,因为我不知道数组functions是如何填充的。
functions[_expand-aliases]=$BUFFER\nRun Code Online (Sandbox Code Playgroud)\n\n该行将当前命令行的内容存储在关联数组内functions,键为_expand-aliases。
(($+functions[_expand-aliases])) &&\nRun Code Online (Sandbox Code Playgroud)\n\n为了更好地理解该行的工作原理,我执行了以下命令:
\n\nalias ls=\'ls --color=auto\'\nalias -g V=\'|vipe\'\nfunctions[_expand-aliases]=\'ls V\'\necho $functions[_expand-aliases] \xe2\x86\x92 ls --color=auto | vipe\necho $+functions[_expand-aliases] \xe2\x86\x92 1\n(($+functions[_expand-aliases])); …Run Code Online (Sandbox Code Playgroud) 我想使用键序列创建一个键绑定,以重新加载存储在 中C-x r的配置以及存储在 中的 readline 库之一。bash~/.bashrc~/.inputrc
要重新加载 readline 的配置,我想我可以使用re-read-init-file以下中描述的函数man 3 readline:
re-read-init-file (C-x C-r)
Read in the contents of the inputrc file, and incorporate any bindings or variable assignments found there.
Run Code Online (Sandbox Code Playgroud)
要重新加载 的配置bash,我可以使用sourceor.命令。但是,我不确定将 shell 命令与 readline 函数结合起来的最佳方法是什么。因此,我想出了 2 个键绑定的组合:
bind '"\C-xr": ". ~/.bashrc \C-x\C-z1\C-m"'
bind '"\C-x\C-z1": re-read-init-file'
Run Code Online (Sandbox Code Playgroud)
当我点击C-x rbash 时,会发生以下情况:
. ~/.bashrc `~/.bashrc` is inserted on the command line
C-x C-z 1 `C-x …Run Code Online (Sandbox Code Playgroud)