Skip to content

Instantly share code, notes, and snippets.

@morganrivers
Created May 26, 2026 18:55
Show Gist options
  • Select an option

  • Save morganrivers/13899ab692e85b02fded938a5b11deb4 to your computer and use it in GitHub Desktop.

Select an option

Save morganrivers/13899ab692e85b02fded938a5b11deb4 to your computer and use it in GitHub Desktop.
Open files in Obsidian from the terminal via obsidian-cli
#!/bin/bash
# oo — open files in Obsidian from the terminal
#
# Install:
# sudo cp oo /usr/local/bin/oo
# sudo chmod +x /usr/local/bin/oo
#
# Prerequisites — enable obsidian-cli in the Obsidian app:
# Settings > Community plugins > Browse > search "obsidian-cli" > Install > Enable
#
cli=/snap/obsidian/current/obsidian-cli
vault="$HOME/obsidian/notes"
# Expand any unresolved glob patterns in CWD
files=()
for arg in "$@"; do
if [[ "$arg" == *'*'* || "$arg" == *'?'* || "$arg" == *'['* ]]; then
expanded=($arg)
files+=("${expanded[@]}")
else
files+=("$arg")
fi
done
for f in "${files[@]}"; do
src="$(realpath "$f")"
target="$vault/$(basename "$f")"
[ "$(realpath "$target" 2>/dev/null)" != "$src" ] && ln -sfn "$src" "$target"
done
/snap/bin/obsidian --no-sandbox 2>/dev/null &
until "$cli" vault >/dev/null 2>&1; do
sleep 0.25
done
for f in "${files[@]}"; do
"$cli" tab:open "file=$(basename "${f}")" 2>/dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment