From 8ec900a1422cbbc38b8e3d56f2da620a4ec2ed40 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Thu, 23 Oct 2025 09:52:30 +0200 Subject: [PATCH] add @fingers-editor option --- src/fingers/action_runner.cr | 37 +++++++++++++++++++---------- src/fingers/commands/load_config.cr | 2 ++ src/fingers/config.cr | 4 +++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/fingers/action_runner.cr b/src/fingers/action_runner.cr index 9040fad..a3961aa 100644 --- a/src/fingers/action_runner.cr +++ b/src/fingers/action_runner.cr @@ -4,6 +4,8 @@ module Fingers class ActionRunner @final_shell_command : String | Nil + EDITORS = %w(nvim vim vi emacs nano) + def initialize( @modifier : String, @match : String, @@ -79,11 +81,20 @@ module Fingers end def edit + if editor.empty? || !exec_exists?(editor) + tmux.display_message("[tmux-fingers] Could not find editor#{editor.presence && ": #{editor}"}", 3000) + return + end + "tmux display-popup -w 80% -h 80% -E \"#{editor} #{expanded_match}\"" end def editor - "nvim" + return Fingers.config.editor if Fingers.config.editor.presence + + EDITORS.find do |editor| + Process.find_executable(editor) + end || "" end def jump @@ -131,37 +142,37 @@ module Fingers def system_copy_command return nil unless Fingers.config.use_system_clipboard - @system_copy_command ||= if program_exists?("pbcopy") - if program_exists?("reattach-to-user-namespace") + @system_copy_command ||= if exec_exists?("pbcopy") + if exec_exists?("reattach-to-user-namespace") "reattach-to-user-namespace" else "pbcopy" end - elsif program_exists?("clip.exe") + elsif exec_exists?("clip.exe") "cat | clip.exe" - elsif program_exists?("wl-copy") + elsif exec_exists?("wl-copy") "wl-copy" - elsif program_exists?("xclip") + elsif exec_exists?("xclip") "xclip -selection clipboard" - elsif program_exists?("xsel") + elsif exec_exists?("xsel") "xsel -i --clipboard" - elsif program_exists?("putclip") + elsif exec_exists?("putclip") "putclip" end end def system_open_command - @system_open_command ||= if program_exists?("cygstart") + @system_open_command ||= if exec_exists?("cygstart") "xargs cygstart" - elsif program_exists?("xdg-open") + elsif exec_exists?("xdg-open") "xargs xdg-open" - elsif program_exists?("open") + elsif exec_exists?("open") "xargs open" end end - def program_exists?(program) - Process.find_executable(program) + def exec_exists?(path : String) + Process.find_executable(path) end def tmux diff --git a/src/fingers/commands/load_config.cr b/src/fingers/commands/load_config.cr index e22ca7d..d8ac405 100644 --- a/src/fingers/commands/load_config.cr +++ b/src/fingers/commands/load_config.cr @@ -77,6 +77,8 @@ class Fingers::Commands::LoadConfig < Cling::Command config.show_copied_notification = value when "enabled_builtin_patterns" config.enabled_builtin_patterns = value + when "editor" + config.editor = value end if option.match(/^pattern/) && !value.empty? diff --git a/src/fingers/config.cr b/src/fingers/config.cr index 82b43b9..a536bc9 100644 --- a/src/fingers/config.cr +++ b/src/fingers/config.cr @@ -24,6 +24,7 @@ module Fingers property tmux_version : String property show_copied_notification : String property enabled_builtin_patterns : String + property editor : String FORMAT_PRINTER = TmuxStylePrinter.new @@ -84,7 +85,8 @@ module Fingers @tmux_version = "3.1", @show_copied_notification = "0", @enabled_builtin_patterns = "all", - @benchmark_mode = "0" + @benchmark_mode = "0", + @editor = "" ) end