From fe339e0379b687968ade7b40b534364dbef8c81f Mon Sep 17 00:00:00 2001 From: Tomas Rivera <137088692+Totorile1@users.noreply.github.com> Date: Sat, 28 Mar 2026 11:31:16 +0100 Subject: [PATCH] added a fzf selector for Obsidian vaults --- hosts/laptop/home.nix | 1 + modules/home-manager/hyprland.nix | 3 ++ modules/scripts/obsidianprofiles.nix | 46 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 modules/scripts/obsidianprofiles.nix diff --git a/hosts/laptop/home.nix b/hosts/laptop/home.nix index 743b238..a2f4230 100755 --- a/hosts/laptop/home.nix +++ b/hosts/laptop/home.nix @@ -79,6 +79,7 @@ (pkgs.callPackage ../../modules/scripts/man.nix {}) (pkgs.callPackage ../../modules/scripts/trimmer.nix {}) (pkgs.callPackage ../../modules/scripts/obsidianbackup.nix {}) # periodically syncs obsidian's note to kdrive + (pkgs.callPackage ../../modules/scripts/obsidianprofiles.nix {}) # fzf vault selector (pkgs.callPackage ../../modules/scripts/QSsysinfo.nix {}) (pkgs.callPackage ../../modules/scripts/QSnotifycache.nix {}) (pkgs.callPackage ../../modules/scripts/QSnotifyhistory.nix {}) diff --git a/modules/home-manager/hyprland.nix b/modules/home-manager/hyprland.nix index c4485c2..25f8ac9 100644 --- a/modules/home-manager/hyprland.nix +++ b/modules/home-manager/hyprland.nix @@ -19,6 +19,7 @@ in { "$mod" = "SUPER"; "$term" = "kitty"; "$editor" = "nvim"; + "$notes" = "kitty --class \"custom-obsidianvaults\" --name \"Select Obsidian vault\" --hold custom-obsidianvaults"; "$file" = "nautilus"; "$browser" = "kitty --class \"custom-librewolfprofiles\" --name \"Select LibreWolf profile\" --hold custom-librewolfprofiles"; # ▄▀█ █▄░█ █ █▀▄▀█ ▄▀█ ▀█▀ █ █▀█ █▄░█ @@ -127,6 +128,7 @@ in { "$mod, T, exec, $term" "$mod, E, exec, $file" "$mod, F, exec, $browser" + "$mod, N, exec, $notes" "$mod+Shift, A, exec, rofi -show drun" "$mod, Q, exec, custom-dontkillsteam" #"Ctrl+Alt, W, exec, pkill waybar || waybar" @@ -414,6 +416,7 @@ in { "float on, match:class ^(vlc)$" "float on, match:class ^(eog)$" "float on, size 400 175, match:class ^(custom-librewolfprofiles)$" + "float on, size 400 175, match:class ^(custom-obsidianvaults)$" "float on, size 600 600, match:initial_class ^(custom-pomodoro)$" "float on, size 1500 800, match:initial_class ^(custom-bottom)$" "border_size 2, match:float 0, match:workspace w[tv1]" diff --git a/modules/scripts/obsidianprofiles.nix b/modules/scripts/obsidianprofiles.nix new file mode 100644 index 0000000..44fc7fb --- /dev/null +++ b/modules/scripts/obsidianprofiles.nix @@ -0,0 +1,46 @@ +{ + writeShellApplication, + zsh, + fzf, + ripgrep, + ... +}: + +writeShellApplication { + name = "custom-obsidianvaults"; + runtimeInputs = [ + zsh + fzf + ripgrep + ]; + text = '' + # Path to your obsidian.nix + obsidian_nix="$HOME/nixos/modules/home-manager/obsidian.nix" + + # Extract vault names without line numbers and colors + mapfile -t vaults < <(rg -N --color=never -Po 'vaults\.\K[[:alnum:]_]+' "$obsidian_nix") + + # Let user select a vault with fzf + selected=$(printf "%s\n" "''${vaults[@]}" \ + | fzf --height 6 --reverse --prompt="Select Obsidian vault:") + + # Exit if user cancels + [[ -z "$selected" ]] && exit 0 + + # Remove any stray ANSI codes (optional) + selected=$(echo "$selected" | sed -r 's/\x1B\[[0-9;]*[mK]//g') + + # Find the target path of the selected vault + vault_path=$(rg -N --color=never -A2 "vaults.$selected" "$obsidian_nix" \ + | rg 'target =' | sed -E 's/.*"([^"]+)".*/\1/') + + # Expand ~ if present + vault_path="''${vault_path/#\~/$HOME}" + + # Launch Obsidian with the selected vault using URI + [[ -n "$vault_path" ]] && setsid xdg-open "obsidian://open?vault=$selected" >/dev/null 2>&1 & + # Exit the kitty terminal after selection + pkill -f "kitty.*Select Obsidian vault" + exit + ''; +}