sat*_*ine 17 terminal colors macos
是否有可用于更改 Mac OS X 终端配色方案的命令?我喜欢能够根据我运行的脚本更改颜色的想法。到目前为止,我只是用 PS1 更改了我的 bash 提示的颜色,这还可以,但没有我想要的那么明显。
Dan*_*eck 18
根据您究竟想要完成什么,这里有一些 AppleScript 中使用终端样式的想法。这些比 更健壮tput,因为这会通过彩色提示重置。等(至少对我而言)。
这会将所有运行 Python 的选项卡(目前没有可用于测试的 SSH 服务器)设置为 Homebrew,其他设置为 Ocean:
tell application "Terminal"
repeat with w from 1 to count windows
repeat with t from 1 to count tabs of window w
if processes of tab t of window w contains "Python" then
set current settings of tab t of window w to (first settings set whose name is "Homebrew")
else
set current settings of tab t of window w to (first settings set whose name is "Ocean")
end if
end repeat
end repeat
end tell
Run Code Online (Sandbox Code Playgroud)
另存为脚本并在osascript Name.scpt您想要重新着色外壳的任何时候运行(当然,您可以将其包装为外壳脚本或其他东西)。
如果要以不同方式显示所有长时间运行的进程,请使用以下条件:
if busy of tab t of window w is true then
或者,您可以设置单个选项卡的样式,手动选择:
on run argv
tell application "Terminal" to set current settings of tab (item 1 of argv as number) of front window to first settings set whose name is (item 2 of argv)
end run
Run Code Online (Sandbox Code Playgroud)
像这样运行它:
osascript StyleTerm.scpt 3 Homebrew
Run Code Online (Sandbox Code Playgroud)
-> 最前面的终端窗口的第三个选项卡获得 Homebrew 风格!
如果要修改背景窗口,请将“前窗口”替换为“tab”之后的括号表达式。如果您总是想修改选定的“当前选项卡”,请使用selected tab代替tab (item 1 of argv as number)。
.bash_profile如果第一个解决方案对您来说太体力劳动,请将以下内容添加到您的:
PROMPT_COMMAND='osascript "/path/to/Name.scpt"'
现在它在每个提示之前执行(唯一的问题是:不是在开始某些东西之后,即ssh。但无论如何,这个主题不是关于花哨的 bash 技巧。这只是一个指针。)
您的脚本可以使用该tput命令以可移植的方式设置颜色。尝试以下脚本,您将看到终端清晰为深青色背景,带有一些亮青色文本。
#!/bin/bash
tput setab 6
tput clear
tput setaf 14
echo Hello World
Run Code Online (Sandbox Code Playgroud)
您可以man 5 terminfo在名为“颜色处理”的部分中查看更多相关信息。
您可以通过回显终端直接识别的转义序列来执行相同的操作。它会更快,但使用其他终端程序可能无法正常工作。他们中的许多人都能识别 xterm 序列,下面是上面的脚本使用它们的样子。
#!/bin/bash
printf "\033[48;5;6m" # or "\033[46m"
printf "\033[H\033[2J" # your system's clear command does something similar
printf "\033[38;5;14m" # or "\033[96m"
echo Hello World
Run Code Online (Sandbox Code Playgroud)
有一个关于xterm的控制序列的详细信息在这里。
| 归档时间: |
|
| 查看次数: |
17652 次 |
| 最近记录: |