You are not logged in.

#1 2021-01-10 12:13:04

VoDo
Member
From: Europe
Registered: 2020-06-04
Posts: 122

[SOLVED]i3 restore session

I followed Arch Wiki
https://wiki.archlinux.org/index.php/I3

I can create workspace-1.json however when I run the next command

tail -n +2 ~/.config/i3/workspace_N.json | fgrep -v '// split' | sed 's|//||g' > ~/.config/i3/workspace_N.json

it deletes all the code inside this .json
Is that command incorrect or my mistakes somewhere?

 // vim:ts=4:sw=4:et
{
    "border": "pixel",
    "current_border_width": 1,
    "floating": "auto_off",
    "geometry": {
       "height": 1393,
       "width": 1515,
       "x": 0,
       "y": 0
    },
    "marks": [],
    "name": "i3: Layout saving in i3 — Mozilla Firefox",
    "percent": 0.6,
    "swallows": [
       {
       // "class": "^firefox$",
       // "instance": "^Navigator$",
       // "title": "^i3\\:\\ Layout\\ saving\\ in\\ i3\\ \\—\\ Mozilla\\ Firefox$",
       // "window_role": "^browser$"
       }
    ],
    "type": "con"
}

{
    // splitv split container with 2 children
    "border": "pixel",
    "floating": "auto_off",
    "layout": "splitv",
    "marks": [],
    "percent": 0.4,
    "type": "con",
    "nodes": [
        {
            // splith split container with 2 children
            "border": "pixel",
            "floating": "auto_off",
            "layout": "splith",
            "marks": [],
            "percent": 0.3,
            "type": "con",
            "nodes": [
                {
                    "border": "pixel",
                    "current_border_width": 1,
                    "floating": "auto_off",
                    "geometry": {
                       "height": 412,
                       "width": 644,
                       "x": 0,
                       "y": 0
                    },
                    "marks": [],
                    "name": "urxvt",
                    "percent": 0.5,
                    "swallows": [
                       {
                       // "class": "^URxvt$",
                       // "instance": "^urxvt$",
                       // "title": "^urxvt$"
                       }
                    ],
                    "type": "con"
                },
                {
                    "border": "pixel",
                    "current_border_width": 1,
                    "floating": "auto_off",
                    "geometry": {
                       "height": 412,
                       "width": 644,
                       "x": 0,
                       "y": 0
                    },
                    "marks": [],
                    "name": "urxvt",
                    "percent": 0.5,
                    "swallows": [
                       {
                       // "class": "^URxvt$",
                       // "instance": "^urxvt$",
                       // "title": "^urxvt$"
                       }
                    ],
                    "type": "con"
                }
            ]
        },
        {
            // splitv split container with 2 children
            "border": "pixel",
            "floating": "auto_off",
            "layout": "splitv",
            "marks": [],
            "percent": 0.7,
            "type": "con",
            "nodes": [
                {
                    // splith split container with 2 children
                    "border": "pixel",
                    "floating": "auto_off",
                    "layout": "splith",
                    "marks": [],
                    "percent": 0.5,
                    "type": "con",
                    "nodes": [
                        {
                            "border": "pixel",
                            "current_border_width": 1,
                            "floating": "auto_off",
                            "geometry": {
                               "height": 412,
                               "width": 644,
                               "x": 0,
                               "y": 0
                            },
                            "marks": [],
                            "name": "urxvt",
                            "percent": 0.675510204081633,
                            "swallows": [
                               {
                               // "class": "^URxvt$",
                               // "instance": "^urxvt$",
                               // "title": "^urxvt$"
                               }
                            ],
                            "type": "con"
                        },
                        {
                            // splitv split container with 2 children
                            "border": "pixel",
                            "floating": "auto_off",
                            "layout": "splitv",
                            "marks": [],
                            "percent": 0.324489795918367,
                            "type": "con",
                            "nodes": [
                                {
                                    "border": "pixel",
                                    "current_border_width": 1,
                                    "floating": "auto_off",
                                    "geometry": {
                                       "height": 412,
                                       "width": 644,
                                       "x": 0,
                                       "y": 0
                                    },
                                    "marks": [],
                                    "name": "urxvt",
                                    "percent": 0.5,
                                    "swallows": [
                                       {
                                       // "class": "^URxvt$",
                                       // "instance": "^urxvt$",
                                       // "title": "^urxvt$"
                                       }
                                    ],
                                    "type": "con"
                                },
                                {
                                    "border": "pixel",
                                    "current_border_width": 1,
                                    "floating": "auto_off",
                                    "geometry": {
                                       "height": 412,
                                       "width": 644,
                                       "x": 0,
                                       "y": 0
                                    },
                                    "marks": [],
                                    "name": "urxvt",
                                    "percent": 0.5,
                                    "swallows": [
                                       {
                                       // "class": "^URxvt$",
                                       // "instance": "^urxvt$",
                                       // "title": "^urxvt$"
                                       }
                                    ],
                                    "type": "con"
                                }
                            ]
                        }
                    ]
                },
                {
                    // splith split container with 2 children
                    "border": "pixel",
                    "floating": "auto_off",
                    "layout": "splith",
                    "marks": [],
                    "percent": 0.5,
                    "type": "con",
                    "nodes": [
                        {
                            "border": "pixel",
                            "current_border_width": 1,
                            "floating": "auto_off",
                            "geometry": {
                               "height": 412,
                               "width": 644,
                               "x": 0,
                               "y": 0
                            },
                            "marks": [],
                            "name": "urxvt",
                            "percent": 0.6,
                            "swallows": [
                               {
                               // "class": "^URxvt$",
                               // "instance": "^urxvt$",
                               // "title": "^urxvt$"
                               }
                            ],
                            "type": "con"
                        },
                        {
                            "border": "pixel",
                            "current_border_width": 1,
                            "floating": "auto_off",
                            "fullscreen_mode": 1,
                            "geometry": {
                               "height": 412,
                               "width": 644,
                               "x": 0,
                               "y": 0
                            },
                            "marks": [],
                            "name": "urxvt",
                            "percent": 0.4,
                            "swallows": [
                               {
                               // "class": "^URxvt$",
                               // "instance": "^urxvt$",
                               // "title": "^urxvt$"
                               }
                            ],
                            "type": "con"
                        }
                    ]
                }
            ]
        }
    ]
} 

Last edited by VoDo (2021-01-11 08:10:43)


Archi3

Offline

#2 2021-01-10 15:44:46

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,626

Re: [SOLVED]i3 restore session

type tail
type fgrep
type sed

What's the output for

tail -n +2 ~/.config/i3/workspace_N.json | fgrep -v '// split' | sed 's|//||g'

?
The command redirects its output into ~/.config/i3/workspace_N.json and overwrites that file, however the output should™ not be empty.

Online

#3 2021-01-10 15:56:59

VoDo
Member
From: Europe
Registered: 2020-06-04
Posts: 122

Re: [SOLVED]i3 restore session

Yeah in my limited understanding it should just overwrite the file, I do not know if it just should uncommend or add something else.

~ >>> type tail
tail is /usr/bin/tail
~ >>> type fgrep                                                                      
fgrep is /usr/bin/fgrep
~ >>> type sed                                                                        
sed is /usr/bin/sed
~ >>> tail -n +2 ~/.config/i3/workspace-1.json | fgrep -v '// split' | sed 's|//||g'  
{                                                                                   
    "border": "pixel",
    "current_border_width": 1,
    "floating": "auto_off",
    "geometry": {
       "height": 1393,
       "width": 1515,
       "x": 0,
       "y": 0
    },
    "marks": [],
    "name": "i3: Layout saving in i3 — Mozilla Firefox",
    "percent": 0.6,
    "swallows": [
       {
        "class": "^firefox$",
        "instance": "^Navigator$",
        "title": "^i3\\:\\ Layout\\ saving\\ in\\ i3\\ \\—\\ Mozilla\\ Firefox$",
        "window_role": "^browser$"
       }
    ],
    "type": "con"
}

{
    "border": "pixel",
    "floating": "auto_off",
    "layout": "splitv",
    "marks": [],
    "percent": 0.4,
    "type": "con",
    "nodes": [
        {
            "border": "pixel",
            "floating": "auto_off",
            "layout": "splith",
            "marks": [],
            "percent": 0.3,
            "type": "con",
            "nodes": [
                {
                    "border": "pixel",
                    "current_border_width": 1,
                    "floating": "auto_off",
                    "geometry": {
                       "height": 412,
                       "width": 644,
                       "x": 0,
                       "y": 0
                    },
                    "marks": [],
                    "name": "urxvt",
                    "percent": 0.5,
                    "swallows": [
                       {
                        "class": "^URxvt$",
                        "instance": "^urxvt$",
                        "title": "^urxvt$"
                       }
                    ],
                    "type": "con"
                },
                {
                    "border": "pixel",
                    "current_border_width": 1,
                    "floating": "auto_off",
                    "geometry": {
                       "height": 412,
                       "width": 644,
                       "x": 0,
                       "y": 0
                    },
                    "marks": [],
                    "name": "urxvt",
                    "percent": 0.5,
                    "swallows": [
                       {
                        "class": "^URxvt$",
                        "instance": "^urxvt$",
                        "title": "^urxvt$"
                       }
                    ],
                    "type": "con"
                }
            ]
        },
        {
            "border": "pixel",
            "floating": "auto_off",
            "layout": "splitv",
            "marks": [],
            "percent": 0.7,
            "type": "con",
            "nodes": [
                {
                    "border": "pixel",
                    "floating": "auto_off",
                    "layout": "splith",
                    "marks": [],
                    "percent": 0.5,
                    "type": "con",
                    "nodes": [
                        {
                            "border": "pixel",
                            "current_border_width": 1,
                            "floating": "auto_off",
                            "geometry": {
                               "height": 412,
                               "width": 644,
                               "x": 0,
                               "y": 0
                            },
                            "marks": [],
                            "name": "urxvt",
                            "percent": 0.675510204081633,
                            "swallows": [
                               {
                                "class": "^URxvt$",
                                "instance": "^urxvt$",
                                "title": "^urxvt$"
                               }
                            ],
                            "type": "con"
                        },
                        {
                            "border": "pixel",
                            "floating": "auto_off",
                            "layout": "splitv",
                            "marks": [],
                            "percent": 0.324489795918367,
                            "type": "con",
                            "nodes": [
                                {
                                    "border": "pixel",
                                    "current_border_width": 1,
                                    "floating": "auto_off",
                                    "geometry": {
                                       "height": 412,
                                       "width": 644,
                                       "x": 0,
                                       "y": 0
                                    },
                                    "marks": [],
                                    "name": "urxvt",
                                    "percent": 0.5,
                                    "swallows": [
                                       {
                                        "class": "^URxvt$",
                                        "instance": "^urxvt$",
                                        "title": "^urxvt$"
                                       }
                                    ],
                                    "type": "con"
                                },
                                {
                                    "border": "pixel",
                                    "current_border_width": 1,
                                    "floating": "auto_off",
                                    "geometry": {
                                       "height": 412,
                                       "width": 644,
                                       "x": 0,
                                       "y": 0
                                    },
                                    "marks": [],
                                    "name": "urxvt",
                                    "percent": 0.5,
                                    "swallows": [
                                       {
                                        "class": "^URxvt$",
                                        "instance": "^urxvt$",
                                        "title": "^urxvt$"
                                       }
                                    ],
                                    "type": "con"
                                }
                            ]
                        }
                    ]
                },
                {
                    "border": "pixel",
                    "floating": "auto_off",
                    "layout": "splith",
                    "marks": [],
                    "percent": 0.5,
                    "type": "con",
                    "nodes": [
                        {
                            "border": "pixel",
                            "current_border_width": 1,
                            "floating": "auto_off",
                            "geometry": {
                               "height": 412,
                               "width": 644,
                               "x": 0,
                               "y": 0
                            },
                            "marks": [],
                            "name": "urxvt",
                            "percent": 0.6,
                            "swallows": [
                               {
                                "class": "^URxvt$",
                                "instance": "^urxvt$",
                                "title": "^urxvt$"
                               }
                            ],
                            "type": "con"
                        },
                        {
                            "border": "pixel",
                            "current_border_width": 1,
                            "floating": "auto_off",
                            "fullscreen_mode": 1,
                            "geometry": {
                               "height": 412,
                               "width": 644,
                               "x": 0,
                               "y": 0
                            },
                            "marks": [],
                            "name": "urxvt",
                            "percent": 0.4,
                            "swallows": [
                               {
                                "class": "^URxvt$",
                                "instance": "^urxvt$",
                                "title": "^urxvt$"
                               }
                            ],
                            "type": "con"
                        }
                    ]
                }
            ]
        }
    ]
}

If I create a new file ie > new file after that tail command it creates file with code but when I run it it shows black screen with

[class=^URxvt$"instance.....]

Last edited by VoDo (2021-01-10 16:05:12)


Archi3

Offline

#4 2021-01-10 16:02:42

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,626

Re: [SOLVED]i3 restore session

That's the expectable output.
What's

echo $SHELL

Online

#5 2021-01-10 16:07:24

VoDo
Member
From: Europe
Registered: 2020-06-04
Posts: 122

Re: [SOLVED]i3 restore session

I use zsh

/bin/zsh

Archi3

Offline

#6 2021-01-10 16:07:54

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,626

Re: [SOLVED]i3 restore session

Also OMZ?

Online

#7 2021-01-10 16:08:48

VoDo
Member
From: Europe
Registered: 2020-06-04
Posts: 122

Re: [SOLVED]i3 restore session

Could it be that I use i3-gaps instead of i3-wm?

I did not install OMZ but have some .zsrhc config for a long time

I switched to bash in terminal a run it again same output black window with that message

Last edited by VoDo (2021-01-10 16:12:33)


Archi3

Offline

#8 2021-01-10 16:14:37

VoDo
Member
From: Europe
Registered: 2020-06-04
Posts: 122

Re: [SOLVED]i3 restore session

It is not critical issue I update every Sunday, just. I can live with reorganizing my windows every Sunday smile


Archi3

Offline

#9 2021-01-10 17:08:57

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,626

Re: [SOLVED]i3 restore session

I switched to bash in terminal a run it again same output black window with that message

Wait a second: your OP suggests that

tail -n +2 ~/.config/i3/workspace_N.json | fgrep -v '// split' | sed 's|//||g' > ~/.config/i3/workspace_N.json

results in a blank ~/.config/i3/workspace_N.json
Is that the case? If not, please describe the actual issue at hand, symptoms, error messages etc.

Online

#10 2021-01-10 17:41:33

VoDo
Member
From: Europe
Registered: 2020-06-04
Posts: 122

Re: [SOLVED]i3 restore session

OK sorry, it was empty then I used the tail command to create a NEW file not overwrite the old, it worked. Hovewer when I run restoring command

i3-msg "workspace 2; append_layout /home/arch/.config/i3/workspace-1.json"

it does not restore the session it just opens new workspace (I use workspace2) with black fullscreen window where this is written

 [class=^URxvt$"instance.....]

I tried to remove those // manually in copied json code with the same result so problem is in my i3 I thinks i3-gaps?

Last edited by VoDo (2021-01-10 17:42:21)


Archi3

Offline

#11 2021-01-10 21:58:45

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,599

Re: [SOLVED]i3 restore session

I'm not going into everything said here besides, input can't be output without a step in between..

VoDo wrote:

it does not restore the session it just opens new workspace (I use workspace2) with black fullscreen window where this is written

 [class=^URxvt$"instance.....]

I tried to remove those // manually in copied json code with the same result so problem is in my i3 I thinks i3-gaps?

You seem to not fully get what it is that's happening here for what you see is actually correct..
The restore sessions is just a place holder.
So, instead of the program you think should be executed, you create a place holder for it, it doesn't actually open the program it just reserves a place for that program if executed.
Lets say you created a placeholder for firefox and 2 terminals, if you would add these to your config also the place holders would be filled right away F.I.

exec --no-startup-id "i3-msg 'workspace 1mon1; append_layout $HOME/.config/i3/workspace-1.json'"
exec --no-startup-id firefox
exec --no-startup-id xterm
exec --no-startup-id xterm

Offline

#12 2021-01-10 22:49:00

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,626

Re: [SOLVED]i3 restore session

input can't be output without a step in between

The relevant step here are the two pipes which should™ generate a 4k blockbuffer that should™ successfully cache the file before writing it.
(Try and then try "stdbuf -oL tail -n +2 | …" which will limit the buffer to a line, you should™ now get an empty result)

The command as is, is stupid but should™n't cause an empty file… *shrug*

More reliable:

sed -i '1,2d; /\/\/ split/d; s|//||g' $HOME/.config/i3/workspace-1.json

Online

#13 2021-01-10 23:40:19

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,599

Re: [SOLVED]i3 restore session

Using temp files or dual pipes ads just unnecessary layers and I wouldn't use that command either but something like that sed command you pasted.
On the other hand I don't get why he's trying to remove perfectly fine notes, there's no need to do that at all;)

edit: I see looking at OP's file I need clarify: don't do that, removing all '//' with a command, some are meant to be a comment even though json uses a different way to comment like "comment": "a comment", the line lines with '//' are disregarded in json but not proper comment far as I know/understand
If you use that command also ' // vim:ts=4:sw=4:et' & '// splitv split container with 2 children' the '//' are removed which makes no sense, well the vim one may..
Best remove the ones to enable by hand or use different files for different purposes.

Last edited by qinohe (2021-01-11 00:27:16)

Offline

#14 2021-01-11 08:10:17

VoDo
Member
From: Europe
Registered: 2020-06-04
Posts: 122

Re: [SOLVED]i3 restore session

Thank you both I will try what is suggested in #11 and yes you are right I did not fully understand what was needed I missed the part of starting those programs too.


Archi3

Offline

Board footer

Powered by FluxBB