[英]How to colorize man-page in Fish shell?
bash解決方案描述了tmux
手冊頁搜索突出顯示功能,在bash中效果很好,但在移植到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
取而代之的是顏色,我得到的是未解釋的代碼: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
魚中顏色編碼的正確語法是什么?
在bash版本中,您正在做的是ANSI-C引用 。 這使得bash在將序列設置為變量之前先對其進行解釋。 因此LESS_TERMCAP_mb不包含文字字符串“ \\ E [01; 31m”,但是由它指定的順序-特別是“ \\ E”是轉義字符。
在fish中,您要做的是在引號之外指定轉義序列-請參見fish文檔中有關引號的部分 :
set -gx LESS_TERMCAP_mb \e'[01;31m'
等等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.