mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 21:21:15 -03:00
Change funced script to default to using $EDITOR if set, and to allow -e to specify a particular editor (with fish meaning the builtin editor)
This commit is contained in:
@@ -1,26 +1,31 @@
|
|||||||
function funced --description 'Edit function definition'
|
function funced --description 'Edit function definition'
|
||||||
set -l external
|
set -l external ''
|
||||||
if test (count $argv) = 2
|
# Default to editing with EDITOR if set
|
||||||
for i in (seq 2)
|
if set -q EDITOR
|
||||||
switch $argv[$i]
|
set external $EDITOR
|
||||||
case -e --editor
|
|
||||||
if set -q EDITOR
|
|
||||||
set external $EDITOR
|
|
||||||
end
|
|
||||||
|
|
||||||
if not type -f "$external" >/dev/null
|
|
||||||
for e in edit emacs vim joe mcedit nano pico vi
|
|
||||||
if type -f $e >/dev/null
|
|
||||||
set external $e
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
set -e argv[$i]
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Allow overriding the editor with a -e flag
|
||||||
|
if test (count $argv) -eq 3
|
||||||
|
if contains -- $argv[1] -e --editor
|
||||||
|
set external $argv[2]
|
||||||
|
set -e argv[2]
|
||||||
|
set -e argv[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Let an editor of "fish" mean to use the default editor
|
||||||
|
if test "$external" = fish
|
||||||
|
set -e external
|
||||||
|
end
|
||||||
|
|
||||||
|
# Make sure any external editor exists
|
||||||
|
if set -q external
|
||||||
|
if not type -f "$external" >/dev/null
|
||||||
|
set -e external
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if test (count $argv) = 1
|
if test (count $argv) = 1
|
||||||
switch $argv
|
switch $argv
|
||||||
|
|
||||||
@@ -37,17 +42,19 @@ function funced --description 'Edit function definition'
|
|||||||
set -l tmp
|
set -l tmp
|
||||||
|
|
||||||
if set -q external[1]
|
if set -q external[1]
|
||||||
set -l tmpname (mktemp --suffix=.fish)
|
# Generate a temporary filename.
|
||||||
|
# mktemp has a different interface on different OSes,
|
||||||
|
# or may not exist at all; thus we fake one up from our pid
|
||||||
|
set -l tmpname (printf "$TMPDIR/fish_funced_%d.fish" %self)
|
||||||
|
|
||||||
if functions -q $argv
|
if functions -q $argv
|
||||||
functions $argv > $tmpname
|
functions $argv > $tmpname
|
||||||
else
|
else
|
||||||
echo "function $argv
|
echo function $argv\n\nend > $tmpname
|
||||||
end
|
end
|
||||||
" > $tmpname
|
if eval $external $tmpname
|
||||||
|
. $tmpname
|
||||||
end
|
end
|
||||||
eval $external $tmpname
|
|
||||||
. $tmpname
|
|
||||||
set -l stat $status
|
set -l stat $status
|
||||||
rm $tmpname >/dev/null
|
rm $tmpname >/dev/null
|
||||||
return $stat
|
return $stat
|
||||||
|
|||||||
Reference in New Issue
Block a user