1

现在,我很确定这里的限制。但让我们退后一步。

简单的说法

 READNULLCMD="less -R"

不起作用,产生以下错误:

$ <basic.tex                                                                            
zsh: command not found: less -R

好的。很确定这是因为默认情况下,zsh 不会在每个空格处拆分字符串变量。无论 zsh 在哪里使用这个变量,它在应该使用 ${=READNULLCMD} 的地方都使用 $READNULLCMD,以确保选项参数通过正常空格与命令正确分隔。请参阅 1996 年的讨论(!): http ://www.zsh.org/mla/users/1996/msg00299.html

那么,在不设置 SH_WORD_SPLIT (99% 的时间我都不想要)的情况下,最好的解决方法是什么?

到目前为止,我最好的想法是将 READNULLCMD 分配给一个简单的 zsh 脚本,该脚本只在 STDIN 上调用“less -R”。例如

#!/opt/local/bin/zsh
less -R /dev/stdin

不幸的是,由于某种原因,这似乎是一个非首发,因为这种方式很少使用,因此错过了 /dev/stdin 输入的前几行。

有人有更好的想法吗?

4

3 回答 3

1
于 2012-12-27T18:00:22.327 回答
1

The problem is not that less doesn't read its environment variables (LESS or LESSOPEN). The problem is that the READNULLCMD is not invoked as you might think.

<foo

does not translate into

less $LESS foo

but rather to something like

cat foo | less $LESS

or, perhaps

cat foo $LESSOPEN | less $LESS

I guess that you (like me) want to use -R to obtain syntax coloring (by using src-hilite-lesspipe.sh in LESSOPEN, which in turn uses the "source-highlight" utility). The problem with the latter two styles of invocation is that src-hilite-lesspipe.sh (embedded in $LESSOPEN) will not receive a filename, and hence it will not be able to deduce the file type (via the --infer-lang option to "source-highligt"). Without a filename suffix, "source-highlight" will revert to "no highlighting".

You can obtain syntax coloring in READNULLCMD, but in a rather useless way. This by specifying the language explicitly via the --lang-def option. However, you'll have as little clue as "source-higlight", since the there's no file name when the data is passed anonymously through the pipe. Maybe there's a way to do a on-the-fly heuristic parser and deduce it by contents, but then you've for sure left this little exercise.

于 2015-03-25T14:09:07.990 回答
0

$LESSenv var 设置为您始终希望在less.

所以不要在你的 zshrc 中触摸READNULLCMD和使用export LESS="R"(以及你想要的其他选项)。

于 2012-12-27T14:08:39.317 回答