Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Commands): Merge all commands into one :Obsidian command #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added `opts.follow_img_func` option for customizing how to handle image paths.
- Added better handling for undefined template fields, which will now be prompted for.
- Added support for the [`snacks.picker`](https://github.com/folke/snacks.nvim/blob/main/docs/picker.md) picker
- Added support for the [`snacks.picker`](https://github.com/folke/snacks.nvim/blob/main/docs/picker.md) picker.
- Added support for the [`blink.cmp`](https://github.com/Saghen/blink.cmp) completion plugin.
- Added `opts.legacy_commands` option which enables the old commands.

### Changed

- Renamed `opts.image_name_func` to `opts.attachments.img_name_func`.
- Default to not activate ui render when `render-markdown.nvim` or `markview.nvim` is present
- Default to not activate ui render when `render-markdown.nvim` or `markview.nvim` is present.
- Moved all commands into one `:Obsidian` command.

### Fixed

Expand Down
66 changes: 34 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ If you're new to Obsidian we highly recommend watching [this excellent YouTube v
_Keep in mind this plugin is not meant to replace Obsidian, but to complement it._ The Obsidian app is very powerful in its own way; it comes with a mobile app and has a lot of functionality that's not feasible to implement in Neovim, such as the graph explorer view. That said, this plugin stands on its own as well. You don't necessarily need to use it alongside the Obsidian app.

## About the fork

The original project has not been actively maintained for quite a while and with the ever-changing Neovim ecosystem, new widely used tools such as [blink.cmp](https://github.com/Saghen/blink.cmp) or [snacks.picker](https://github.com/folke/snacks.nvim/blob/main/docs/picker.md) were not supported.
With bugs, issues and pull requests piling up, people from the community decided to fork and maintain the project.
The fork aims to stay close to the original, but fix bugs, include and merge useful improvements, and ensure long term robustness.
Expand Down Expand Up @@ -47,54 +48,54 @@ The fork aims to stay close to the original, but fix bugs, include and merge use

### Commands

- `:ObsidianOpen [QUERY]` to open a note in the Obsidian app.
- `:Obsidian open [QUERY]` to open a note in the Obsidian app.
This command has one optional argument: a query used to resolve the note to open by ID, path, or alias. If not given, the note corresponding to the current buffer is opened.

- `:ObsidianNew [TITLE]` to create a new note.
- `:Obsidian new [TITLE]` to create a new note.
This command has one optional argument: the title of the new note.

- `:ObsidianQuickSwitch` to quickly switch to (or open) another note in your vault, searching by its name using [ripgrep](https://github.com/BurntSushi/ripgrep) with your preferred picker (see [plugin dependencies](#plugin-dependencies) below).
- `:Obsidian quickswitch` to quickly switch to (or open) another note in your vault, searching by its name using [ripgrep](https://github.com/BurntSushi/ripgrep) with your preferred picker (see [plugin dependencies](#plugin-dependencies) below).

- `:ObsidianFollowLink [vsplit|hsplit]` to follow a note reference under the cursor, optionally opening it in a vertical or horizontal split.
- `:Obsidian followlink [vsplit|hsplit]` to follow a note reference under the cursor, optionally opening it in a vertical or horizontal split.

- `:ObsidianBacklinks` for getting a picker list of references to the current buffer.
- `:Obsidian backlinks` for getting a picker list of references to the current buffer.

- `:ObsidianTags [TAG ...]` for getting a picker list of all occurrences of the given tags.
- `:Obsidian tags [TAG ...]` for getting a picker list of all occurrences of the given tags.

- `:ObsidianToday [OFFSET]` to open/create a new daily note. This command also takes an optional offset in days, e.g. use `:ObsidianToday -1` to go to yesterday's note. Unlike `:ObsidianYesterday` and `:ObsidianTomorrow` this command does not differentiate between weekdays and weekends.
- `:Obsidian today [OFFSET]` to open/create a new daily note. This command also takes an optional offset in days, e.g. use `:Obsidian today -1` to go to yesterday's note. Unlike `:Obsidian yesterday` and `:Obsidian tomorrow` this command does not differentiate between weekdays and weekends.

- `:ObsidianYesterday` to open/create the daily note for the previous working day.
- `:Obsidian yesterday` to open/create the daily note for the previous working day.

- `:ObsidianTomorrow` to open/create the daily note for the next working day.
- `:Obsidian tomorrow` to open/create the daily note for the next working day.

- `:ObsidianDailies [OFFSET ...]` to open a picker list of daily notes. For example, `:ObsidianDailies -2 1` to list daily notes from 2 days ago until tomorrow.
- `:Obsidian dailies [OFFSET ...]` to open a picker list of daily notes. For example, `:Obsidian dailies -2 1` to list daily notes from 2 days ago until tomorrow.

- `:ObsidianTemplate [NAME]` to insert a template from the templates folder, selecting from a list using your preferred picker. See ["using templates"](#using-templates) for more information.
- `:Obsidian template [NAME]` to insert a template from the templates folder, selecting from a list using your preferred picker. See ["using templates"](#using-templates) for more information.

- `:ObsidianSearch [QUERY]` to search for (or create) notes in your vault using `ripgrep` with your preferred picker.
- `:Obsidian search [QUERY]` to search for (or create) notes in your vault using `ripgrep` with your preferred picker.

- `:ObsidianLink [QUERY]` to link an inline visual selection of text to a note.
- `:Obsidian link [QUERY]` to link an inline visual selection of text to a note.
This command has one optional argument: a query that will be used to resolve the note by ID, path, or alias. If not given, the selected text will be used as the query.

- `:ObsidianLinkNew [TITLE]` to create a new note and link it to an inline visual selection of text.
- `:Obsidian linknew [TITLE]` to create a new note and link it to an inline visual selection of text.
This command has one optional argument: the title of the new note. If not given, the selected text will be used as the title.

- `:ObsidianLinks` to collect all links within the current buffer into a picker window.
- `:Obsidian links` to collect all links within the current buffer into a picker window.

- `:ObsidianExtractNote [TITLE]` to extract the visually selected text into a new note and link to it.
- `:Obsidian extractnote [TITLE]` to extract the visually selected text into a new note and link to it.

- `:ObsidianWorkspace [NAME]` to switch to another workspace.
- `:Obsidian workspace [NAME]` to switch to another workspace.

- `:ObsidianPasteImg [IMGNAME]` to paste an image from the clipboard into the note at the cursor position by saving it to the vault and adding a markdown image link. You can configure the default folder to save images to with the `attachments.img_folder` option.
- `:Obsidian pasteimg [IMGNAME]` to paste an image from the clipboard into the note at the cursor position by saving it to the vault and adding a markdown image link. You can configure the default folder to save images to with the `attachments.img_folder` option.

- `:ObsidianRename [NEWNAME] [--dry-run]` to rename the note of the current buffer or reference under the cursor, updating all backlinks across the vault. Since this command is still relatively new and could potentially write a lot of changes to your vault, I highly recommend committing the current state of your vault (if you're using version control) before running it, or doing a dry-run first by appending "--dry-run" to the command, e.g. `:ObsidianRename new-id --dry-run`.
- `:Obsidian rename [NEWNAME] [--dry-run]` to rename the note of the current buffer or reference under the cursor, updating all backlinks across the vault. Since this command is still relatively new and could potentially write a lot of changes to your vault, I highly recommend committing the current state of your vault (if you're using version control) before running it, or doing a dry-run first by appending "--dry-run" to the command, e.g. `:Obsidian rename new-id --dry-run`.

- `:ObsidianToggleCheckbox` to cycle through checkbox options.
- `:Obsidian togglecheckbox` to cycle through checkbox options.

- `:ObsidianNewFromTemplate [TITLE]` to create a new note from a template in the templates folder. Selecting from a list using your preferred picker.
- `:Obsidian newfromtemplate [TITLE]` to create a new note from a template in the templates folder. Selecting from a list using your preferred picker.
This command has one optional argument: the title of the new note.

- `:ObsidianTOC` to load the table of contents of the current note into a picker list.
- `:Obsidian toc` to load the table of contents of the current note into a picker list.

### Demo

Expand All @@ -110,11 +111,11 @@ The fork aims to stay close to the original, but fix bugs, include and merge use

Specific operating systems also require additional dependencies in order to use all of obsidian.nvim's functionality:

- **Windows WSL** users need [`wsl-open`](https://gitlab.com/4U6U57/wsl-open) for the `:ObsidianOpen` command.
- **MacOS** users need [`pngpaste`](https://github.com/jcsalterego/pngpaste) (`brew install pngpaste`) for the `:ObsidianPasteImg` command.
- **Linux** users need xclip (X11) or wl-clipboard (Wayland) for the `:ObsidianPasteImg` command.
- **Windows WSL** users need [`wsl-open`](https://gitlab.com/4U6U57/wsl-open) for the `:Obsidian open` command.
- **MacOS** users need [`pngpaste`](https://github.com/jcsalterego/pngpaste) (`brew install pngpaste`) for the `:Obsidian pasteimg` command.
- **Linux** users need xclip (X11) or wl-clipboard (Wayland) for the `:Obsidian pasteimg` command.

Search functionality (e.g. via the `:ObsidianSearch` and `:ObsidianQuickSwitch` commands) also requires a picker such [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) (see [plugin dependencies](#plugin-dependencies) below).
Search functionality (e.g. via the `:Obsidian search` and `:Obsidian quickswitch` commands) also requires a picker such [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) (see [plugin dependencies](#plugin-dependencies) below).

### Install and configure

Expand Down Expand Up @@ -419,7 +420,7 @@ This is a complete list of all of the options that can be passed to `require("ob
substitutions = {},
},

-- Optional, by default when you use `:ObsidianFollowLink` on a link to an external
-- Optional, by default when you use `:Obsidian followlink` on a link to an external
-- URL it will be ignored but you can customize this behavior here.
---@param url string
follow_url_func = function(url)
Expand All @@ -430,7 +431,7 @@ This is a complete list of all of the options that can be passed to `require("ob
-- vim.ui.open(url) -- need Neovim 0.10.0+
end,

-- Optional, by default when you use `:ObsidianFollowLink` on a link to an image
-- Optional, by default when you use `:Obsidian followlink` on a link to an image
-- file it will be ignored but you can customize this behavior here.
---@param img string
follow_img_func = function(img)
Expand All @@ -443,7 +444,7 @@ This is a complete list of all of the options that can be passed to `require("ob
-- https://github.com/Vinzent03/obsidian-advanced-uri
use_advanced_uri = false,

-- Optional, set to true to force ':ObsidianOpen' to bring the app to the foreground.
-- Optional, set to true to force ':Obsidian open' to bring the app to the foreground.
open_app_foreground = false,

picker = {
Expand All @@ -467,7 +468,7 @@ This is a complete list of all of the options that can be passed to `require("ob

-- Optional, sort search results by "path", "modified", "accessed", or "created".
-- The recommend value is "modified" and `true` for `sort_reversed`, which means, for example,
-- that `:ObsidianQuickSwitch` will show the notes sorted by latest modified time
-- that `:Obsidian quickswitch` will show the notes sorted by latest modified time
sort_by = "modified",
sort_reversed = true,

Expand Down Expand Up @@ -554,12 +555,12 @@ This is a complete list of all of the options that can be passed to `require("ob

-- Specify how to handle attachments.
attachments = {
-- The default folder to place images in via `:ObsidianPasteImg`.
-- The default folder to place images in via `:Obsidian pasteimg`.
-- If this is a relative path it will be interpreted as relative to the vault root.
-- You can always override this per image by passing a full path to the command instead of just a filename.
img_folder = "assets/imgs", -- This is the default

-- Optional, customize the default name or prefix when pasting images via `:ObsidianPasteImg`.
-- Optional, customize the default name or prefix when pasting images via `:Obsidian pasteimg`.
---@return string
img_name_func = function()
-- Prefix image names with timestamp.
Expand Down Expand Up @@ -807,4 +808,5 @@ And keep in mind that to reset a configuration option to `nil` you'll have to us
Please read the [CONTRIBUTING](https://github.com/obsidian-nvim/obsidian.nvim/blob/main/.github/CONTRIBUTING.md) guide before submitting a pull request.

## Acknowledgement

We would like to thank [epwalsh](https://github.com/epwalsh) for creating this beautiful plugin. If you're feeling especially generous, [he still appreciates some coffee funds! ❤️](https://www.buymeacoffee.com/epwalsh).
48 changes: 24 additions & 24 deletions doc/obsidian.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,64 +76,64 @@ extmarks for references, tags, and check-boxes.

COMMANDS *obsidian-commands*

- `:ObsidianOpen [QUERY]` to open a note in the Obsidian app. This command has
- `:Obsidian open [QUERY]` to open a note in the Obsidian app. This command has
one optional argument: a query used to resolve the note to open by ID, path, or
alias. If not given, the note corresponding to the current buffer is opened.
- `:ObsidianNew [TITLE]` to create a new note. This command has one optional
- `:Obsidian new [TITLE]` to create a new note. This command has one optional
argument: the title of the new note.
- `:ObsidianQuickSwitch` to quickly switch to (or open) another note in your
- `:Obsidian quickswitch` to quickly switch to (or open) another note in your
vault, searching by its name using ripgrep
<https://github.com/BurntSushi/ripgrep> with your preferred picker (see
|obsidian-plugin-dependencies| below).
- `:ObsidianFollowLink [vsplit|hsplit]` to follow a note reference under the
- `:Obsidian followlink [vsplit|hsplit]` to follow a note reference under the
cursor, optionally opening it in a vertical or horizontal split.
- `:ObsidianBacklinks` for getting a picker list of references to the current
- `:Obsidian backlinks` for getting a picker list of references to the current
buffer.
- `:ObsidianTags [TAG ...]` for getting a picker list of all occurrences of the
- `:Obsidian tags [TAG ...]` for getting a picker list of all occurrences of the
given tags.
- `:ObsidianToday [OFFSET]` to open/create a new daily note. This command also
- `:Obsidian today [OFFSET]` to open/create a new daily note. This command also
takes an optional offset in days, e.g. use `:ObsidianToday -1` to go to
yesterday’s note. Unlike `:ObsidianYesterday` and `:ObsidianTomorrow` this
command does not differentiate between weekdays and weekends.
- `:ObsidianYesterday` to open/create the daily note for the previous working
- `:Obsidian yesterday` to open/create the daily note for the previous working
day.
- `:ObsidianTomorrow` to open/create the daily note for the next working day.
- `:ObsidianDailies [OFFSET ...]` to open a picker list of daily notes. For
- `:Obsidian tomorrow` to open/create the daily note for the next working day.
- `:Obsidian dailies [OFFSET ...]` to open a picker list of daily notes. For
example, `:ObsidianDailies -2 1` to list daily notes from 2 days ago until
tomorrow.
- `:ObsidianTemplate [NAME]` to insert a template from the templates folder,
- `:Obsidian template [NAME]` to insert a template from the templates folder,
selecting from a list using your preferred picker. See
|obsidian-"using-templates"| for more information.
- `:ObsidianSearch [QUERY]` to search for (or create) notes in your vault using
- `:Obsidian search [QUERY]` to search for (or create) notes in your vault using
`ripgrep` with your preferred picker.
- `:ObsidianLink [QUERY]` to link an inline visual selection of text to a note.
- `:Obsidian link [QUERY]` to link an inline visual selection of text to a note.
This command has one optional argument: a query that will be used to resolve
the note by ID, path, or alias. If not given, the selected text will be used as
the query.
- `:ObsidianLinkNew [TITLE]` to create a new note and link it to an inline visual
- `:Obsidian linknew [TITLE]` to create a new note and link it to an inline visual
selection of text. This command has one optional argument: the title of the new
note. If not given, the selected text will be used as the title.
- `:ObsidianLinks` to collect all links within the current buffer into a picker
- `:Obsidian links` to collect all links within the current buffer into a picker
window.
- `:ObsidianExtractNote [TITLE]` to extract the visually selected text into a new
- `:Obsidian extractnote [TITLE]` to extract the visually selected text into a new
note and link to it.
- `:ObsidianWorkspace [NAME]` to switch to another workspace.
- `:ObsidianPasteImg [IMGNAME]` to paste an image from the clipboard into the
- `:Obsidian workspace [NAME]` to switch to another workspace.
- `:Obsidian pasteimg [IMGNAME]` to paste an image from the clipboard into the
note at the cursor position by saving it to the vault and adding a markdown
image link. You can configure the default folder to save images to with the
`attachments.img_folder` option.
- `:ObsidianRename [NEWNAME] [--dry-run]` to rename the note of the current
- `:Obsidian rename [NEWNAME] [--dry-run]` to rename the note of the current
buffer or reference under the cursor, updating all backlinks across the vault.
Since this command is still relatively new and could potentially write a lot of
changes to your vault, I highly recommend committing the current state of your
vault (if you’re using version control) before running it, or doing a dry-run
first by appending "–dry-run" to the command, e.g. `:ObsidianRename new-id
--dry-run`.
- `:ObsidianToggleCheckbox` to cycle through checkbox options.
- `:ObsidianNewFromTemplate [TITLE]` to create a new note from a template in the
- `:Obsidian togglecheckbox` to cycle through checkbox options.
- `:Obsidian newfromtemplate [TITLE]` to create a new note from a template in the
templates folder. Selecting from a list using your preferred picker. This
command has one optional argument: the title of the new note.
- `:ObsidianTOC` to load the table of contents of the current note into a picker
- `:Obsidian toc` to load the table of contents of the current note into a picker
list.


Expand All @@ -160,8 +160,8 @@ all of obsidian.nvim’s functionality:
- **MacOS** users need `pngpaste` <https://github.com/jcsalterego/pngpaste> (`brew install pngpaste`) for the `:ObsidianPasteImg` command.
- **Linux** users need xclip (X11) or wl-clipboard (Wayland) for the `:ObsidianPasteImg` command.

Search functionality (e.g. via the `:ObsidianSearch` and
`:ObsidianQuickSwitch` commands) also requires a picker such telescope.nvim
Search functionality (e.g. via the `:Obsidian search` and
`:Obsidian quickswitch` commands) also requires a picker such telescope.nvim
<https://github.com/nvim-telescope/telescope.nvim> (see
|obsidian-plugin-dependencies| below).

Expand Down
2 changes: 1 addition & 1 deletion lua/obsidian/commands/dailies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ return function(client, data)
offset_start = offsets[1]
offset_end = offsets[2]
else
error ":ObsidianDailies expected at most 2 arguments"
error ":Obsidian dailies expected at most 2 arguments"
end
end

Expand Down
Loading