我知道可以通过echo -e "\033]50;SetProfile=Foo\a"的方式设置会话配置文件,但是有没有一种方法可以获取当前会话的配置文件呢?
我知道可以通过echo -e "\033]50;SetProfile=Foo\a"的方式设置会话配置文件,但是有没有一种方法可以获取当前会话的配置文件呢?
对于现在正在查找会话的人,您可以通过检查$ITERM_PROFILE
变量来获取会话。查看printenv
的输出可以帮助您查看类似这样的内容。
我提供的是最简单的 AppleScript 代码,可以实现以下功能:
tell application "iTerm2"
get profile name of current session of current window
end tell
以下是一段使用此脚本设置配置文件,运行命令,然后再次设置配置文件的简单bash脚本。它使用第一个参数作为配置文件,其余参数作为命令(例如script < profile > < command >)。
#/bin/bash
#get the current window settings
CUR_SETTINGS=`osascript -e 'tell application "iTerm-2"
get profile name of current session of current window
end tell'`
#Restore the current settings if the user ctrl-c's out of the command
trap ctrl_c INT
function ctrl_c() {
echo -e "\033]50;SetProfile=$CUR_SETTINGS\a"
exit
}
#set profile
echo -e "\033]50;SetProfile=$1\a"
shift
#run command
$@
#Restore settings
echo -e "\033]50;SetProfile=$CUR_SETTINGS\a"
除了像这样的方式之外,我没有找到获取配置文件名称的方法:
tell application "System Events" to tell process "iTerm"
keystroke "i" using command down
set p to value of text field 1 of tab group 1 of group 1 of window 1
click button 1 of window 1
end tell
p
您可以通过一些属性来识别配置文件:
tell application "iTerm" to tell current session of terminal 1
background color is {0, 0, 0} and transparency is 0.0
end tell
字典中记录的属性:
背景颜色、背景图片路径、粗体颜色、内容、光标颜色、光标文本颜色、前景色、ID、名称、数字、选定文本颜色、选择颜色、透明度、TTY
ITERM_PROFILE
环境变量不会更改。 - bitdancer