2016-12-07 03:24:08 +00:00
|
|
|
function edit_command_buffer --description 'Edit the command buffer in an external editor'
|
|
|
|
set -l f (mktemp)
|
|
|
|
if set -q f[1]
|
|
|
|
mv $f $f.fish
|
|
|
|
set f $f.fish
|
|
|
|
else
|
|
|
|
# We should never execute this block but better to be paranoid.
|
|
|
|
if set -q TMPDIR
|
2018-03-15 23:31:15 +00:00
|
|
|
set f $TMPDIR/fish.$fish_pid.fish
|
2016-12-07 03:24:08 +00:00
|
|
|
else
|
2018-03-15 23:31:15 +00:00
|
|
|
set f /tmp/fish.$fish_pid.fish
|
2016-12-07 03:24:08 +00:00
|
|
|
end
|
|
|
|
touch $f
|
|
|
|
or return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
# Edit the command line with the users preferred editor or vim or emacs.
|
|
|
|
commandline -b >$f
|
|
|
|
if set -q VISUAL
|
2017-06-05 18:32:06 +00:00
|
|
|
__fish_disable_bracketed_paste
|
2019-02-07 08:47:24 +00:00
|
|
|
eval $VISUAL $f
|
2017-06-05 18:32:06 +00:00
|
|
|
__fish_enable_bracketed_paste
|
2016-12-07 03:24:08 +00:00
|
|
|
else if set -q EDITOR
|
2017-06-05 18:32:06 +00:00
|
|
|
__fish_disable_bracketed_paste
|
2019-02-07 08:47:24 +00:00
|
|
|
eval $EDITOR $f
|
2017-06-05 18:32:06 +00:00
|
|
|
__fish_enable_bracketed_paste
|
2016-12-07 03:24:08 +00:00
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo (_ 'External editor requested but $VISUAL or $EDITOR not set.')
|
|
|
|
echo (_ 'Please set VISUAL or EDITOR to your preferred editor.')
|
|
|
|
commandline -f repaint
|
|
|
|
command rm $f
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
# Here we're checking the exit status of the editor.
|
|
|
|
if test $status -eq 0 -a -s $f
|
|
|
|
# Set the command to the output of the edited command and move the cursor to the
|
|
|
|
# end of the edited command.
|
2017-01-22 04:23:06 +00:00
|
|
|
commandline -r -- (cat $f)
|
2016-12-07 03:24:08 +00:00
|
|
|
commandline -C 999999
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo (_ "Ignoring the output of your editor since its exit status was non-zero")
|
|
|
|
echo (_ "or the file was empty")
|
|
|
|
end
|
|
|
|
command rm $f
|
2018-10-25 15:34:01 +00:00
|
|
|
# We've probably opened something that messed with the screen.
|
|
|
|
# A repaint seems in order.
|
|
|
|
commandline -f repaint
|
2016-12-07 03:24:08 +00:00
|
|
|
end
|