mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
Pass cursor position to edit_command_buffer for some editors
Fixes #6138 Naturally this does not work for many other editors/aliases, but it's still nice that we can make it work for some common editors without requiring any configuration. Of course this approach is not terribly flexible; but it's alwyas possible to just wrap edit_command_buffer and set an EDITOR that knows about the cursor position. It doesn't feel important enough to add a configuration option.
This commit is contained in:
parent
27e88adcd5
commit
87728c4d0d
1 changed files with 27 additions and 1 deletions
|
@ -29,8 +29,34 @@ function edit_command_buffer --description 'Edit the command buffer in an extern
|
|||
end
|
||||
|
||||
commandline -b >$f
|
||||
set -l offset (commandline --cursor)
|
||||
# compute cursor line/column
|
||||
set -l lines (commandline)\n
|
||||
set -l line 1
|
||||
while test $offset -ge (string length $lines[1])
|
||||
set offset (math $offset - (string length $lines[1]))
|
||||
set line (math $line + 1)
|
||||
set -e lines[1]
|
||||
end
|
||||
set col (math $offset + 1)
|
||||
|
||||
set -l basename (string match -r '[^/]*$' -- $editor[1])
|
||||
if contains $basename vi vim nvim
|
||||
set -a editor +$line +"norm $col|" $f
|
||||
else if contains $basename emacs emacsclient gedit kak
|
||||
set -a editor +$line:$col $f
|
||||
else if contains $basename nano
|
||||
set -a editor +$line,$col $f
|
||||
else if contains $basename joe ee
|
||||
set -a editor +$line $f
|
||||
else if contains $basename code code-oss
|
||||
set -a editor --goto $f:$line:$col
|
||||
else
|
||||
set -a editor $f
|
||||
end
|
||||
|
||||
__fish_disable_bracketed_paste
|
||||
$editor $f
|
||||
$editor
|
||||
set -l editor_status $status
|
||||
__fish_enable_bracketed_paste
|
||||
|
||||
|
|
Loading…
Reference in a new issue