You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an usecase where I want to use several directories with tmuxp workspace definitions
I though that the easiest way to do it would be to put symbolic links to my folders in ~/.config/tmuxp but found out that the session file discovery isn’t recursive :
I wonder if recursive session file discovery would be a good feature.
Implementation ideas
I implemented the feature in the patch shown below.
As it follows symlinks, it could lead to infinite loops.
Patch implementing the feature (draft, no tests)
diff --git a/src/tmuxp/cli/ls.py b/src/tmuxp/cli/ls.py
index e0447edf..c5998afb 100644
--- a/src/tmuxp/cli/ls.py+++ b/src/tmuxp/cli/ls.py@@ -1,6 +1,7 @@
import argparse
import os
import typing as t
+from itertools import chain
from tmuxp.workspace.constants import VALID_WORKSPACE_DIR_FILE_EXTENSIONS
from tmuxp.workspace.finders import get_workspace_dir
@@ -17,7 +18,11 @@ def command_ls(
) -> None:
tmuxp_dir = get_workspace_dir()
if os.path.exists(tmuxp_dir) and os.path.isdir(tmuxp_dir):
- for f in sorted(os.listdir(tmuxp_dir)):+ for f in sorted(+ chain.from_iterable(+ files for _, _, files in os.walk(tmuxp_dir, followlinks=True)+ )+ ):
stem, ext = os.path.splitext(f)
if os.path.isdir(f) or ext not in VALID_WORKSPACE_DIR_FILE_EXTENSIONS:
continue
diff --git a/src/tmuxp/workspace/finders.py b/src/tmuxp/workspace/finders.py
index 2cb0360a..799bae4b 100644
--- a/src/tmuxp/workspace/finders.py+++ b/src/tmuxp/workspace/finders.py@@ -128,6 +128,14 @@ def get_workspace_dir() -> str:
return path
+def _dirs_and_ext(+ workspace_base_dir: str, extensions: list[str] = VALID_WORKSPACE_DIR_FILE_EXTENSIONS+):+ for dir, _, _ in os.walk(workspace_base_dir, followlinks=True):+ for extension in extensions:+ yield dir, extension++
def find_workspace_file(
workspace_file: StrPath,
workspace_dir: t.Optional[StrPath] = None,
@@ -184,8 +192,8 @@ def find_workspace_file(
candidates = [
x
for x in [
- f"{join(workspace_dir, workspace_file)}{ext}"- for ext in VALID_WORKSPACE_DIR_FILE_EXTENSIONS+ f"{join(dir, workspace_file)}{ext}"+ for dir, ext in _dirs_and_ext(workspace_dir)
]
if exists(x)
]
While trying to implement the feature, I noticed that the in_dir and in_cwd functions aren’t used except in the tests. Why is that ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I have an usecase where I want to use several directories with tmuxp workspace definitions
I though that the easiest way to do it would be to put symbolic links to my folders in
~/.config/tmuxp
but found out that the session file discovery isn’t recursive :only
my-other-config
can be used withtmuxp load
.I wonder if recursive session file discovery would be a good feature.
Implementation ideas
I implemented the feature in the patch shown below.
As it follows symlinks, it could lead to infinite loops.
Patch implementing the feature (draft, no tests)
While trying to implement the feature, I noticed that the
in_dir
andin_cwd
functions aren’t used except in the tests. Why is that ?Beta Was this translation helpful? Give feedback.
All reactions