A library for storage and restore of system state in terms of windows and workspaces
pyxis is the Latin name for the box housing a mariner's compass. This name also relates to the 'box tree' (Buxus sempervirens), whose wood is a source of buxine, a steroid alkaloid used to treat fever. In a similar vein, this library aims to be an elaborate cabinet for process-centric storage of all the components that make up a developer's workflow, to assist in the shutting down of a system in use and restoring its workflow to the same state it was in before.
pyx-sys
has no external Python dependencies beyond the standard library. You will need:
- dejsonlz4 (GitHub: avih/dejsonlz4)
- Used to decompress recovery JSON of Firefox browser state (windows, tabs, recent history)
- Clone into
~/opt/
, symlink the binary at~/opt/bin/dejsonlz4
and add~/opt/bin/
to your PATH
- Linux
- For use with Mac/Windows, I'd need to see their Firefox
sessionstore-backups
location
- For use with Mac/Windows, I'd need to see their Firefox
- X window system (
xwininfo
must be called to retrieve the list of windows) wmctrl
(determine workspaces the windows are in through the window manager)tmux
(to obtain listings of terminal windows, any splits/resultant panes, and activities therein).bashrc
must include awmctrl
call totmux
that changes the title of tmux windows upon creation to include the tmux window ID in thegnome-terminal
title
if tmux info &> /dev/null; then
# Tmux server is up, set the terminal title to be the tmux window ID
TMUX_WINDOW_TITLE=$(tmux run "echo 'Terminal #{window_id}'")
wmctrl -r :ACTIVE: -N "$TMUX_WINDOW_TITLE";
fi
This library has now been reorganised as a package ready for distribution on PyPi, with an entrypoint
pyx-space
to function as a simple command to execute a relabelling of all workspaces on the system.
The next step is to determine which terminal is where (at what working directory), and what it's running
there (i.e. what its PID is, perhaps using psutil
). This is available from the list-panes
output,
which is only semi-finished parsing (I got sidetracked cross-referencing window IDs).
See tm/pane.py
where the function list_panes
should be finished (it is currently still partly just
a copy of list_windows
and needs some rethinking), and then added to a Pane
object
(currently only some of the info retrieved is being used, the pane_id
, within the PaneGeom
).
There should be enough info at the pane level to create a descriptive summary string indicating the contents of all panes within all terminal windows in tmux, and thus the terminal window can be serialised to a persistent and immediately readable format (desktop workspace names).
This will achieve a large part of pyx-space
. Once it's working for human-readable 'storage',
we can move onto considering machine-readability and 'restoring' from this representation.
- Access the
xwininfo
tree, stored as aWindowTree
class with achildren
attribute that can be walked to enumerate all windows on the system.- Modify and activate particular windows in the tree using
wmctrl
given their ID - Cross-reference to the workspace listing
- Modify and activate particular windows in the tree using
- Access the
wmctrl
workspace listing, stored as aWorkspaceTerritory
class with asticky_windows
attribute containing the desktop windows and aworkspaces
attribute, each of which has awindows
attribute that lists all windows in that workspace- Connect window IDs to those in the
WindowTree
fromxwininfo
(differ by one hex digit) - Restore windows to a workspace from a pickled
WorkspaceTerritory
on disk
- Connect window IDs to those in the
- List Firefox window/tab list which can be cross-referenced to the X window/workspace list
- Store the list of windows/tabs
- Cross-reference to the X window/workspace list
- List tmux terminal session list (e.g. which text files are open in vim, command line paths, etc.)
- cross-reference to X window/workspace list
- In part, the purpose is to catalogue and archive tabs being viewed rather than have this be standalone logs
- The goal is to feed into these logs and for their use to also be fed from a mobile app
- Initially however, the goal is to provide session restore for as many components of the developer workflow as possible
- especially so as to keep associated activities (e.g. doc reading in a browser alongside app development in a terminal) recorded together.
- Partly this is for session restore, however it may also be used for 'reference restore', i.e. restore at a later date, (for instance when returning to work on a particular feature and opening both the code files and the docs together).
When the module is run (python3 -im pyxsys
from the src/
directory), __main__.py
calls cli.py
and finally
adds four local variables to the Python environment:
ff_session
—pyxsys.ff.session
⠶BrowserSession
class representing a Firefox browser's state (excluding incognito windows)x_session
—pyxsys.x.tree
⠶WindowTree
class representing the X window manager's listing of windows in the active sessionwm_territory
—pyxsys.wm.territory
⠶WorkspaceTerritory
class representing thewmctrl
-derived window manager set of workspaces (which I term a 'territory' following the notion of Zubin spaces from the GIS research literature on "spatial information theory")tmux_server
—pyxsys.tm.server
⠶TmuxServer
class representing the currently running tmux instance, all terminals across all windows/workspaces, and listing relevant information about all panes within them.
They look something like this:
>>> ff_session
BrowserSession of 11 windows, since 2020-03-05 16:48:39.172000
>>> x_session
WindowTree (rooted at RootWindow, id: 0x13f, (has no name))
>>> wm_territory
WorkspaceTerritory of 9 workspaces (30 windows)
>>> tmux_server
TmuxServer of 15 sessions (15 windows)
I'm currently working on finishing off the finer details of these classes, and aim to make them 'work together', i.e. cross-reference their IDs and related activities.
- Wiki ⠶ Firefox profiles
- Initial spark for this project was these 2 Q&A posts: