Skip to main content

A simple but flexible solution to saving and restoring i3 workspace layouts

Project description

i3-resurrect

A simple but flexible solution to saving and restoring i3 workspace layouts

Table of Contents

Introduction

i3-resurrect originated as a mixture of hacked together Python and bash scripts that I wrote in order to be able to quickly save and load workspaces on the fly.

I hate having to reboot my computer because it disrupts everything I have open (which tends to be a lot).

To cope with this problem, I try to make it as easy as possible for myself to get everything back to its pre-reboot state.

I quickly found out about the i3-save-tree utility and i3's append-layout command, but these weren't much use to me on their own, as you are expected to customise a layout manually after saving it and relaunch all your programs manually when you restore the layout.

My solution was to create a script that would extract just the bits from i3-save-tree that are needed, and use the i3ipc, wmctrl, and psutil Python libraries to obtain the commands necessary to launch the programs in a saved workspace.

Since I decided to release this publicly, I have improved the standard of the code a great deal and gotten rid of the hacky bash parts.

Getting Started

Installation

From PyPI (recommended)

pip3 install --user i3-resurrect

Manual

Obtain source code

git clone git@github.com:JonnyHaystack/i3-resurrect.git

Install dependencies then run script directly

# Install dependencies
cd i3-resurrect
pip3 install --user -r requirements.txt

# Run script directly
python3 i3-resurrect.py

Or just install locally using pip

pip3 install --user .

Usage

Command line

# Save workspace '1'
i3-resurrect save -w 1

# Restore workspace '1'
i3-resurrect restore -w 1

Example configuration in i3

# Save workspace mode.
mode "save" {
  bindsym 1 exec "i3-resurrect save -w 1"
  bindsym 2 exec "i3-resurrect save -w 2"
  bindsym 3 exec "i3-resurrect save -w 3"
  bindsym 4 exec "i3-resurrect save -w 4"
  bindsym 5 exec "i3-resurrect save -w 5"
  bindsym 6 exec "i3-resurrect save -w 6"
  bindsym 7 exec "i3-resurrect save -w 7"
  bindsym 8 exec "i3-resurrect save -w 8"
  bindsym 9 exec "i3-resurrect save -w 9"
  bindsym 0 exec "i3-resurrect save -w 0"

  # Back to normal: Enter, Escape, or s
  bindsym Return mode "default"
  bindsym Escape mode "default"
  bindsym s mode "default"
  bindsym $mod+s mode "default"
}

bindsym $mod+s mode "save"

# Restore workspace mode.
mode "restore" {
  bindsym 1 exec "i3-resurrect restore -w 1"
  bindsym 2 exec "i3-resurrect restore -w 2"
  bindsym 3 exec "i3-resurrect restore -w 3"
  bindsym 4 exec "i3-resurrect restore -w 4"
  bindsym 5 exec "i3-resurrect restore -w 5"
  bindsym 6 exec "i3-resurrect restore -w 6"
  bindsym 7 exec "i3-resurrect restore -w 7"
  bindsym 8 exec "i3-resurrect restore -w 8"
  bindsym 9 exec "i3-resurrect restore -w 9"
  bindsym 0 exec "i3-resurrect restore -w 0"

  # Back to normal: Enter, Escape, or n
  bindsym Return mode "default"
  bindsym Escape mode "default"
  bindsym n mode "default"
  bindsym $mod+n mode "default"
}

bindsym $mod+n mode "restore"

Configuration

The config file should be located at ~/.config/i3-resurrect/config.json. You will have to create it yourself if you want to use it.

In the case of a window where the process cmdline is not the same as the command you must run to launch that program, you can add an explicit window class to command mapping in the config file.

For example, gnome-terminal's process is gnome-terminal-server, but we need to launch it with the command gnome-terminal. To get this working, you would put the following in your config file:

{
  "window_command_mappings": {
    "Gnome-terminal": "gnome-terminal"
  }
}

If you need to find out a window's class, type xprop | grep WM_CLASS in a terminal and then click on the desired window.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Built With

  • i3ipc - Used to get the list of windows in a specified workspace
  • wmctrl - Used to get the PIDs of the windows that are retrieved using i3ipc
  • psutil - Used to get the cmdline and cwd of each process

Contributors

See also the list of contributors who participated in this project.

Acknowledgments

  • @acrisci - for the i3ipc Python library
  • @antocuni - for the wmctrl Python library
  • @giampaolo - for the psutil Python library
  • Everyone who has worked on i3

Related projects

For those interested, other excellent software I use to get things up and running quickly includes:

  • tmux-resurrect - which obviously also inspired the name of this project
  • tmux-continuum - an excellent companion to tmux-resurrect
  • qutebrowser - which has excellent session management, especially if you create bindings for saving and loading individual windows

License

This project is licensed under the GNU GPL Version 3 - see the LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

i3-resurrect-1.0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

i3_resurrect-1.0.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file i3-resurrect-1.0.1.tar.gz.

File metadata

  • Download URL: i3-resurrect-1.0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for i3-resurrect-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ff5eef1a179f22e2b177b76f333159e26da7beeac196d20d3387cedf6974bd41
MD5 326b72b6bafd2cd21bd557e885e8e220
BLAKE2b-256 e6054a62cfaaef6da666f62ee1ecfb821c64cd7f9622715cb47cbd73548cac56

See more details on using hashes here.

File details

Details for the file i3_resurrect-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: i3_resurrect-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for i3_resurrect-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f7fbc91a1df693ab97905015fd943af9f4bf269fbcca203093468b7160b8a58
MD5 9557f12cf95b65240f3f8ccddb11cddb
BLAKE2b-256 7c891c94d1d0facb1391eb22c6ee834c3df53cff86c5298538831fb3286ba1d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page