Skip to content

Commit 251aae4

Browse files
committed
If keep_alive file contains filenames, open those instead of orig files
1 parent 81a5ca4 commit 251aae4

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ The format is based on [Keep a Changelog], and this project adheres to
1111

1212
## [Unreleased](https://github.com/bbugyi200/zorg/compare/0.2.1...HEAD)
1313

14-
No notable changes have been made.
14+
### Added
15+
16+
* Add support for changing the paths opened in vim by writing those file paths
17+
to `/tmp/zorg_keep_alive`.
1518

1619

1720
## [0.2.1](https://github.com/bbugyi200/zorg/compare/0.2.0...0.2.1) - 2024-03-07

src/zorg/runners.py

+20-12
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,33 @@ def _start_vim_loop(zo_paths: Iterable[Path], cfg: EditConfig) -> None:
5959
"Vim loop will run as long as the keep alive file exists.",
6060
keep_alive_file=cfg.keep_alive_file,
6161
)
62+
last_paths = zo_paths
6263
while cfg.keep_alive_file.exists():
64+
if cfg.keep_alive_file.stat().st_size == 0:
65+
paths = last_paths
66+
else:
67+
paths = last_paths = [
68+
Path(p.strip())
69+
for p in cfg.keep_alive_file.read_text().split()
70+
]
71+
6372
cfg.keep_alive_file.unlink()
6473
vimala.vim(
65-
*[cfg.zettel_dir / p for p in zo_paths],
74+
*[cfg.zettel_dir / p for p in paths],
6675
commands=_process_vim_commands(cfg.zettel_dir, cfg.vim_commands),
6776
)
6877

6978

79+
def _process_vim_commands(
80+
zettel_dir: Path, vim_commands: Iterable[str]
81+
) -> Iterator[str]:
82+
for vim_cmd in vim_commands:
83+
if "{zdir}" in vim_cmd:
84+
yield vim_cmd.format(zdir=zettel_dir)
85+
else:
86+
yield vim_cmd
87+
88+
7089
@runner
7190
def run_new(cfg: NewConfig) -> int:
7291
"""Runner for the 'new' command."""
@@ -112,14 +131,3 @@ def _build_template_in_dir(
112131
else line
113132
)
114133
temp_template_path.write_text("".join(new_lines))
115-
116-
117-
# TODO(bugyi): Move to config.py?
118-
def _process_vim_commands(
119-
zettel_dir: Path, vim_commands: Iterable[str]
120-
) -> Iterator[str]:
121-
for vim_cmd in vim_commands:
122-
if "{zdir}" in vim_cmd:
123-
yield vim_cmd.format(zdir=zettel_dir)
124-
else:
125-
yield vim_cmd

0 commit comments

Comments
 (0)