diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2012-06-29 18:35:26 -0700 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2012-06-29 18:35:26 -0700 |
commit | a8bae31939b47363bfc07af837562247e6a9323f (patch) | |
tree | 8cbc873dfa904fdd9c91a32da00cb39cda78e817 /share | |
parent | faea588fb8e216ef504e2f0bb3dbfb88f1d4489b (diff) |
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)
Diffstat (limited to 'share')
-rw-r--r-- | share/functions/funced.fish | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/share/functions/funced.fish b/share/functions/funced.fish index 29d2f65f..985cc4fc 100644 --- a/share/functions/funced.fish +++ b/share/functions/funced.fish @@ -1,26 +1,31 @@ function funced --description 'Edit function definition' - set -l external - if test (count $argv) = 2 - for i in (seq 2) - switch $argv[$i] - case -e --editor - if set -q EDITOR - set external $EDITOR - end + set -l external '' + # Default to editing with EDITOR if set + 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 + # 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 switch $argv @@ -37,17 +42,19 @@ function funced --description 'Edit function definition' set -l tmp 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 functions $argv > $tmpname else - echo "function $argv -end -" > $tmpname + echo function $argv\n\nend > $tmpname + end + if eval $external $tmpname + . $tmpname end - eval $external $tmpname - . $tmpname set -l stat $status rm $tmpname >/dev/null return $stat |