![](/img/trans.png)
[英]How do I make bash reverse-search work in Terminal.app without it displaying garbled output?
[英]How do I change the color of my Terminal.App when I log into my production remote on Heroku?
我记得有一篇或者几篇关于作者如何根据SSH地址将终端颜色从绿色(用于开发)更改为红色(用于生产)的文章。
但我不知道如何使用Heroku控制台复制它。
理想情况下,我想说它是蓝色的,当我做heroku console --remote staging
然后红色,当我做heroku console --remote production
。
有人建议吗?
在作为生产环境的一部分加载的任何文件中(例如, config/environments/production.rb
),您可以放置:
if defined? IRB
# whew!
conf = IRB.conf[:PROMPT][IRB.conf[:PROMPT_MODE]]
red = "\033[0;31m"
reset = "\033[0m"
conf[:PROMPT_S] = "#{red}>> #{reset}" # regular prompt
end
疯狂的转义字符是ANSI颜色代码。 "\\033"
是一个转义字符,其余的是特定颜色或效果的代码。 您可以在此处找到其他颜色和效果的列表。 IRB.conf哈希是IRB的全局配置。 您可能需要在其上设置一些其他键 - 它们在此处记录 。
如果您没有使用Rails(因此不一定有环境文件),您可以使用ENV['RACK_ENV']
来检查当前环境,这应该在Heroku上设置为'production'
。
我通过使用Marco Polo gem https://github.com/arches/marco-polo来做到这一点
然后,您可以通过设置heroku配置变量MARCO_POLO_APP_NAME来更改控制台提示。 您可以利用转义码来更改颜色。 就我而言,我使用此控制序列将生产提示设置为洋红色背景上的白色(很难错过)MARCO_POLO_APP_NAME的值
[ESC][105;97;1mPRODUCTION[ESC][0m
不幸的是,Stack Overflow不会让我发布转义字符本身。 你必须使用Notepad ++并运行Regexp搜索和替换,将上面的[ESC]替换为\\ x1B。 然后,您可以复制并粘贴到Heroku控制台中的MARCO_POLO_APP_NAME值。 我无法在命令行设置它。
未经测试,但你的.bashrc或其他任何你可能想要的东西(它不是完全安全,但你应该得到的想法)
function heroku {
REMOTE_TERMINAL_THEME_NAME="Solarized Light"
CURTAB=$(osascript -e "tell application \"Terminal\" to get the selected tab of the front window")
CURTHEME=$(osascript -e "tell application \"Terminal\" to get the name of current settings of the selected tab of the front window")
HEROKU=$(which heroku)
osascript -e "tell application \"Terminal\" to set current settings of $CURTAB to settings set \"$REMOTE_TERMINAL_THEME_NAME\""
$HEROKU "$@"
osascript -e "tell application \"Terminal\" to set current settings of $CURTAB to settings set \"$CURTHEME\""
}
我将它用于ssh但它在概念上是相同的:用一个使用osascript更改终端设置的函数覆盖你的命令,然后在退出时更改它们。 基于参数的切换应该相对容易添加。
您可以在键入时使用bash或batch自动化它。别名在我看来是cli / terminal devving最好的东西之一。 这是一篇文章,其中一个简单的echo命令可以改变你的颜色,直到你用另一个回声设置它。
如果您是一名nix用户,那么您可以使用bashrc执行此操作。
#pretend this is a bunch of prompt setup
#USER ALIASES
alias heroku-staging="export PS1="\e[0;34m[Heroku Staging]$]" && heroku console --remote staging"
然后输入heroku-staging
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.