如何解决如何将bash函数转换为fish函数?
我使用this post和文档,试图为gokechan/lf软件包上的PR创建fish函数,以使lfcd在鱼中工作。
这是我要转换的bash函数:
2020-09-15 17:05:36,992 [INFO] No Names entry in Catalog
Traceback (most recent call last):
File "facturx-pdfextractxml.py",line 95,in <module>
main(options,arguments)
File "facturx-pdfextractxml.py",line 80,in main
logger.warn('File %s has not been created',out_xml_filename)
File "C:\Users\Selim SEDIKKI\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py",line 1449,in warn
warnings.warn("The 'warn' method is deprecated,"
File "C:\Users\Selim SEDIKKI\AppData\Local\Programs\Python\Python38\lib\warnings.py",line 109,in _showwarnmsg
sw(msg.message,msg.category,msg.filename,msg.lineno,File "C:\Users\Selim SEDIKKI\AppData\Local\Programs\Python\Python38\lib\site-packages\PyPDF4\pdf.py",line 1133,in _showwarning
file.write(formatWarning(message,category,filename,lineno,line))
File "C:\Users\Selim SEDIKKI\AppData\Local\Programs\Python\Python38\lib\site-packages\PyPDF4\utils.py",line 69,in formatWarning
file = filename.replace("/","\\").rsplit("\\",1)[1] # find the file name
IndexError: list index out of range
这是我从上面的函数改编而成的fish函数:
lfcd () {
tmp="$(mktemp)"
lf -last-dir-path="$tmp" "$@"
if [ -f "$tmp" ]; then
dir="$(cat "$tmp")"
rm -f "$tmp"
if [ -d "$dir" ]; then
if [ "$dir" != "$(pwd)" ]; then
cd "$dir"
fi
fi
fi
}
到目前为止,该函数运行lf,但在退出时未打开最后选择的目录。
我在创建鱼功能或将bash转换为鱼方面有0年经验。 这是我的入门鱼项目,因此,非常感谢您的帮助或指导!
解决方法
大多数时候,并不是必须要在鱼中引用变量:分词不是鱼的功能。
您可以写:
function lfcd
set tmp (mktemp)
lf -last-dir-path=$tmp $argv
if [ -f $tmp ]
set dir (cat $tmp)
rm -f $tmp
[ -d $dir ]; and [ $dir != (pwd) ]; and cd $dir
end
end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。