The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
2

How can I renumber workspaces?

asked Mar 30 '14

jameshfisher gravatar image

updated Mar 30 '14

After a while, I end up with my workspace list looking like: 2 5 6 7 9 .... I would like to consolidate these; i.e. renumber them to 1 2 3 4 5 .... Is that possible? Is there a shortcut for it? If not how can I create a shortcut for it?

1 answer

Sort by » oldest newest most voted
3

answered Mar 30 '14

TonyC gravatar image

You can do this with the new ipc library. This script uses the JavaScript version but the same API is available in many languages. You can find the latest version of this script here.

#!/usr/bin/env gjs

/*
   This example shows how to renumber your workspaces so they are consolidated
   into a harmonious linear order starting from 1. For instance, if you have
   open workspaces 2, 5, 6, 7, 9 they will be renumbered to 1, 2, 3, 4, 5
   respectively.

   https://faq.i3wm.org/question/3595/how-can-i-renumber-workspaces/
*/

const i3ipc = imports.gi.i3ipc;

let conn = new i3ipc.Connection;

let workspaces = conn.get_workspaces()
    .filter(function(ws) {
        return !isNaN(parseInt(ws.name));
    }).sort(function(a, b) {
        return parseInt(a.name) - parseInt(b.name);
    });

workspaces.forEach(function(ws, i) {
    let new_name = ws.name.replace(parseInt(ws.name).toString(), (i + 1).toString());
    conn.command('rename workspace "' + ws.name + '" to "' + new_name + '"');
});

Question Tools

Stats

Asked: Mar 30 '14

Seen: 325 times

Last updated: Mar 30 '14