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

Script: How do I print the workspace number?

asked Nov 25 '13

geo909 gravatar image

updated Nov 25 '13

I occasionally want to rename my workspaces and refer to them by their numbers. So I switched from workspace to workspace number and renamed them like so:

1 renamed to 1: www

2 renamed to 2: music, etc

as per the user guide. Furthermore, following the suggestion from section 6.5.2 of the user guide, I added the following line in my configuration file:

bindsym $mod+n exec i3-input -F 'rename workspace to %s' -P 'New name: '

However, I would like to avoid typing "1: www" if I could just type www and automatically have the workspace number assigned. In particular, I need a variable, say $WSNUM such that I could write the line like so:

bindsym $mod+n exec i3-input -F 'rename workspace to "$WSNUM: %s"' -P 'New name: '

Is there such a variable? How should I write this line?

Comments

Oops. I think this is a duplicate of https://faq.i3wm.org/question/451/dynamically-change-workspace-name-with-ease/ I will check it out more thoroughly and will close this question if it is so. EDIT: No, it's not exactly duplicate, plus the script in that question does not work for me.

geo909 gravatar imagegeo909 (Nov 25 '13)edit

It seems the solution is in section 3.3 of http://i3wm.org/docs/ipc.html#_workspaces_reply (due to my karma I cannot post links). Apparently the workspace number is part of the reply for the workspaces of the IPC interface. I am trying to read through but I'm totally lost, don't know how to use it..

geo909 gravatar imagegeo909 (Nov 25 '13)edit

1 answer

Sort by » oldest newest most voted
2

answered Nov 25 '13

TonyC gravatar image

Use a script

WS=`python3 -c "import json; print(next(filter(lambda w: w['focused'], json.loads('$(i3-msg -t get_workspaces)')))['num'])"`; i3-input -F "rename workspace to $WS:%s" -P 'New name'

Comments

Thanks, but this doesn't work.. If I input `www` in workspace 2, it will rename it to "2:".. I run it from the command line.

geo909 gravatar imagegeo909 (Nov 25 '13)edit

I think you might be adding a space after the colon. Running it just like that works for me

TonyC gravatar imageTonyC (Nov 25 '13)edit

Indeed, I must have done something funny.. Thank you!

geo909 gravatar imagegeo909 (Nov 25 '13)edit

Or try `WS=$(python3 -c "import json; print(next(filter(lambda w: w['focused'], json.loads('$(i3-msg -t get_workspaces)')))['num'])"); i3-input -F "rename workspace to \"$WS: %s\"" -P 'New name'` if you'd like to keep the space after the colon. ( ` `` ` replaced by `$()` just for formatting)

Adaephon gravatar imageAdaephon (Nov 25 '13)edit

Question Tools

Stats

Asked: Nov 25 '13

Seen: 187 times

Last updated: Nov 25 '13