support options --json and --quiet

This commit is contained in:
Tilman Kranz 2025-05-30 22:07:53 +02:00
parent 75de33bb30
commit 0ad7f26102
3 changed files with 119 additions and 20 deletions

View file

@ -36,6 +36,9 @@ environment variable `XDG_DATA_DIRS`.
- `-v`, `--verbose`: Print directives in found .desktop files.
- `-j`, `--json`: Print .desktop files found and directives to display
as JSON data structure (see also EXAMPLES below).
- `-d STRING`, `--show-directive STRING`: Instead of printing all directives
when searching in verbose mode, print only the directive given by `STRING`
(e.g. "Name"). Option can be repeated to print multiple directives.
@ -47,17 +50,37 @@ environment variable `XDG_DATA_DIRS`.
## RETURN VALUES
The command returns 0 if .desktop files were found that match the specified
criteria, 1 on usage error and 2 if no matching .desktop files were found.
criteria, 1 if no matching .desktop files were found and 127 on usage error.
## EXAMPLE
## EXAMPLES
Search for the string "firefox" in all .desktop files found in the path
specified by `XDG_DATA_DIRS`. To match, the string "firefox" must be contained
in either the "Exec" or the "Comment" directive. List the matching files, also
show the "Exec" and "TryExec" directives in each found file.
`xdg-desktop-search -s Exec -s Comment -v -d Exec -d TryExec firefox`
Search for .desktop files containing GVim in their "Name" directive and
determine the value of the "Exec" directive in the files found. Display
results as JSON data structure:
`xdg-desktop-search -j -d Exec -s Name GVim`
Result:
```
xdg-desktop-search -s Exec -s Comment -v -d Exec -d TryExec firefox
[
{
"desktop": "/usr/share/applications/gvim.desktop",
"results": [
{
"directive": "Exec",
"value": "gvim -f %F"
}
]
}
]
```
## AUTHOR AND COPYRIGHT
@ -70,7 +93,7 @@ xdg-desktop-search is distributed under the terms and conditions of the MIT
license <https://opensource.org/license/mit>.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
@ -79,7 +102,7 @@ so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER