mirror of
https://github.com/tomasriveral/nixos.git
synced 2026-08-12 10:30:44 +02:00
added a fzf selector for Obsidian vaults
This commit is contained in:
@@ -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]"
|
||||
|
||||
@@ -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
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user