您可以在 Gnome 工作区切换器上“右键单击 => 首选项”来重命名工作区。
我想知道是否可以配置键盘快捷键来触发重命名当前活动工作区。
答案1
dconf-editor
从终端使用,导航到gnome>desktop>wm>
然后设置workspace-names
为
["Internet", "Oracle", "Gimp", "PHP"]
答案2
我不知道有快捷方式,但您可以编写脚本来更改工作区标签:
#!/bin/zsh
#get desktop number
n=$(xdotool get_desktop)
n=$[n+1]
#get current workspace label
et=$(cat ~/.workspacenames/names| sed -n "$n p")
#prompt user for new workspace label
label=$(zenity --entry --entry-text="$et" --title="Workspace label" --text="New label")
if [ "$label" = "" ] ; then exit; fi
#replace the workspace label in our local file
sed "$n s/.*/$label/" -i ~/.workspacenames/names
#convert lines of the local file to an array gsettings can understand
magic=$(cat ~/.workspacenames/names | tr '\r\n' '|' | sed "s/.$/\"/;s/^/\"/;s/|/\",\"/g"|sed 's/\(.*\)/\[\1\]/')
#update settings
gsettings set org.gnome.desktop.wm.preferences workspace-names "$magic"
此脚本假设您已安装 zenity,并且有一个名为 的本地文件,~/.workspacenames/names
该文件在新行上为每个工作区命名。您可以将此脚本放在与名称相同的目录中,并且可以使用快捷方式(对我来说是Super+ W)来运行它。
答案3
更简洁的脚本(但需要qdbus
)。可能也适用于 bash。
#!/usr/bin/env zsh
# Capture output in evaljs properly
IFS=$'\n'
function evaljs() {
eval_res=($(qdbus org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval "$1"))
echo $eval_res[2]
}
if [[ -z $1 ]]; then
name=$(zenity --entry --entry-text="" --title="Workspace label" --text="New label")
else
name=$1
fi
evaljs "
const Gio = imports.gi.Gio;
let i = global.screen.get_active_workspace_index();
let settings = new Gio.Settings({ schema_id:
'org.gnome.desktop.wm.preferences'});
let names = settings.get_strv('workspace-names');
let oldName = names[i];
names[i] = '$name';
settings.set_strv('workspace-names', names);
oldName;
"
答案4
我很喜欢@anishsane 的回答,并且经常使用他的回答...但是我想改变它,以便如果设置了空名称,它会将名称重置为“WP#”。
由于 @anishsane 的解决方案需要使用两次 Python,因此我的版本只是用 Python 重写:
#! /usr/bin/python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, Gtk, GLib
import subprocess
gs = Gio.Settings.new("org.gnome.desktop.wm.preferences")
names = list(gs.get_value("workspace-names"))
# Get existing workspace number
current = int(subprocess.check_output(['xdotool', 'get_desktop']).strip())
# Create and run dialog
dialog = Gtk.Dialog(title="Workspace {} label".format(current+1))
dialog.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK,
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
dialog.set_default_response(Gtk.ResponseType.OK)
entry = Gtk.Entry(text=names[current])
entry.set_activates_default(True)
label = Gtk.Label(label="New label:")
a = dialog.get_content_area()
a.add(label)
a.add(entry)
a.show_all()
resp = dialog.run()
# If "OK" was clicked (or Enter was pressed)...
if resp == Gtk.ResponseType.OK:
value = entry.get_text().strip()
if value:
# ... either set the new name to the one chosen by the user...
names[current] = value
else:
# ... or to a placeholder if the user set the empty string.
names[current] = 'WP {}'.format(current + 1)
# Set the new names:
gs.set_value("workspace-names", GLib.Variant('as', value=names))