Functions to backup a function and remove a backed up function

This commit is contained in:
Bruno Pinto 2012-07-24 01:00:10 -03:00
parent 3c10941014
commit f5e7eacbe0
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,33 @@
function backup_function
set -l funcname $argv[1]
if functions -q -- $funcname
_create_tmpname
functions -- $funcname | sed -e s/^function\ $funcname/function\ old_$funcname/ > $tmpname
_source_old_function
else
_print_function_not_found $argv
remove_backup_function $argv
return 1
end
end
function _create_tmpname
set -l TMPDIR /tmp
set -g tmpname (printf "$TMPDIR/fish_funced_%d_%d.fish" %self (random))
while test -f $tmpname
set -g tmpname (printf "$TMPDIR/fish_funced_%d_%d.fish" %self (random))
end
end
function _print_function_not_found
set_color red
_ "Function '$argv' not found.
"
set_color normal
end
function _source_old_function
. $tmpname
end

View File

@ -0,0 +1,6 @@
function remove_backup_function
functions -e old_$argv[1]
rm $tmpname >/dev/null ^&1
set -e tmpname
end