-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request #41 from davep/jump-to-obsidian-vault
Add `obsidian` as a command for the command line
- Loading branch information
Showing
6 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Provides a command for browsing Obsidian vaults.""" | ||
|
||
############################################################################## | ||
# Python imports. | ||
from pathlib import Path | ||
|
||
############################################################################## | ||
# Textual imports. | ||
from textual.widget import Widget | ||
|
||
############################################################################## | ||
# Local imports. | ||
from ...data import load_configuration | ||
from ...messages import SetLocalViewRoot | ||
from .base_command import InputCommand | ||
|
||
|
||
############################################################################## | ||
class ObsidianCommand(InputCommand): | ||
"""Change the root directory to your Obsidian vaults""" | ||
|
||
COMMAND = "`obsidian`" | ||
ALIASES = "`obs`" | ||
|
||
@classmethod | ||
def handle(cls, text: str, for_widget: Widget) -> bool: | ||
"""Handle the command. | ||
Args: | ||
text: The text of the command. | ||
for_widget: The widget to handle the command for. | ||
Returns: | ||
`True` if the command was handled; `False` if not. | ||
""" | ||
if cls.is_command(text): | ||
if vaults := Path(load_configuration().obsidian_vaults).expanduser(): | ||
if vaults.exists() and vaults.is_dir(): | ||
for_widget.post_message(SetLocalViewRoot(vaults.resolve())) | ||
return True | ||
return False | ||
|
||
|
||
### obsidian.py ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters