Change konsole tab title from command line and make it persistent?

前端 未结 6 1740
情深已故
情深已故 2021-02-14 00:47

How can I change the konsole tab title? By default, it\'s set to %u : %n, so it always changes automatically.

I can set it with:

qdbus org.         


        
6条回答
  •  没有蜡笔的小新
    2021-02-14 01:06

    Posting my own solution to this old question, because

    • OP solution does not work on newer(?) KDE systems due to the hard-coding of the service name to org.kde.konsole
    • the answers based on echo require a permanent change to konsole settings

    After reading the Scripting Konsole chapter in the konsole documentation I wrote these bash functions which can be added to $HOME/.bashrc:

    set-konsole-tab-title-type ()
    {
        local _title=$1
        local _type=${2:-0}
        [[ -z "${_title}" ]]               && return 1
        [[ -z "${KONSOLE_DBUS_SERVICE}" ]] && return 1
        [[ -z "${KONSOLE_DBUS_SESSION}" ]] && return 1
        qdbus >/dev/null "${KONSOLE_DBUS_SERVICE}" "${KONSOLE_DBUS_SESSION}" setTabTitleFormat "${_type}" "${_title}"
    }
    set-konsole-tab-title ()
    {
        set-konsole-tab-title-type $1 && set-konsole-tab-title-type $1 1
    }
    

    Example 1: set both local & remote tab formats

    $ set-konsole-tab-title test
    

    Example 2: leave remote tab format unchanged

    $ set-konsole-tab-title-type test
    

    Example 3: leave local tab format unchanged

    $ set-konsole-tab-title-type test 1
    

    You can also use this function to set the tab title dynamically to %w for the echo solutions.

提交回复
热议问题