From edaf011ab1e4ae4fe4b7b0c66a23418c80096d8c Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Thu, 10 Oct 2024 05:12:10 +0200 Subject: [PATCH] Try to use the fish_indent that corresponds to the fish binary Users may install two versions of fish and configure their terminal to run the one that is second in $PATH. This is not really what I'd do but it seems reasonable. We should not need $PATH for this. Fixes #10770 --- share/functions/__fish_indent.fish | 8 ++++++++ share/functions/edit_command_buffer.fish | 4 ++-- share/functions/fish_clipboard_copy.fish | 4 ++-- share/functions/funced.fish | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 share/functions/__fish_indent.fish diff --git a/share/functions/__fish_indent.fish b/share/functions/__fish_indent.fish new file mode 100644 index 000000000..988770ad4 --- /dev/null +++ b/share/functions/__fish_indent.fish @@ -0,0 +1,8 @@ +function __fish_indent + set -l dir "$(path dirname -- (status fish-path 2>/dev/null))" + if command -v $dir/fish_indent >/dev/null + $dir/fish_indent $argv + else + fish_indent $argv + end +end diff --git a/share/functions/edit_command_buffer.fish b/share/functions/edit_command_buffer.fish index 11f8e2e2e..31bfd9429 100644 --- a/share/functions/edit_command_buffer.fish +++ b/share/functions/edit_command_buffer.fish @@ -18,7 +18,7 @@ function edit_command_buffer --description 'Edit the command buffer in an extern set -l editor (__fish_anyeditor) or return 1 - set -l indented_lines (commandline -b | fish_indent --only-indent) + set -l indented_lines (commandline -b | __fish_indent --only-indent) string join -- \n $indented_lines >$f set -l offset (commandline --cursor) # compute cursor line/column @@ -91,7 +91,7 @@ function edit_command_buffer --description 'Edit the command buffer in an extern $editor set -l raw_lines (command cat $f) - set -l unindented_lines (string join -- \n $raw_lines | fish_indent --only-unindent) + set -l unindented_lines (string join -- \n $raw_lines | __fish_indent --only-unindent) # Here we're checking the exit status of the editor. if test $status -eq 0 -a -s $f diff --git a/share/functions/fish_clipboard_copy.fish b/share/functions/fish_clipboard_copy.fish index 74985c48a..50964d384 100644 --- a/share/functions/fish_clipboard_copy.fish +++ b/share/functions/fish_clipboard_copy.fish @@ -3,8 +3,8 @@ function fish_clipboard_copy if isatty stdin # Copy the current selection, or the entire commandline if that is empty. # Don't use `string collect -N` here - `commandline` adds a newline. - set cmdline (commandline --current-selection | fish_indent --only-indent | string collect) - test -n "$cmdline"; or set cmdline (commandline | fish_indent --only-indent | string collect) + set cmdline (commandline --current-selection | __fish_indent --only-indent | string collect) + test -n "$cmdline"; or set cmdline (commandline | __fish_indent --only-indent | string collect) else # Read from stdin while read -lz line diff --git a/share/functions/funced.fish b/share/functions/funced.fish index 5e2be69f8..2a38d2420 100644 --- a/share/functions/funced.fish +++ b/share/functions/funced.fish @@ -47,12 +47,12 @@ function funced --description 'Edit function definition' if test "$editor" = fish if functions -q -- $funcname - functions --no-details -- $funcname | fish_indent --only-unindent | fish_indent --no-indent | read -z init + functions --no-details -- $funcname | __fish_indent --only-unindent | __fish_indent --no-indent | read -z init end set -l prompt 'printf "%s%s%s> " (set_color green) '$funcname' (set_color normal)' if read -p $prompt -c "$init" --shell cmd - echo -n $cmd | fish_indent --only-unindent | read -lz cmd + echo -n $cmd | __fish_indent --only-unindent | read -lz cmd eval "$cmd" end if set -q _flag_save