aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/funced.fish
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2007-04-23 04:55:39 +1000
committerGravatar axel <axel@liljencrantz.se>2007-04-23 04:55:39 +1000
commitdd48de068dcbdc3f96eb622baf2254b09301320f (patch)
tree1806d35962cd215f76d56a6f4ff2fb5cffd85c62 /share/functions/funced.fish
parentcb179c448bc9f2b984b1740307b916ec8f3eb9e1 (diff)
Add funced function, which works like vared, but with functions
darcs-hash:20070422185539-ac50b-9080fb745cec45609e7e29971b55b96e073806e6.gz
Diffstat (limited to 'share/functions/funced.fish')
-rw-r--r--share/functions/funced.fish39
1 files changed, 39 insertions, 0 deletions
diff --git a/share/functions/funced.fish b/share/functions/funced.fish
new file mode 100644
index 00000000..3e58548d
--- /dev/null
+++ b/share/functions/funced.fish
@@ -0,0 +1,39 @@
+
+function funced --description "Edit function definition"
+ if test (count $argv) = 1
+ switch $argv
+
+ case '-h' '--h' '--he' '--hel' '--help'
+ __fish_print_help funced
+ return 0
+
+ case '-*'
+ printf (_ "%s: Unknown option %s\n") funced $argv
+ return 1
+
+ case '*'
+ set -l init ''
+ set -l tmp
+
+ # Shadow IFS here to avoid array splitting in command substitution
+ set -l IFS
+ if functions -q $argv
+ set init (functions $argv | fish_indent --no-indent)
+ 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
+ if read -p $prompt -c "$init" -s cmd
+ # Shadow IFS _again_ to avoid array splitting in command substitution
+ set -l IFS
+ eval (echo -n $cmd | fish_indent)
+ end
+ return 0
+ end
+ else
+ printf (_ '%s: Expected exactly one argument, got %s.\n\nSynopsis:\n\t%sfunced%s FUNCTION\n') funced (count $argv) (set_color $fish_color_command) (set_color $fish_color_normal)
+ end
+end
+