Unix Bash 脚本来粗体/下划线/斜体特定文本
我一直在网上搜寻,试图找到可以处理基本文本样式(粗体/下划线/斜体)的 Unix Bash 脚本示例,但找不到任何东西?这样的事可以做吗?
例如:
- 将所有以“:”结尾的行加粗/下划线/斜体?
- (关闭)将所有以“:”结尾的行加粗/下划线/斜体?
我想通过 Automator 将其设置为服务;因此,使用 /bin/bash
并对“选定的文本”执行操作(当然,在富文本兼容的文件中)。
I've been trawling the web trying to find examples of Unix Bash script that can handle basic text styling (bold/underline/italics), but can't find anything? Is such a thing possible to do?
For example:
- Embolden/Underline/Italicize all lines ending in ":"?
- (Turn off) Embolden/Underline/Italicize all lines ending in ":"?
I want to set it up as a Service via Automator; so using /bin/bash
and actioning on "selected text" (in a rich-text-compatible file, of course).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,您想要使用样式代码声明一些变量 - 类似这样:
然后您可以使用变量调用这些变量以在输出中使用,如下所示:
至于自动将其应用于以特定开头的所有行字符,您最好只使用如上所示的变量。使用这种方法不仅更简单,而且更干净、更可用。例如,使用此方法时,您可以对给定输出字符串中的任意数量的单词进行不同的样式,以便强调特定单词,而不是整个句子(当然,除非这是您的目标)。
有关更多信息,您应该查看 http://tldp.org/HOWTO/Bash-Prompt-HOWTO/ x405.html 和/或 man tput
Basically, you want to do declare some variables with the styling code--something like this:
then you can call these for use in your output using the variables, like this:
As far as automating it to apply to all lines beginning with a specific character, you're better off just using the variables as shown above. Besides using this method just being easier, it's also cleaner and more usable. For example, when using this method you have the ability to style any number of words in a given output string differently, so as to emphasize a specific word, not the entire sentence (unless of course that's your goal).
For more information, you should check out http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x405.html and/or man tput
只是补充一下,您不要使用
tput
,还可以将颜色指定为 ANSI 转义序列。它们的指定方式类似于
\033[XXXm
,其中 XXX 是一系列以分号分隔的参数(如ECMA-48
标准)。例如:例如以亮紫色打印(请注意,需要
-e
才能启用反斜杠转义的解释)颜色由您正在使用的终端呈现,传统上终端颜色是 8 位,现在大多数terminl 模拟器是真彩色 / 256 位。
Just to add, that instead of using
tput
, you can also specify colors as ANSI escape sequences.These are specified like
\033[XXXm
, where XXX is a series of semicolon-separated parameters (as covered by theECMA-48
standard). For example:E.g. to print in bright purple (note that
-e
is required to enable interpretation of backslash escapes)Colors are rendered by the terminal you are using, traditionally terminal colors were 8-bit, nowadays most termainl emulators are true color / 256-bit.