我用这种方式安装过z.lua, 好用;
记录一些常用的api:
api记录
获取用户主目录
home_dir = os.path.expanduser("~")
获取脚本文件的绝对路径
zlua_path = os.path.abspath(__file__)
zlua_dir = os.path.dirname(zlua_path)
构建路径字符串
# 构建目标文件路径
target_dir = os.path.join(home_dir, ".config/fish/conf.d")
target_file = os.path.join(target_dir, "z.fish")
检查或创建文件夹
# 检查并创建目标目录
if not os.path.exists(target_dir):
os.makedirs(target_dir)
print(f"Created directory: {target_dir}")
写入文本到文件
# 要写入的内容
content = f"source (lua {zlua_dir}/z.lua --init fish | psub)"
# 写入内容到目标文件
with open(target_file, "w") as file:
file.write(content)
print(f"Written to file: {target_file}")
pass
pass
pass
pass
标签:target,python,pass,file,Linux,path,os,dir,搭建
From: https://www.cnblogs.com/runninginsilence/p/18222502