Skip to content

Linux Tool for Creating .desktop Files with Ease

Notifications You must be signed in to change notification settings

Liangdi/deskfile

Repository files navigation

Deskfile

一个用于生成 Linux .desktop 文件的命令行工具,完全兼容 freedesktop.org 规范。

English Version: README_en.md

功能特性

  • 🚀 快速生成 .desktop 文件,支持所有必需字段和常用可选字段
  • 格式验证 确保生成的文件符合 freedesktop.org Desktop Entry Specification v1.5
  • 🎯 用户友好 清晰的命令行界面和详细的错误提示
  • 🔧 灵活配置 支持自定义字段和高级选项
  • 📦 系统集成 支持直接安装到系统应用目录

安装

通过 Cargo 安装

cargo install deskfile

从源码编译

git clone https://github.com/Liangdi/deskfile
cd deskfile
cargo build --release

快速开始

基本用法

# 创建基本的 .desktop 文件
deskfile create -n "MyApp" -e "/usr/bin/myapp" -i "/usr/share/icons/myapp.png"

# 创建带分类和关键词的 .desktop 文件
deskfile create -n "文本编辑器" -e "/usr/bin/textedit" -i "text-editor" \
  --categories "Office,TextEditor" --keywords "文本,编辑器,写作"

# 创建终端应用程序 .desktop 文件
deskfile create -n "终端应用" -e "/usr/bin/termapp" -i "terminal" \
  --terminal true --comment "基于终端的应用程序"

# 指定输出路径并验证
deskfile create -n "MyApp" -e "/usr/bin/myapp" -i "myapp" \
  -o "~/Desktop/myapp.desktop" --validate

# 安装到系统应用目录
deskfile create -n "MyApp" -e "/usr/bin/myapp" -i "myapp" --install

# 强制安装到系统应用目录(覆盖已存在文件)
deskfile create -n "MyApp" -e "/usr/bin/myapp" -i "myapp" --install --force

命令参数

必需参数

  • --name, -n <NAME>: 应用程序名称
  • --exec, -e <EXEC>: 可执行文件路径
  • --icon, -i <ICON>: 图标文件路径

可选参数

  • --type, -t <TYPE>: 应用程序类型(默认: Application)
  • --comment, -c <COMMENT>: 应用程序描述
  • --categories <CATEGORIES>: 应用程序分类,逗号分隔
  • --keywords <KEYWORDS>: 搜索关键词,逗号分隔
  • --terminal, -T: 是否在终端中运行(默认: false)
  • --startup-notify: 是否显示启动通知(默认: true)
  • --output, -o <OUTPUT>: 输出文件路径(默认: ./.desktop)
  • --install: 安装到系统应用目录
  • --force: 强制覆盖已存在文件(与 --install 配合使用)
  • --validate: 生成后验证文件

系统安装

工具会自动检测并选择最合适的系统应用目录:

  1. 用户目录(优先,无需特殊权限):

    • ~/.local/share/applications/
  2. 系统目录(需要 root 权限):

    • /usr/share/applications/
    • /usr/local/share/applications/

安装完成后会自动调用 update-desktop-database 更新系统桌面数据库。

技术特性

  • 编程语言: Rust (2024 edition)
  • 错误处理: anyhow + thiserror
  • 日志系统: tracing + tracing-subscriber
  • 命令行解析: clap
  • 性能: 文件生成时间 < 100ms,内存使用 < 10MB

兼容性

  • 规范兼容: freedesktop.org Desktop Entry Specification v1.5
  • 发行版支持: Ubuntu, Fedora, Arch, openSUSE 等主流 Linux 发行版
  • 桌面环境: GNOME, KDE, XFCE, LXDE 等
  • 编码支持: UTF-8

开发

# 运行测试
cargo test

# 静态检查
cargo check

# 构建项目
cargo build --release

许可证

MIT License - 详见 LICENSE 文件

贡献

欢迎提交 Issue 和 Pull Request!请查看我们的 贡献指南

支持

About

Linux Tool for Creating .desktop Files with Ease

Resources

Stars

Watchers

Forks

Packages

No packages published