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 2014-03-30 16:13:48 +0000

jameshfisher gravatar image

updated 2014-03-30 16:14:07 +0000

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2014-03-30 18:23:58 +0000

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 + '"');
});
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-03-30 16:13:48 +0000

Seen: 325 times

Last updated: Mar 30 '14