bash - 如何在 Fish shell 中为手册页着色?

标签 bash shell colors fish manpage

描述的 bash 解决方案 tmux man-page search highlighting在 bash 中运行良好,但在移植到 fish 中时失败。

fish 配置

function configure_pager
    # Colored man pages: http://linuxtidbits.wordpress.com/2009/03/23/less-colors-for-man-pages/
    # Less Colors for Man Pages
    set -gx LESS_TERMCAP_mb '\E[01;31m'       # begin blinking
    set -gx LESS_TERMCAP_md '\E[01;38;5;74m'  # begin bold
    set -gx LESS_TERMCAP_me '\E[0m'           # end mode
    set -gx LESS_TERMCAP_se '\E[0m'           # end standout-mode
    set -gx LESS_TERMCAP_so '\E[38;5;016m\E[48;5;220m'    # begin standout-mode - info box
    set -gx LESS_TERMCAP_ue '\E[0m'           # end underline
    set -gx LESS_TERMCAP_us '\E[04;38;5;146m' # begin underline
end

在 fish 中渲染

我得到的不是颜色,而是未解释的代码: LS(1) 用户命令 LS(1)

\E[01;38;5;74mNAME\E[0m
       ls - list directory contents

\E[01;38;5;74mSYNOPSIS\E[0m
       \E[01;38;5;74mls\E[0m [\E[04;38;5;146mOPTION\E[0m]... [\E[04;38;5;146mFILE\E[0m]...

\E[01;38;5;74mDESCRIPTION\E[0m
       List information about the FILEs (the current directory by default).  Sort entries alphabetically if none of \E[01;38;5;74m-cftuvSUX\E[0m nor \E[01;38;5;74m--sort\E[0m is specified.

问题

这可能是因为我在 fish 中对字符串文字变量使用了错误的语法:

set -gx LESS_TERMCAP_mb '\E[01;31m'       # begin blinking

原始 bash 是:

export LESS_TERMCAP_mb=$'\E[01;31m'       # begin blinking

fish 的颜色编码的正确语法是什么?

最佳答案

你在 bash 版本中所做的是 ANSI-C Quoting .这使得 bash 在将其设置为变量之前解释序列。所以 LESS_TERMCAP_mb 不包含文字字符串“\E[01;31m”,但包含由它指定的序列 - 特别是,“\E”是转义字符。

在 fish 中,您要做的是在引号外指定转义序列 - 参见 the section on quotes in the fish documentation :

set -gx LESS_TERMCAP_mb \e'[01;31m'

等等。

预览

fish man page highlight configuration

关于bash - 如何在 Fish shell 中为手册页着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34265221/

相关文章:

java - NoSuchBeanDefinitionException : No qualifying bean of type 'java.util.List<org.springframework.shell.ParameterResolver>'

r - 向 R 中的等高线图添加颜色键

macos - Mac OS-X 上的颜色选择器选择了错误的颜色

linux - 在下一行提示后面打印 bash 脚本结果

linux - 遍历文件,搜索 nan 的

linux - 如何在 bash 中使用 grep 测试进程是否正在运行?

java - 如何通过 JPanel 构造函数中的 String 参数更改 JPanel 的背景颜色?

bash - 在 Windows 上使用 Git Bash,如何 checkout /重命名以 Unicode 字符开头的分支?

python - 从 shell 程序脚本执行(service ssh start)有效,但是当我从python调用脚本时,它不起作用

linux - sshpass:找不到命令错误