add Makefile and manpage

This commit is contained in:
Tilman Kranz 2024-11-03 19:08:55 +01:00
parent 9e48b48173
commit 25e7e3f454
4 changed files with 224 additions and 44 deletions

37
Makefile Normal file
View File

@ -0,0 +1,37 @@
NAME=xdg-desktop-search
DESTDIR=
PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
MANDIR=$(PREFIX)/share/man/man1
DOCDIR=$(PREIFX)/share/doc/$(NAME)
PROGRAM=$(NAME)
MANPAGE=$(NAME).1
README=README.md
LICENSE=LICENSE.txt
COPYING=COPYING.txt
$(README): $(PROGRAM)
./$(PROGRAM) --help > $(README)
$(MANPAGE): $(README)
ronn < $(README) > $(MANPAGE)
.PHONY: all install install-bin install-doc install-man
all: $(PROGRAM) $(MANPAGE)
install: install-bin install-doc install-man
install-man: $(MANPAGE)
install -d -m 0755 $(DESTDIR)$(MANDIR)
install -m 0644 $(MANPAGE) $(DESTDIR)$(MANDIR)
install-bin: $(PROGRAM)
install -d -m 0755 $(DESTDIR)$(BINDIR)
install -m 0755 $(PROGRAM) $(DESTDIR)$(BINDIR)
install-doc: $(README) $(LICENSE) $(COPYING)
install -d -m 0755 $(DESTDIR)$(DOCDIR)
install -m 0644 $(README) $(DESTDIR)$(DOCDIR)
install -m 0644 $(LICENSE) $(DESTDIR)$(DOCDIR)
install -m 0644 $(COPYING) $(DESTDIR)$(DOCDIR)

View File

@ -1,38 +1,55 @@
# XDG-DESKTOP-SEARCH(1) - Search for .desktop files
## Usage
## SYNOPSIS
```
xdg-desktop-search [ OPTIONS ] SEARCH ...
```
## Arguments
## DESCRIPTION
xdg-desktop-search locates files with names that end in `.desktop` in
sub-directories of name "applications" of a collection of directories
refered to as "XDG data directories". It the searches the lines of such
desktop files for "directives", meaning key-value-assignments such as
`Exec=/some/program` where the assigned value matches one of the search
string given as commandline arguments SEARCH.
xdg-desktop-search prints a list of files that match the given search
criteria, it optionally prints selected directives from the file.
xdg-desktop-search returns successfully if the search rendered one or
more results and unsuccessfully otherwise.
The path of XDG directories searched can be modified by altering the
environment variable `XDG_DATA_DIRS`.
## ARGUMENTS
- `SEARCH`: Search .desktop files with search directives containing this
string. The searched directives are "Name" and "Exec" by default but can be
overridden using the -s option (see below).
overridden using the `-s` option (see below).
## Options
## OPTIONS
- `-h`, `--help`: Print this message and exit.
- `-v`, `--verbose`: Print directives in found .desktop files.
- `-d STRING`, `--show-directive STRING`: Instead of printing all directives
when searching in verbose mode, print only this directive (e.g. "Name").
Option can be repeated to print multiple directives.
when searching in verbose mode, print only the directive given by `STRING`
(e.g. "Name"). Option can be repeated to print multiple directives.
- `-s STRING`, `--search-directive STRING`: Instead of searching directives
"Name" and "Exec" for strings containing SEARCH, search the given directive
"Name" and "Exec" for strings containing `SEARCH`, search the given directive
instead (e.g. "Comment"). Option can be repeated to search in multiple directives.
## Return Values
## 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.
## Example
## EXAMPLE
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
@ -42,3 +59,30 @@ show the "Exec" and "TryExec" directives in each found file.
```shell
xdg-desktop-search -s Exec -s Comment -v -d Exec -d TryExec firefox
```
## AUTHOR AND COPYRIGHT
Copyright © 2024 Tilman Kranz <t.kranz@tk-sls.de>
## LICENSE
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
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
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
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
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -19,47 +19,95 @@ search_directives_regex="(Name|Exec)"
# Functions
usage() {
cat << EOF
Usage: $name [ OPTIONS ] SEARCH ...
cat << 'EOF'
# XDG-DESKTOP-SEARCH(1) - Search for .desktop files
Arguments:
## SYNOPSIS
SEARCH: Search .desktop files with search directives
containing this string. The searched directives
are "Name" and "Exec" by default but can be
overridden using the -s option (see below).
```
xdg-desktop-search [ OPTIONS ] SEARCH ...
```
Options:
## DESCRIPTION
-h | --help Print this message and exit.
-v | --verbose Print directives in found .desktop files.
-d STRING | --show-directive STRING
Instead of printing all directives when
searching in verbose mode, print only
this directive (e.g. "Name"). Option can
be repeated to print multiple directives.
-s STRING | --search-directive STRING
Instead of searching directives "Name" and
"Exec" for strings containing SEARCH,
search the given diretcive instead
(e.g. "Comment"). Option can be repeated
to search in multiple directives.
xdg-desktop-search locates files with names that end in `.desktop` in
sub-directories of name "applications" of a collection of directories
refered to as "XDG data directories". It the searches the lines of such
desktop files for "directives", meaning key-value-assignments such as
`Exec=/some/program` where the assigned value matches one of the search
string given as commandline arguments SEARCH.
Return Values:
xdg-desktop-search prints a list of files that match the given search
criteria, it optionally prints selected directives from the file.
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.
xdg-desktop-search returns successfully if the search rendered one or
more results and unsuccessfully otherwise.
Example:
The path of XDG directories searched can be modified by altering the
environment variable `XDG_DATA_DIRS`.
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.
## ARGUMENTS
$name -s Exec -s Comment -v -d Exec -d TryExec firefox
- `SEARCH`: Search .desktop files with search directives containing this
string. The searched directives are "Name" and "Exec" by default but can be
overridden using the `-s` option (see below).
## OPTIONS
- `-h`, `--help`: Print this message and exit.
- `-v`, `--verbose`: Print directives in found .desktop files.
- `-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.
- `-s STRING`, `--search-directive STRING`: Instead of searching directives
"Name" and "Exec" for strings containing `SEARCH`, search the given directive
instead (e.g. "Comment"). Option can be repeated to search in multiple directives.
## 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.
## EXAMPLE
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.
```shell
xdg-desktop-search -s Exec -s Comment -v -d Exec -d TryExec firefox
```
## AUTHOR AND COPYRIGHT
Copyright © 2024 Tilman Kranz <t.kranz@tk-sls.de>
## LICENSE
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
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
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
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
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
EOF
}
@ -128,7 +176,8 @@ parse_options $@
found=0
for data_dir in $xdg_data_dirs ; do
for _data_dir in $xdg_data_dirs ; do
data_dir=$(realpath --canonicalize-missing --no-symlinks "$_data_dir")
applications="$data_dir/applications"
[[ -d $applications ]] && for desktop in "$applications"/*.desktop ; do

50
xdg-desktop-search.1 Normal file
View File

@ -0,0 +1,50 @@
.\" generated with Ronn-NG/v0.10.1
.\" http://github.com/apjanke/ronn-ng/tree/0.10.1
.TH "XDG\-DESKTOP\-SEARCH" "1" "November 2024" ""
.SH "NAME"
\fBXDG\-DESKTOP\-SEARCH\fR \- Search for \.desktop files
.SH "SYNOPSIS"
.nf
xdg\-desktop\-search [ OPTIONS ] SEARCH \|\.\|\.\|\.
.fi
.SH "DESCRIPTION"
xdg\-desktop\-search locates files with names that end in \fB\.desktop\fR in sub\-directories of name "applications" of a collection of directories refered to as "XDG data directories"\. It the searches the lines of such desktop files for "directives", meaning key\-value\-assignments such as \fBExec=/some/program\fR where the assigned value matches one of the search string given as commandline arguments SEARCH\.
.P
xdg\-desktop\-search prints a list of files that match the given search criteria, it optionally prints selected directives from the file\.
.P
xdg\-desktop\-search returns successfully if the search rendered one or more results and unsuccessfully otherwise\.
.P
The path of XDG directories searched can be modified by altering the environment variable \fBXDG_DATA_DIRS\fR\.
.SH "ARGUMENTS"
.IP "\(bu" 4
\fBSEARCH\fR: Search \.desktop files with search directives containing this string\. The searched directives are "Name" and "Exec" by default but can be overridden using the \fB\-s\fR option (see below)\.
.IP "" 0
.SH "OPTIONS"
.IP "\(bu" 4
\fB\-h\fR, \fB\-\-help\fR: Print this message and exit\.
.IP "\(bu" 4
\fB\-v\fR, \fB\-\-verbose\fR: Print directives in found \.desktop files\.
.IP "\(bu" 4
\fB\-d STRING\fR, \fB\-\-show\-directive STRING\fR: Instead of printing all directives when searching in verbose mode, print only the directive given by \fBSTRING\fR (e\.g\. "Name")\. Option can be repeated to print multiple directives\.
.IP "\(bu" 4
\fB\-s STRING\fR, \fB\-\-search\-directive STRING\fR: Instead of searching directives "Name" and "Exec" for strings containing \fBSEARCH\fR, search the given directive instead (e\.g\. "Comment")\. Option can be repeated to search in multiple directives\.
.IP "" 0
.SH "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\.
.SH "EXAMPLE"
Search for the string "firefox" in all \.desktop files found in the path specified by \fBXDG_DATA_DIRS\fR\. 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\.
.IP "" 4
.nf
xdg\-desktop\-search \-s Exec \-s Comment \-v \-d Exec \-d TryExec firefox
.fi
.IP "" 0
.SH "AUTHOR AND COPYRIGHT"
Copyright \(co 2024 Tilman Kranz \fIt\.kranz@tk\-sls\.de\fR
.SH "LICENSE"
xdg\-desktop\-search is distributed under the terms and conditions of the MIT license \fIhttps://opensource\.org/license/mit\fR\.
.P
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software\(rs), 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 so, subject to the following conditions:
.P
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software\.
.P
THE SOFTWARE IS PROVIDED “AS IS\(rs, 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 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE\.