带有 tcsh 的彩色手册页?

发布于 2024-10-16 08:15:15 字数 495 浏览 3 评论 0原文

实现的彩色联机帮助页

export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

我真的很喜欢可以在 .bashrc 或 .zshrc 中 。 我的问题是:如何在 tcsh 中导出这些变量?我必须在工作中使用 tcsh,但无法使其工作。我尝试了很多变体,但没有任何效果。简单地用 setenv 替换导出并用“”替换 = 并不能解决问题。 但它应该以某种方式起作用。如果我使用此导出集从我的 zsh 中启动 tcsh,我也可以在 tcsh 中享受彩色手册页。但这是一个丑陋的解决方法。

I really like the colored manpages which can are achieved by

export LESS_TERMCAP_mb=

in your .bashrc or .zshrc.
My question is: How do I export these variables in tcsh? I have to use tcsh at work and cannot get it working. I tried plenty of variations, but nothing worked. Simply replacing export with setenv and = with " " doesn't do the trick.
But it should work somehow. If i start a tcsh out of my zsh with this exports set I can enjoy colored manpages in tcsh, also. But that's an ugly workaround.

\E[01;31m' export LESS_TERMCAP_md=

in your .bashrc or .zshrc.
My question is: How do I export these variables in tcsh? I have to use tcsh at work and cannot get it working. I tried plenty of variations, but nothing worked. Simply replacing export with setenv and = with " " doesn't do the trick.
But it should work somehow. If i start a tcsh out of my zsh with this exports set I can enjoy colored manpages in tcsh, also. But that's an ugly workaround.

\E[01;31m' export LESS_TERMCAP_me=

in your .bashrc or .zshrc.
My question is: How do I export these variables in tcsh? I have to use tcsh at work and cannot get it working. I tried plenty of variations, but nothing worked. Simply replacing export with setenv and = with " " doesn't do the trick.
But it should work somehow. If i start a tcsh out of my zsh with this exports set I can enjoy colored manpages in tcsh, also. But that's an ugly workaround.

\E[0m' export LESS_TERMCAP_se=

in your .bashrc or .zshrc.
My question is: How do I export these variables in tcsh? I have to use tcsh at work and cannot get it working. I tried plenty of variations, but nothing worked. Simply replacing export with setenv and = with " " doesn't do the trick.
But it should work somehow. If i start a tcsh out of my zsh with this exports set I can enjoy colored manpages in tcsh, also. But that's an ugly workaround.

\E[0m' export LESS_TERMCAP_so=

in your .bashrc or .zshrc.
My question is: How do I export these variables in tcsh? I have to use tcsh at work and cannot get it working. I tried plenty of variations, but nothing worked. Simply replacing export with setenv and = with " " doesn't do the trick.
But it should work somehow. If i start a tcsh out of my zsh with this exports set I can enjoy colored manpages in tcsh, also. But that's an ugly workaround.

\E[01;44;33m' export LESS_TERMCAP_ue=

in your .bashrc or .zshrc.
My question is: How do I export these variables in tcsh? I have to use tcsh at work and cannot get it working. I tried plenty of variations, but nothing worked. Simply replacing export with setenv and = with " " doesn't do the trick.
But it should work somehow. If i start a tcsh out of my zsh with this exports set I can enjoy colored manpages in tcsh, also. But that's an ugly workaround.

\E[0m' export LESS_TERMCAP_us=

in your .bashrc or .zshrc.
My question is: How do I export these variables in tcsh? I have to use tcsh at work and cannot get it working. I tried plenty of variations, but nothing worked. Simply replacing export with setenv and = with " " doesn't do the trick.
But it should work somehow. If i start a tcsh out of my zsh with this exports set I can enjoy colored manpages in tcsh, also. But that's an ugly workaround.

\E[01;32m'

in your .bashrc or .zshrc.
My question is: How do I export these variables in tcsh? I have to use tcsh at work and cannot get it working. I tried plenty of variations, but nothing worked. Simply replacing export with setenv and = with " " doesn't do the trick.
But it should work somehow. If i start a tcsh out of my zsh with this exports set I can enjoy colored manpages in tcsh, also. But that's an ugly workaround.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长亭外,古道边 2024-10-23 08:15:15

执行此操作的方法是 tcsh 原生的,并且可移植到不同的终端类型,方法是使用 echotc 内置命令:

setenv LESS_TERMCAP_mb `echotc md; echotc AF 1`
setenv LESS_TERMCAP_md `echotc md; echotc AF 1`
setenv LESS_TERMCAP_me `echotc me`
setenv LESS_TERMCAP_se `echotc me`
setenv LESS_TERMCAP_so `echotc md; echotc AF 3; echotc AB 4`
setenv LESS_TERMCAP_ue `echotc me`
setenv LESS_TERMCAP_us `echotc md; echotc AF 2`

请参阅 man 5 terminfo 用于 termcap 代码和颜色代码。

mdenter_bold_mode
exit_attribute_mode
AFset_a_foreground
ABset_a_background

顺便说一下,要在 Bash 中执行此操作,请使用外部实用程序 tput 和 terminfo 功能名称:

export LESS_TERMCAP_mb=$(tput bold; tput setaf 1)
export LESS_TERMCAP_md=$(tput bold; tput setaf 1)
export LESS_TERMCAP_me=$(tput sgr0)
export LESS_TERMCAP_se=$(tput sgr0)
export LESS_TERMCAP_so=$(tput bold; tput setaf 3; tput setab 4)
export LESS_TERMCAP_ue=$(tput sgr0)
export LESS_TERMCAP_us=$(tput bold; tput setaf 2)

The way to do this which is native to tcsh and is portable to different terminal types is to use the echotc builtin command:

setenv LESS_TERMCAP_mb `echotc md; echotc AF 1`
setenv LESS_TERMCAP_md `echotc md; echotc AF 1`
setenv LESS_TERMCAP_me `echotc me`
setenv LESS_TERMCAP_se `echotc me`
setenv LESS_TERMCAP_so `echotc md; echotc AF 3; echotc AB 4`
setenv LESS_TERMCAP_ue `echotc me`
setenv LESS_TERMCAP_us `echotc md; echotc AF 2`

See man 5 terminfo for the termcap codes and color codes.

md is enter_bold_mode
me is exit_attribute_mode
AF is set_a_foreground
AB is set_a_background

By the way, to do this in Bash, use the external utility tput and the terminfo capability names:

export LESS_TERMCAP_mb=$(tput bold; tput setaf 1)
export LESS_TERMCAP_md=$(tput bold; tput setaf 1)
export LESS_TERMCAP_me=$(tput sgr0)
export LESS_TERMCAP_se=$(tput sgr0)
export LESS_TERMCAP_so=$(tput bold; tput setaf 3; tput setab 4)
export LESS_TERMCAP_ue=$(tput sgr0)
export LESS_TERMCAP_us=$(tput bold; tput setaf 2)
烛影斜 2024-10-23 08:15:15

问题是 tcsh 不会解释变量名称中的转义序列,因此当您尝试使用 tcsh 设置环境变量时,环境变量最终会以文字 \E 结尾。这是解决这个问题的一种方法,使用 Bash 来解释转义序列,尽管它有点难看:

% setenv LESS_TERMCAP_md `bash -c 'echo -en "\e[01;31m"'`
% setenv LESS_TERMCAP_me `bash -c 'echo -en "\e[0m"'`
% setenv LESS_TERMCAP_se `bash -c 'echo -en "\e[0m"'`
% setenv LESS_TERMCAP_so `bash -c 'echo -en "\e[01;44;33m"'`
% setenv LESS_TERMCAP_ue `bash -c 'echo -en "\e[0m"'`
% setenv LESS_TERMCAP_us `bash -c 'echo -en "\e[01;32m"'`

The problem is that tcsh isn't interpreting the escape sequence in your variable name, so the environment variable ends up with a literal \E in it when you try to set it with tcsh. Here's one way you can get around that, using Bash to interpret the escape sequences, although it's a little ugly:

% setenv LESS_TERMCAP_md `bash -c 'echo -en "\e[01;31m"'`
% setenv LESS_TERMCAP_me `bash -c 'echo -en "\e[0m"'`
% setenv LESS_TERMCAP_se `bash -c 'echo -en "\e[0m"'`
% setenv LESS_TERMCAP_so `bash -c 'echo -en "\e[01;44;33m"'`
% setenv LESS_TERMCAP_ue `bash -c 'echo -en "\e[0m"'`
% setenv LESS_TERMCAP_us `bash -c 'echo -en "\e[01;32m"'`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文