Answers:
#找出有多少pofile-刚开始时只有1-默认
profiles_list = $(gconftool-2 --get“ / apps / gnome-terminal / global / profile_list” | sed“ s | \ [||; s | \\] ||;”)
回声“ 1个配置文件列表:” $ {profiles_list}
last_profile = $(echo“ $ {profiles_list}” | sed“ s /^.*,//” | sed's / Profile //')
回显“最后的配置文件名称/编号:” $ {last_profile}
#如果只有默认值或最后一个加1,则将“ ProfileX” X编号设置为0
如果[$ {last_profile} ==“默认”]; 然后
next_profile_number = 0;
回显“ 1个新的配置文件编号:” $ {next_profile_number}
其他
next_profile_number = $((($ {last_profile} + 1));
回声“ 2新的配置文件编号:” $ {next_profile_number}
科幻
回显“新配置文件编号:” $ {next_profile_number}
#使用额外的配置文件“数字”构造配置文件列表
profiles_list = $(回显“ [$ {profiles_list},Profile $ {next_profile_number}]”))
回声“ 1个配置文件列表:” $ {profiles_list}
#获取默认配置文件的转储,将全局名称更改为新的配置文件名称
profileName = MyNewProfile
gconftool-2-转储“ / apps / gnome-terminal / profiles / Default”> /tmp/${USER}_gnome-terminal_profiles_${profileName}.xml
sed -i“ s | Default | Profile $ {next_profile_number} | g” /tmp/${USER}_gnome-terminal_profiles_${profileName}.xml
#加载新的配置文件
gconftool-2 --load /tmp/${USER}_gnome-terminal_profiles_${profileName}.xml
#告诉gnome-terminal有另一个配置文件
gconftool-2 --set --type list --list-type字符串“ / apps / gnome-terminal / global / profile_list”“ $ {profiles_list}”
#设置属性
gconftool-2 --set --type字符串/ apps / gnome-terminal / profiles / Profile $ {next_profile_number} / visible_name“ $ {profileName}”
gconftool-2 --set --type字符串/ apps / gnome-terminal / profiles / Profile $ {next_profile_number} / exit_action“ hold”
gconftool-2 --set --type字符串/ apps / gnome-terminal / profiles / Profile $ {next_profile_number} / font“ Monospace 14”
gconftool-2 --set --type字符串/ apps / gnome-terminal / profiles / Profile $ {next_profile_number} / background_color“#000000000000”
gconftool-2 --set --type字符串/ apps / gnome-terminal / profiles / Profile $ {next_profile_number} / foreground_color“#0000FFFF0000”
gconftool-2 --set --type字符串/ apps / gnome-terminal / profiles / Profile $ {next_profile_number} / scrollbar_position“隐藏”
gconftool-2 --set --type布尔值/ apps / gnome-terminal / profiles / Profile $ {next_profile_number} / use_system_font“ false”
gconftool-2 --set --type布尔值/ apps / gnome-terminal / profiles / Profile $ {next_profile_number} / use_theme_colors“ false”
gconftool-2 --set --type布尔值/ apps / gnome-terminal / profiles / Profile $ {next_profile_number} / login_shell“ true”
gconftool-2 --set --type布尔值/ apps / gnome-terminal / profiles / Profile $ {next_profile_number} / scrollback_unlimited“ true”
#创建一个终端
gnome-terminal --geometry = 80x24 + 0 + 0 --profile = $ {profileName}标题“ $ {profileName}” --zoom 0.8 -e“ / bin / sh”
对于GNOME Terminal> = 3.8,要通过cli创建/编辑/读取配置文件,可以使用dconf-cli或gsettings。我的选择是dconf-cli。
GNOME终端的dconf目录为
/org/gnome/terminal/legacy/profiles:。所有操作都在该目录中进行。我将其存储在$dconfdir下面的脚本中。
最少的步骤是
uuidgenlist:dconf write "$dconfdir/list" "[..., 'UUID']"visible-name:dconf write "$dconfdir/:UUID"/visible-name "'NAME'"之后,即使未设置许多设置,新的配置文件也会显示在终端的GUI设置中,以便您可以通过GUI编辑设置。
工作脚本:
#!/bin/bash
dconfdir=/org/gnome/terminal/legacy/profiles:
create_new_profile() {
local profile_ids=($(dconf list $dconfdir/ | grep ^: |\
sed 's/\///g' | sed 's/://g'))
local profile_name="$1"
local profile_ids_old="$(dconf read "$dconfdir"/list | tr -d "]")"
local profile_id="$(uuidgen)"
[ -z "$profile_ids_old" ] && local lb="[" # if there's no `list` key
[ ${#profile_ids[@]} -gt 0 ] && local delimiter=, # if the list is empty
dconf write $dconfdir/list \
"${profile_ids_old}${delimiter} '$profile_id']"
dconf write "$dconfdir/:$profile_id"/visible-name "'$profile_name'"
echo $profile_id
}
# Create profile
id=$(create_new_profile TEST)
请注意所写值周围的引号。如手册中所述,
设置键时,还需要指定一个
VALUE。该值的格式是序列化的GVariant的格式,因此,例如,字符串必须包含显式引号:"'foo'"。打印出值时也使用此格式。
如果需要,可以通过cli设置配置文件的更多选项。跑
dconf write /org/gnome/terminal/legacy/profiles:/:UUID/KEY "'NAME'"
设置。您可以dconf-editor用来检查可用的选项。导航至类似的路径
/org/gnome/terminal/legacy/profiles:/:9ca4ab84-42f2-4acf-8aa9-50e6351b209a/。最好检查设置了许多选项的旧配置文件。
您可以dconf dump将旧的配置文件添加load到现有配置文件。因此,要复制配置文件,您需要使用上述步骤创建一个新的配置文件,并复制一个旧的配置文件以覆盖它。记住在覆盖后重命名它。
工作脚本:
# ... codes from last script
duplicate_profile() {
local from_profile_id="$1"; shift
local to_profile_name="$1"; shift
local profile_ids=($(dconf list $dconfdir/ | grep ^: |\
sed 's/\///g' | sed 's/://g'))
# If UUID doesn't exist, abort
in_array "$from_profile_id" "${profile_ids[@]}" || return 1
# Create a new profile
local id=$(create_new_profile "$to_profile_name")
# Copy an old profile and write it to the new
dconf dump "$dconfdir/:$from_profile_id/" \
| dconf load "$dconfdir/:$id/"
# Rename
dconf write "$dconfdir/:$id"/visible-name "'$to_profile_name'"
}
# Create a profile from an existing one
duplicate_profile $id TEST1
要通过名称获取配置文件的UUID:
get_profile_uuid() {
# Print the UUID linked to the profile name sent in parameter
local profile_ids=($(dconf list $dconfdir/ | grep ^: |\
sed 's/\///g' | sed 's/://g'))
local profile_name="$1"
for i in ${!profile_ids[*]}; do
if [[ "$(dconf read $dconfdir/:${profile_ids[i]}/visible-name)" == \
"'$profile_name'" ]]; then
echo "${profile_ids[i]}"
return 0
fi
done
}
id=$(get_profile_uuid Default)
只需将配置文件的UUID写入密钥default:
dconf write $dconfdir/default "'$UUID'"
dconf watch /并最终得到了进展,答案如@joegnis所言。只需创建一个UUID,将其写入数据库并设置visible-name和即可/list。