问题

问题

在我的~/.bashrc

Terminal() {
    TerminalDarkProfile="b1dcc9dd-5262-4d8d-a863-c897e6d979b9"
    TerminalLightProfile="3dd28c15-6ba4-4ba0-8289-ab023e6c88fc"

    Gsetting="org.gnome.Terminal.ProfilesList"
    [[ "${1}" == 'Light' ]] && gsettings set "${Gsetting}" default "${TerminalLightProfile}"
    [[ "${1}" == 'Dark' ]] && gsettings set "${Gsetting}" default "${TerminalDarkProfile}"
    gsettings get "${Gsetting}" default
}

如果我在 bash 终端中输入Terminal Light,则没有输出,Gnome 终端颜色也不会改变。

但是如果我手动将函数粘贴到终端中:

$ Terminal() {
    TerminalDarkProfile="b1dcc9dd-5262-4d8d-a863-c897e6d979b9"
    TerminalLightProfile="3dd28c15-6ba4-4ba0-8289-ab023e6c88fc"

    Gsetting="org.gnome.Terminal.ProfilesList"
    [[ "${1}" == 'Light' ]] && gsettings set "${Gsetting}" default "${TerminalLightProfile}"
    [[ "${1}" == 'Dark' ]] && gsettings set "${Gsetting}" default "${TerminalDarkProfile}"
    gsettings get "${Gsetting}" default
}
$ Terminal Light
'3dd28c15-6ba4-4ba0-8289-ab023e6c88fc'

然后,我们可以看到 gsettings 正在工作,并且 gnome 终端配置文件确实发生了变化!

问题

为什么会发生这种情况?如何从定义的脚本或 bashfunction 内部更改 gsettings~/.bashrc


编辑

$ type Terminal
bash: type Terminal: command not found
$ Terminal Dark

我很惊讶,type Terminal: command not foundTerminal Dark没有给出任何输出!

此外:

cat Theme.sh
#!/usr/bin/env bash
set -xv
echo $DBUS_SESSION_BUS_ADDRESS
whoami
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
gsettings get org.gnome.desktop.interface color-scheme
$ bash ./Theme.sh 
echo $DBUS_SESSION_BUS_ADDRESS
+ echo unix:path=/run/user/1000/bus
unix:path=/run/user/1000/bus
whoami
+ whoami
lamy
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
+ gsettings set org.gnome.desktop.interface color-scheme prefer-light
gsettings get org.gnome.desktop.interface color-scheme
+ gsettings get org.gnome.desktop.interface color-scheme
'prefer-light'
$ gsettings get org.gnome.desktop.interface color-scheme
'prefer-dark'

我们可以看到gsettings get运行脚本后立即显示不同的值!

相关内容