diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..50eb7b9 --- /dev/null +++ b/.npmignore @@ -0,0 +1,8 @@ +.gitignore +.npmignore +.github/ +node_modules/ +package-lock.json +*.tgz +*.tar +*.zip diff --git a/README.md b/README.md index eaf02ed..ce4426e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ However, you are free to pass in whole slew of options: --help display help --view View file --edit Call your editor with the file ---list List all desktop files +--list List all desktop files +--changelog Show the changelog -d, --desktop Desktop file to use -k, --keywords Set keywords @@ -31,6 +32,11 @@ However, you are free to pass in whole slew of options: --json Set key/values from JSON ``` +#### Extra Features Usage + `--list` has an optional filter, so you can do +`desktopmenuitem --list .local` and it will only show `.desktop` files in a folder that has `.local` in it. + + ### Notes - [.desktop spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html) @@ -41,5 +47,3 @@ However, you are free to pass in whole slew of options: - Does not preserve any comments in an existing file - The underlying ini load/save module doesn't support this yet. I would be willing to switch for another no-dependency ini module. (PR would be welcome) -- Edits the original .desktop file, so you must have sudo rights if you are editing a .desktop file in a protected folder. - - Technically, I believe it should create the "edited" menu item in your ~/.local... folder, this could easily be added, PR would be accepted. diff --git a/changelog b/changelog new file mode 100644 index 0000000..3d4aae5 --- /dev/null +++ b/changelog @@ -0,0 +1,4 @@ +0.0.1 - First version (unreleased) +0.0.2 - First Released version +0.0.3 - Added call desktop-update-database after modification to make sure mime cache is updated. +0.0.4 - Added --changelog, filter to --list, automatically now save changed .desktop in the .local folder. diff --git a/menuitem.js b/menuitem.js index 5349ec1..6215b46 100755 --- a/menuitem.js +++ b/menuitem.js @@ -29,6 +29,7 @@ const pathsToCheck = [process.env.HOME+'/.local/share/applications/', '/usr/loca addPathsToCheck(process.env['XDG_DATA_DIRS']?.split(":") || []); addPathsToCheck(process.env['XDG_DATA_HOME']?.split(':') || []); +const isRoot = process.getuid() === 0 || process.getgid() === 0; // noinspection SpellCheckingInspection console.log("\r\ndesktopmenuitem".blue,version.blue, "\r\n---------------------"); @@ -40,6 +41,8 @@ program.description('An application for creating or editing .desktop files'); program.option("--view", "View .desktop file"); program.option("--edit", "Call your editor with the .desktop file"); program.option("--list", "List all .desktop files" ); +program.option("--changelog", "Display the changelog"); +program.option("--overwrite", "Over write the original file location, if root.") program.option("-d, --desktop ", "Desktop file to use"); program.option("-k, --keywords ", "Set keywords"); program.option("-m, --mime ", "Set mime type"); @@ -56,10 +59,30 @@ const options = program.opts(); // List Directories if (options.list) { - pathsToCheck.forEach((val) => { - listDirectory(val); - console.log(""); - }); + if (program.args.length) { + pathsToCheck.forEach((val) => { + if (val.indexOf(program.args[0]) >= 0) { + listDirectory(val); + console.log(""); + } + }); + } else { + pathsToCheck.forEach((val) => { + listDirectory(val); + console.log(""); + }); + } + process.exit(0); +} + +// Show the Changelog +if (options.changelog) { + let startPath = path.normalize(process.argv[1].replace(path.basename(process.argv[1]),'') + "../lib/node_modules/@master.technology/desktopmenuitem/changelog"); + if (fs.existsSync(startPath)) { + console.log(fs.readFileSync(startPath).toString()); + } else { + console.log("Missing changelog".red); + } process.exit(0); } @@ -100,7 +123,7 @@ if (program.args.length && program.args[0].endsWith(".desktop")) { // Figure out the Application Name to show as the Menu if (options.name == null || options.name.length === 0) { if (program.args.length) { - options.dynamicName = cleanName(path.basename(program.args[0], ".desktop")); + options.dynamicName = properCase(cleanName(path.basename(program.args[0], ".desktop"))); } else if (options.desktop != null && options.desktop.length) { options.dynamicName = path.basename(options.desktop, ".desktop"); } @@ -116,30 +139,30 @@ if (options.exec == null || options.exec.length === 0) { } const info = loadFile(desktopFile); -if (options.edit && !info._created) { - spawnEditor(info._pathToDesktopFile); - spawnUpdateDB(info._pathToDesktopFile.replace(path.basename(info._pathToDesktopFile), '')); +if (options.edit && !info.__internal.created) { + spawnEditor(info.__internal.pathWithDesktopFile); + spawnUpdateDB(info.__internal.pathToDesktopFile); process.exit(0); } // If they just want to view the file... if (options.view) { + delete info.__internal; console.log(info); process.exit(0); } -if (configureDesktopEntry(info)) { -// console.log(info); - const fileName = info['_pathToDesktopFile']; - delete info['_pathToDesktopFile']; - delete info['_created']; +if (configureDesktopEntry(info) || options.edit) { + const fileName = info.__internal.pathWithDesktopFile; + const pathToDesktopFile = info.__internal.pathToDesktopFile; + delete info.__internal; fs.writeFileSync(fileName, ini.stringify(info)); if (options.edit) { spawnEditor(fileName); } else { console.log("Saved:", fileName); } - spawnUpdateDB(fileName.replace(path.basename(fileName), '')); + spawnUpdateDB(pathToDesktopFile); } else { console.log("No Changes"); } @@ -153,7 +176,6 @@ if (configureDesktopEntry(info)) { * @param path */ function spawnUpdateDB(path) { - console.log(path); const updater = ['/usr/bin/update-desktop-database']; for (let i=0;i