obsave
obsave copied to clipboard
A cli utility to enable piping content into an Obsidian vault, adding frontmatter on the way.
obsave
obsave is a command-line utility that allows you to pipe text content into an Obsidian vault, adding YAML front matter in the process. It offers features like front matter customization, debug mode, and options to control how existing files are handled.
Changelog
Latest Changes
- Enhanced debug logging with detailed configuration and operation reporting
- Added extended help system:
-hshows concise usage information--helpdisplays detailed help with examples
- Added short form options:
-nfor--name-tfor--tags-pfor--properties-vfor--verbose-obfor--vault-cfor--config
- Improved configuration handling:
- Changed config from positional argument to flag option (
-cor--config) - Implemented clear configuration precedence
- Better handling of default and specified config files
- Changed config from positional argument to flag option (
Features
- Front Matter Generation: Automatically adds YAML front matter to your notes, including fields such as
title,tags, and customproperties. - Custom Properties: Add custom key-value pairs to the front matter.
- Multiple Configuration Files: Support for multiple YAML configuration files, allowing for different setups for various projects or use cases.
- Flexible Tag and Property Handling: Options to replace, add, or merge tags and properties.
- Overwrite Modes: Control how to handle existing files.
- Dry Run Mode: Simulate operations without writing files.
- Debug Mode: Enable detailed logging.
- Verbose Mode: Print the full path of saved files.
[!IMPORTANT]
Changelog
- 04-Feb-2025: Added
--passthroughoptions to allow saving and pipeing to stdout- 19-Oct-2024: Added
--verboseoption to output final filename and path- 17-Oct-2024:
- Switched to YAML for configuration
- Implemented separate configuration files
- 16-Oct-2024:
- Implemented
--debugoption for verbose output- Added
--dry-runoption and support for custom properties- 15-Oct-2024: Initial commit of Obsave project
Installation
To install obsave, you need to have Go installed on your machine. You can install the utility with:
go install github.com/mattjoyce/obsave@latest
This will install the utility to your $GOPATH/bin directory.
Command Line Options
Core Options
-n, --name: Note name/title (required if not in config)-ob, --vault: Path to Obsidian vault (required if not in config)-t, --tags: Comma-separated list of tags-p, --properties: Custom frontmatter properties (format: key=value;key2=value2)
Configuration
-c, --config: Specify a config file to use (default: ~/.config/obsave/config)
Control Options
--overwrite-mode: How to handle existing files ("overwrite", "serialize", or "fail")--tags-handling: How to handle tags ("replace", "add", or "merge")--properties-handling: How to handle properties ("replace", "add", or "merge")
Output Control
-v, --verbose: Print the full path of the saved file--debug: Enable detailed debug logging--dry-run: Simulate the operation without writing files
Help and Documentation
-h: Display concise usage information--help: Display detailed help with examples
Usage
Basic Example
You can pipe text content into obsave and save it to your Obsidian vault:
echo "This is my note content." | obsave -n "MyNote" -t "project,example" -p "author=John Doe;status=Draft" -ob "~/Documents/ObsidianVault"
Additional Options
-
Debug Mode: Enable detailed logging to troubleshoot or inspect the internal operations of
obsave:echo "Test content" | obsave -n "DebugTest" -ob "~/vault" --debug -
Dry Run: Use the
--dry-runoption to simulate the operation without writing the file:echo "Test content" | obsave -n "TestNote" -ob "~/vault" --dry-run -
Overwrite Mode: Specify how to handle existing files:
echo "New content" | obsave -n "ExistingNote" -ob "~/vault" --overwrite-mode "overwrite"
Configuration
Configuration files use YAML format and are stored in ~/.config/obsave/. The configuration system follows a clear precedence order:
- Start with empty configuration
- Load default config file (~/.config/obsave/config) if it exists
- Load specified config file (if -c/--config provided)
- Apply command line options (these always override config file settings)
[!IMPORTANT] Windows users should use
%USERPROFILE%instead of~/for the config directory. Which might beC:\Users\<username>\
Required Settings
The following settings must be provided either through a config file or command line options:
name(via -n/--name)vault_path(via -ob/--vault)
Example Configuration File
vault_path: "~/Documents/ObsidianVault"
overwrite_mode: "fail"
tags:
- default
- obsave
properties:
tool: obsave
version: "1.0"
debug: false
dry_run: false
tags_handling: "merge"
properties_handling: "merge"
name: "Default Note Name" # optional
verbose: false
Configuration Scenarios
-
No Config File:
- Must provide --name and --vault options
- Other options use program defaults
echo "Content" | obsave -n "Note" -ob "~/vault" -
Default Config Exists:
- Settings from ~/.config/obsave/config are used
- Can override any setting via command line
# Use config but override name echo "Content" | obsave -n "Custom Name" -
Specified Config:
- Loads specified config instead of default
- Can still override via command line
echo "Content" | obsave -c custom-config -n "Override Name"
Tag and Property Handling Options
obsave provides flexible options for managing tags and properties. These options control how the command-line inputs interact with existing configuration or content.
Tags Handling
Use the --tags-handling option to specify how tags should be managed. Available modes are:
-
Replace: Completely replaces existing tags with the ones provided in the CLI.
echo "Content" | obsave -n "TaggedNote" -t "example,notes,project" --tags-handling "replace"- If config had:
["existing", "tags"] - CLI tags:
"example,notes,project" - Result:
["example", "notes", "project"]
- If config had:
-
Add: Adds new tags from the CLI, avoiding duplicates.
echo "Content" | obsave -n "TaggedNote" -t "example,notes,project" --tags-handling "add"- If config had:
["project", "important"] - CLI tags:
"example,notes,project" - Result:
["project", "important", "example", "notes"]
- If config had:
-
Merge: Adds all tags from the CLI, allowing duplicates.
echo "Content" | obsave -n "TaggedNote" -t "example,notes,project" --tags-handling "merge"- If config had:
["project", "important"] - CLI tags:
"example,notes,project" - Result:
["project", "important", "example", "notes", "project"]
- If config had:
Properties Handling
Use the --properties-handling option to specify how properties should be managed. Available modes are:
-
Replace: Completely replaces existing properties with the ones provided in the CLI.
echo "Content" | obsave -n "PropertyNote" -p "status=Review;author=John" --properties-handling "replace"- If config had:
{"category": "Work", "priority": "High"} - CLI properties:
"status=Review;author=John" - Result:
{"status": "Review", "author": "John"}
- If config had:
-
Add: Adds new properties from the CLI, without overwriting existing ones.
echo "Content" | obsave -n "PropertyNote" -p "status=Review;author=John" --properties-handling "add"- If config had:
{"category": "Work", "priority": "High"} - CLI properties:
"status=Review;author=John" - Result:
{"category": "Work", "priority": "High", "status": "Review", "author": "John"}
- If config had:
-
Merge: Adds all properties from the CLI, overwriting existing ones with the same key.
echo "Content" | obsave -n "PropertyNote" -p "status=Review;priority=Medium" --properties-handling "merge"- If config had:
{"category": "Work", "priority": "High"} - CLI properties:
"status=Review;priority=Medium" - Result:
{"category": "Work", "priority": "Medium", "status": "Review"}
- If config had:
Cloning and Building from Source
Prerequisites
Make sure you have Go installed on your system. You can install Go from here.
Steps to Clone and Build:
-
Clone the Repository:
git clone https://github.com/mattjoyce/obsave.git cd obsave -
Build the Project: To build the project into an executable binary, run:
go build -o obsaveThis will generate the
obsaveexecutable in the current directory. -
Run the Utility: You can now run
obsavedirectly:./obsave -n "TestNote" -t "example" -ob "~/Documents/ObsidianVault" -
Install Locally (Optional): If you want to install
obsaveto your system's$GOPATH/bindirectory for global usage, run:go installAfter installation, you can use
obsavefrom anywhere in your terminal:obsave -n "NewNote" -ob "~/ObsidianVault"