我hello在fishshell中定义了一个函数:
function hello
echo Hello
end
Run Code Online (Sandbox Code Playgroud)
并保存它:
funcsave hello
Run Code Online (Sandbox Code Playgroud)
如果我想删除它,我可以删除该文件~/.config/fish/functions/hello.fish.
还有其他办法吗?(如内置funcdel或funcrm)
gle*_*man 18
不,没有内置删除文件,但您可以使用:
functions --erase hello
Run Code Online (Sandbox Code Playgroud)
要么
functions -e hello
Run Code Online (Sandbox Code Playgroud)
擦除当前会话中的函数定义.
小智 8
我为此创造了另一种鱼类功能
function funcdel
if test -e ~/.config/fish/functions/$argv[1].fish
rm ~/.config/fish/functions/$argv[1].fish
echo 'Deleted function ' $argv[1]
else
echo 'Not found function ' $argv[1]
end
end
Run Code Online (Sandbox Code Playgroud)
小智 5
以上解决方案functions -e hello仅hello在当前会话中删除.打开另一个终端,功能仍在那里.
要以持久的方式删除该函数,我不得不求助于~/.config/fish/functions/hello.fish直接删除该文件.到目前为止,我不知道另一种以持久方式删除的方式.
一个更完整的、自定义的(和安静的)自制解决方案,灵感来自@Kanzee 的回答(复制到文件~/.config/fish/functions/funcdel.fish):
function funcdel --description 'Deletes a fish function both permanently and from memory'
set -l fun_name $argv[1]
set -l fun_file ~/.config/fish/functions/$fun_name.fish
# Delete the in-memory function, if it exists
functions --erase $fun_name
# Delete the function permanently,
# if it exists as a file in the regular location
if test -e $fun_file
rm $fun_file
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3349 次 |
| 最近记录: |