0

I saved the layout for my workspace following the docs:

i3-save-tree --workspace 1 > ~/.i3/layouts/ws1.json

Because my workspace name is a quoted string variable, I had to make a script (~/.i3/scripts/load_layout.sh) in order to call i3-msg properly:

i3-msg "workspace $1"
i3-msg "append_layout /home/villasv/.i3/layouts/ws$2.json"

Then my ~/.i3/config file had the following for workspace setup:

set $ws1 "1 "
bindsym $mod+1 workspace $ws1
bindsym $mod+Shift+1 move container to workspace $ws1
exec --no-startup-id 'sh ~/.i3/scripts/load_layout.sh $ws1 1'
exec firefox

But the layout change does not happen after sign out and sign in. I've tried even using exec_always and restarting i3, but still no effect.

Running sh ~/.i3/scripts/load_layout.sh "dummy" 1 successfuly creates a workspace with the layout.

Also, using exec --no-startup-id "i3-msg 'workspace 1; append_layout ~/.i3/layouts/ws1.json'" wil also work, almost as desired. I guess the problem happens in the script or the script call, but I don't know what.

What am I missing to make this work with workspace variable names?

villasv
  • 6,304
  • 2
  • 44
  • 78

2 Answers2

2

There are a two reasons this does not work:

  1. You quoted the whole command in with single quotes ('). Single quotes are not special in i3 configurations. That means they are not "parsed away" and thus 'sh ~/.i3/scripts/load_layout.sh $ws1 1' as a whole is taken as the name of the command, spaces and all, instead of the command sh with multiple arguments.
  2. Your workspace name contains a space. So, even if 1. were not an issue, it would fail because the first argument - $ws1 - to your script is not quoted on its own. This would leads to the script getting three - 1 and 1 - instead of two arguments - 1  and 1.

Try this exec command instead:

exec --no-startup-id sh ~/.i3/scripts/load_layout.sh '$ws1' 1

As noted the single quotes around $ws1 will not be stripped away by the i3 configuration parser, so they will be present when passing on the argument. Also, as i3 is doing the replacment of $ws1 the usual rule that shell variables are not expanded inside single quotes does not apply.

Adaephon
  • 16,929
  • 1
  • 54
  • 71
  • you are right that my workspace name contains a space, but it *was* also quoted, so the replacement of `$ws1` is also quoted. woudn't that solve issue 2? – villasv Aug 18 '16 at 15:41
  • No, unfortunately it would not help because the double quotes are stripped away by *i3's* configuration parser. That is one of the reasons why quoting shell commands correctly in *i3's* configuration is notoriously difficult. Especially when needing multiple levels of quotes and/or variables. – Adaephon Aug 18 '16 at 16:32
1

Well, I could not find out what the problem was, but I found a simple workaround that I've discovered by trial and error.

Simply defining the workspace name without quotation marks will work fine, and won't disrupt the one-liner provided in the docs.

So my solution was the change set $ws1 "1 " -> set $ws1 1 

villasv
  • 6,304
  • 2
  • 44
  • 78