diff options
author | maxfl <gmaxfl@gmail.com> | 2012-06-27 07:37:48 +0400 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2012-06-29 16:42:34 -0700 |
commit | 85f19f9b8c74239d22bbe34cdf338598f89f41b6 (patch) | |
tree | 6ec3665a9eb2d2db6ea6d24157a7b84e684c91ee /share | |
parent | 40e4f49dbe483cef84edbea5e7a723e21c0f5e2e (diff) |
Add -e option to funced
New option -e or --editor allows to edit function inside external
editor, rather than in reader.
Diffstat (limited to 'share')
-rw-r--r-- | share/completions/funced.fish | 1 | ||||
-rw-r--r-- | share/functions/funced.fish | 47 |
2 files changed, 43 insertions, 5 deletions
diff --git a/share/completions/funced.fish b/share/completions/funced.fish index 2e9f66a4..2c2580d2 100644 --- a/share/completions/funced.fish +++ b/share/completions/funced.fish @@ -1 +1,2 @@ complete -c funced -xa "(functions -na)" --description "Save function" +complete -c funced -s e -l editor -d 'Open function in external editor' diff --git a/share/functions/funced.fish b/share/functions/funced.fish index 5bd54acd..13ee4438 100644 --- a/share/functions/funced.fish +++ b/share/functions/funced.fish @@ -1,5 +1,26 @@ +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 -function funced --description "Edit function definition" + if not type -f "$external" >/dev/null + for e in edit nano pico joe mcedit vim vi + if type -f $e >/dev/null + set external $e + break + end + end + end + set -e argv[$i] + break + end + end + end if test (count $argv) = 1 switch $argv @@ -15,15 +36,31 @@ function funced --description "Edit function definition" set -l init '' set -l tmp - # Shadow IFS here to avoid array splitting in command substitution - set -l IFS + if set -q external[1] + set -l tmpname (mktemp --suffix=.fish) + + if functions -q $argv + functions $argv > $tmpname + else + echo "function $argv +end +" > $tmpname + end + eval $external $tmpname + . $tmpname + set -l stat $status + rm $tmpname >/dev/null + return $stat + end + + set -l IFS if functions -q $argv - set init (functions $argv | fish_indent --no-indent) + # Shadow IFS here to avoid array splitting in command substitution + set init (functions $argv | fish_indent --no-indent) else set init function $argv\nend end - set -l prompt 'printf "%s%s%s> " (set_color green) '$argv' (set_color normal)' # Unshadow IFS since the fish_title breaks otherwise set -e IFS |