mirror of
https://github.com/oh-my-fish/oh-my-fish.git
synced 2024-11-22 14:42:20 +08:00
Functions to backup a function and remove a backed up function
This commit is contained in:
parent
3c10941014
commit
f5e7eacbe0
33
functions/backup_function.fish
Normal file
33
functions/backup_function.fish
Normal 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
|
6
functions/remove_backup_function.fish
Normal file
6
functions/remove_backup_function.fish
Normal file
|
@ -0,0 +1,6 @@
|
|||
function remove_backup_function
|
||||
functions -e old_$argv[1]
|
||||
|
||||
rm $tmpname >/dev/null ^&1
|
||||
set -e tmpname
|
||||
end
|
Loading…
Reference in New Issue
Block a user