[metadata] name = "obsidian" description = """ Obsidian vaults under ~/Documents/Obsidian, most recently modified first. Enter opens the vault in Obsidian; vaults Obsidian has never opened are registered in obsidian.json first. """ requirements = ["fd", "jq", "eza", "obsidian", "xdg-open", "mtime-sort"] # Entries are "\t": the name is what you fuzzy-match, the # path is what the actions use. [source] command = ''' v=$HOME/Documents/Obsidian fd -H -t d -d 3 '^\.obsidian$' "$v" -x dirname | awk -v r="$v/" '{ print substr($0, length(r) + 1) "\t" $0 }' | mtime-sort ''' shell = "bash" display = "{split:\\t:0}" output = "{split:\\t:1}" [preview] command = "eza --tree --level 2 --color=always '{split:\\t:1}' 2>/dev/null || ls -la '{split:\\t:1}'" shell = "bash" # ctrl-e (edit) is bound globally in config.toml. [keybindings] enter = "actions:open" # obsidian://open?path= only resolves vaults listed in obsidian.json, and # Obsidian reads that file once at startup and rewrites it from memory. An # unlisted vault is therefore added only while Obsidian is closed; while it # runs, the vault switcher opens instead. [actions.open] description = "Open the vault in Obsidian" command = ''' d='{split:\t:1}' cfg=${XDG_CONFIG_HOME:-$HOME/.config}/obsidian/obsidian.json uri="obsidian://open?path=$(jq -rn --arg p "$d" '$p | @uri')" if ! jq -e --arg p "$d" 'any(.vaults[]?; .path == $p)' "$cfg" >/dev/null 2>&1; then # [o]: keep pgrep from matching this script's own command line. if pgrep -f '[o]bsidian/app.asar' >/dev/null; then msg="Vault not registered and Obsidian is running: use 'Open folder as vault' for $d" echo "$msg" >&2 notify-send Obsidian "$msg" 2>/dev/null uri="obsidian://choose-vault" else mkdir -p "${cfg%/*}" [ -s "$cfg" ] || echo '{}' >"$cfg" tmp=$(mktemp "$cfg.XXXXXX") || exit 1 jq --arg id "$(od -An -N8 -tx1 /dev/urandom | tr -d ' \n')" --arg p "$d" \ --argjson ts "$(date +%s%3N)" '.vaults[$id] = {path: $p, ts: $ts}' \ "$cfg" >"$tmp" && mv "$tmp" "$cfg" || rm -f "$tmp" fi fi setsid -f xdg-open "$uri" >/dev/null 2>&1 ''' shell = "bash" mode = "execute" [actions.edit] description = "Open the vault in nvim" command = "cd '{split:\\t:1}' && nvim . /dev/tty" shell = "bash" mode = "execute"