The i3 FAQ has migrated to https://www.reddit.com/r/i3wm/. All content here is read-only.
Ask Your Question
0

Script: How do I print the workspace number?

asked 2013-11-25 16:21:56 +0000

geo909 gravatar image

updated 2013-11-25 16:44:30 +0000

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?

edit retag flag offensive close merge delete

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 ( 2013-11-25 16:29:18 +0000 )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 ( 2013-11-25 18:08:02 +0000 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-11-25 18:31:35 +0000

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'
edit flag offensive delete link more

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 ( 2013-11-25 18:47:44 +0000 )edit

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

TonyC gravatar imageTonyC ( 2013-11-25 18:55:15 +0000 )edit

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

geo909 gravatar imagegeo909 ( 2013-11-25 20:14:51 +0000 )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 ( 2013-11-25 20:16:48 +0000 )edit

Question Tools

Stats

Asked: 2013-11-25 16:21:56 +0000

Seen: 187 times

Last updated: Nov 25 '13