File wikiman.spec of Package wikiman

#
# spec file for package wikiman
#
# Copyright (c) 2025 SUSE LLC and contributors
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


Name:           wikiman
Version:        2.14.1
Release:        0
Summary:        Offline interactive documentation search
License:        MIT
URL:            https://github.com/filiparag/wikiman
Source0:        %{name}-%{version}.tar.gz
Source1:        arch-wiki_20250710.source.tar.xz
# Source1:        https://github.com/filiparag/wikiman/releases/download/%%{version}/arch-wiki_20250710.source.tar.xz
Source2:        devdocs_20250710.source.tar.xz
# Source2:        https://github.com/filiparag/wikiman/releases/download/%%{version}/devdocs_20250710.source.tar.xz
Source3:        freebsd-docs_20250710.source.tar.xz
# Source3:        https://github.com/filiparag/wikiman/releases/download/%%{version}/freebsd-docs_20250710.source.tar.xz
Source4:        gentoo-wiki_20250710.source.tar.xz
# Source4:        https://github.com/filiparag/wikiman/releases/download/%%{version}/gentoo-wiki_20250710.source.tar.xz
Source5:        tldr-pages_20250710.source.tar.xz
# Source5:        https://github.com/filiparag/wikiman/releases/download/%%{version}/tldr-pages_20250710.source.tar.xz
# Source5:        sources.awk
Patch0:         completions-dir.patch
BuildRequires:  fdupes
BuildRequires:  fish
BuildRequires:  make
BuildRequires:  unar
BuildRequires:  zsh
Requires:       man
Requires:       fzf
Requires:       ripgrep
Requires:       gawk
Requires:       w3m
Requires:       findutils
Requires:       sed
Requires:       grep
Requires:       gnu_parallel

%description
Wikiman is a universal offline documentation search engine. It can
browse system manual pages, tldr-pages, the ArchWiki, Gentoo Wiki,
FreeBSD documentation, and many other sources curated by DevDocs.
It provides an easy interface for browsing documentation without the
need to be exact and connected to the internet. This is achieved by
utilizing full-text search for wikis, partial name and description
matching for man pages, and fuzzy filtering for search results.

%package arch-wiki
Summary:        Arch Wiki bundle for use with Wikiman
Supplements:    %{name}

%description arch-wiki
Arch Wiki bundle for use with Wikiman

%package devdocs
Summary:        Devdocs bundle for use with Wikiman
Supplements:    %{name}

%description devdocs
Devdocs bundle for use with Wikiman
WARNING: This is a large package, and will use >2 GiB of disk space.


%package freebsd-docs
Summary:         FreeBSD bundle for use with Wikiman
Supplements:    %{name}

%description freebsd-docs
Freebsd Docs bundle for use with Wikiman

%package gentoo-wiki
Summary:        Gentoo bundle for use with Wikiman
Supplements:    %{name}

%description gentoo-wiki
Gentoo Wiki bundle for use with Wikiman

%package tldr-pages
Summary:        Tldr Pages bundle for use with Wikiman
Supplements:    %{name}

%description tldr-pages
Tldr Pages bundle for use with Wikiman

%package bash-completion
Summary:        Bash Completion for %{name}
Requires:       bash-completion
Requires:       %{name}
Supplements:    (%{name} and bash-completion)
BuildArch:      noarch

%description bash-completion
Bash command line completion support for %{name}.

%package fish-completion
Summary:        Fish Completion for %{name}
Requires:       fish
Requires:       %{name}
Supplements:    (%{name} and fish)
BuildArch:      noarch

%description fish-completion
Fish command line completion support for %{name}.

%package zsh-completion
Summary:        Zsh Completion for %{name}
Requires:       zsh
Requires:       %{name}
Supplements:    (%{name} and zsh)
BuildArch:      noarch

%description zsh-completion
Zsh command line completion support for %{name}.

%prep
%autosetup -p1

%build
make

%install
make prefix=%{buildroot} install
# for the actual documentation tarballs. We could potentially do this for
# openSUSE too...would be much nicer to grep through all the docs
# this is the command to manually grab the tarballs from the github release
# make source-arch source-devdocs source-freebsd source-gentoo source-tldr
mkdir -p %{buildroot}/usr/share/doc

for i in %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE4} %{SOURCE5}; do
    tar xf "${i}" -C %{buildroot}/usr/share/doc --strip-components=3
done
# for some reason, the included tldr tarball has a broken symlink.
# looks like a holdover from old tldr page archive formats
# below is targeted to just remove that single dead symlinks,
# but probably a good idea to just automatically clobber dead symlinks
# rm -f %%{buildroot}/usr/share/doc/tldr-pages/en/pages.en
find %{buildroot}/usr/share/doc -xtype l -delete
# One of the docs in devdocs tarball has a dir containing the tilde character ~ :
# /home/abuild/rpmbuild/BUILD/wikiman-2.14.1-build/BUILDROOT/usr/share/doc/devdocs/deno/api/deno/~
# Just in case this happens more in the future, let's just make sure to rename all tilde dirs to
# something sensible, e.g. the name of the dir above it.
for tildir in $(find %{buildroot}/usr/share/doc -type d -name '~'); do
    mv "$tildir"/* "$(dirname "$tildir")/" 2>/dev/null || true
    rmdir "$tildir" 2>/dev/null || true
done
%fdupes -s %{buildroot}%{_datadir}

%files
%license LICENSE
%doc README.md
%config(noreplace) %{_sysconfdir}/%{name}.conf
%{_bindir}/%{name}
%{_datadir}/%{name}
%{_datadir}/%{name}/sources/*.sh
%{_datadir}/%{name}/widgets/widget*
%{_mandir}/man1/%{name}.1.gz

%files bash-completion
%{_datadir}/bash-completion/completions/%{name}

%files fish-completion
%{_datadir}/fish/vendor_completions.d/%{name}.fish

%files zsh-completion
%dir %{_datadir}/zsh/site-functions
%{_datadir}/zsh/site-functions/_%{name}

%files arch-wiki
%{_datadir}/doc/arch-wiki
%files devdocs
%{_datadir}/doc/devdocs/
%files freebsd-docs
%{_datadir}/doc/freebsd-docs
%files gentoo-wiki
%{_datadir}/doc/gentoo-wiki
%files tldr-pages
%{_datadir}/doc/tldr-pages

%changelog
openSUSE Build Service is sponsored by