Skip to content

Instantly share code, notes, and snippets.

@andergrim
Created September 10, 2015 17:46
Show Gist options
  • Save andergrim/0a778b397b8db0e4b208 to your computer and use it in GitHub Desktop.
Save andergrim/0a778b397b8db0e4b208 to your computer and use it in GitHub Desktop.
Script and instruction on a flexible i3 window manager workspace name changer.

i3 WM workspace name changer

This script enables dynamic workspace name changing in the i3 window manager. The script is based on this script by Jeroen Janssens .

Usage

Press you desired key combination ($mod+n) and enter the new workspace name. If you run it on workspace 1 and enter "irc" at the prompt the workspace will be named 1:irc. Using the numbered workspace configuration in i3 it will be accessible using your normal key binding (such as $mod+1) even though it has been renamed.

The script

Save this bash script as i3-rename-workspace somewhere within your system path. Don't forget to make it executable.

#!/bin/bash
WS=$(i3-msg -t 'get_workspaces' | sed -e 's/{"num/\n{"num/g' | grep \"focused\":true | sed -e 's/,"/\n/g' | grep name | cut -d\" -f 3)
WS_TEXT=$(echo $WS | cut -d \: -f 2)
WS_NR=$(echo $WS | cut -d \: -f 1)
NEW=$(zenity --text="Enter new name:" --entry --title="Rename workspace $WS" --entry-text="$WS_TEXT")
i3-msg "rename workspace \"$WS\" to \"$WS_NR:$NEW\"" 

i3 Configuration

Make the following changes to ~/.i3/config

Add the key binding

bindsym $mod+n exec i3-rename-workspace

Make sure your workspace switching key bindings are using the numbered directive

bindsym $mod+1 workspace number 1
bindsym $mod+1 workspace number 2
...

bindsym $mod+Shift+1 move container to workspace number 1
bindsym $mod+Shift+1 move container to workspace number 2
...
@zenVentzi
Copy link

Doesn't seem to work? Also tried the other script that this one is based on, same output.

ERROR: Old workspace "1
2
9" not found
[{"success":false,"error":"Old workspace \"1\n2\n9\" not found"}]

Step1 execute command:
image
Step2 change name and click OK:
image
Step3 receive error message:
image

@zenVentzi
Copy link

Here is an updated, simpler version that works:

#!/bin/bash
WS_NAME=$(i3-msg -t get_workspaces | jq -r '.[] | select(.focused==true).name')
WS_NAME_NEW=$(zenity --text="Enter new name:" --entry --title="Rename workspace $WS_NAME" --entry-text="$WS_NAME")
i3-msg "rename workspace \"$WS_NAME\" to \"$WS_NAME_NEW\"" 

@holidaycereal
Copy link

holidaycereal commented Mar 10, 2024

made rofi version with workspace numbers yay

WS_NAME=$(i3-msg -t get_workspaces | jq -r '.[] | select(.focused==true).name')
WS_NUM=$(wmctrl -d | grep "*" | cut -d \: -f 4 | grep -o [0-9])
WS_NAME_NEW=$(echo "" | rofi -dmenu -p "")
i3-msg "rename workspace \"$WS_NAME\" to \"$WS_NUM: $WS_NAME_NEW\""

@alvaroringo
Copy link

thanks for the idea, thanks for the updated fix zenVentzi it work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment