Skip to content

Commit

Permalink
Merge pull request #2 from Antiz96/dev
Browse files Browse the repository at this point in the history
Initial Release
  • Loading branch information
Antiz96 authored Aug 8, 2022
2 parents 3935201 + 934d82c commit d00494b
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 1 deletion.
69 changes: 68 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,68 @@
Under construction
# Zaman

A simple tool that prints man pages in a PDF file (with vim keys support) for an easier reading.

## Table of contents
* [Description](#description)
* [Installation](#installation)
* [Dependencies](#dependencies)
* [Usage](#usage)
* [Documentation](#documentation)

## Description

A simple tool that prints man pages in a PDF file (with vim keys support) via [Zathura](https://pwmt.org/projects/zathura/) for an easier reading, which also allows you to select the man page to display through a list generated via [Dmenu](https://tools.suckless.org/dmenu/).

## Installation

### AUR

Arch (or Arch based distro) users can install the [zaman](https://aur.archlinux.org/packages/zaman "zaman AUR package") AUR package.

### From Source

#### Installation

Launch the following command in your terminal to execute the install script (requires "curl" and "sudo") :
```
curl -s https://raw.githubusercontent.com/Antiz96/zaman/main/install.sh | bash
```

#### Update

Simply re-execute the install script (requires "curl" and "sudo") :
```
curl -s https://raw.githubusercontent.com/Antiz96/zaman/main/install.sh | bash
```

#### Uninstalling

Launch the following command in your terminal to execute the uninstall script :
```
curl -s https://raw.githubusercontent.com/Antiz96/zaman/main/uninstall.sh | bash
```

## Dependencies

Arch-Update depends on [zathura](https://pwmt.org/projects/zathura/) (and zathura-pdf-poppler) to print the PDF file and [dmenu](https://tools.suckless.org/dmenu/) to display the list of available man pages.

## Usage

Simply launch the `zaman` command in your terminal to open the menu list of all the man pages available on your system, allowing you to search and select the man page you want to read.
You can also specify the man page to open directly in the command, like so :
```
zaman ls
```

Check the screenshots below for more information.

### Screenshot

## Documentation

Refer to the [Wiki Documentation Page](https://github.com/Antiz96/zaman/wiki/Documentation "Wiki Documentation Page").
<br>
<br>
The full documentation is also available as a man page and with the "--help" function.
<br>
Type `man zaman` or `zaman --help` after you've installed the **zaman** package.
118 changes: 118 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/bin/bash

pkgname="zaman"
url="https://github.com/Antiz96/zaman"
latest_release=$(curl -s https://raw.githubusercontent.com/Antiz96/zaman/main/latest_release.txt)

checksum=$(curl -Ls "${url}/releases/download/v${latest_release}/sha256sum.txt")
current_version=$("${pkgname}" -v 2>/dev/null)

package() {

package_manager=$( (ls /usr/bin/apt || ls /usr/bin/dnf || ls /usr/bin/pacman || ls /usr/bin/emerge) 2>/dev/null | awk -F/ '{print $4}' )

if [ -z "${package_manager}" ]; then
echo -e "This script only supports the following package manager to handle dependencies :\napt\ndnf\npacman\nemerge\n\nYour package manager is not supported\nYou'll need to install the following packages yourself to make \"zaman\" work correctly (if you don't have them installed already)\nzathura\zathura-pdf-poppler\ndmenu"
fi

if ! command -v zathura > /dev/null ; then
echo "Installing dependencies via ${package_manager} : zathura"

case "${package_manager}" in
apt)
sudo apt install -y zathura > /dev/null || exit 1
;;
dnf)
sudo dnf install -y zathura > /dev/null || exit 1
;;
pacman)
sudo pacman -S --noconfirm zathura > /dev/null || exit 1
;;
emerge)
sudo emerge zathura > /dev/null || exit 1
;;
esac
fi

case "${package_manager}" in
apt)
if ! apt list --installed | grep -q zathura-pdf-poppler ; then
echo "Installing dependencies via ${package_manager} : zathura-pdf-poppler"
sudo apt install -y zathura-pdf-poppler > /dev/null || exit 1
fi
;;
dnf)
if ! dnf list installed | grep -q zathura-pdf-poppler ; then
echo "Installing dependencies via ${package_manager} : zathura-pdf-poppler"
sudo dnf install -y zathura-pdf-poppler > /dev/null || exit 1
fi
;;
pacman)
if ! pacman -Q | grep -q zathura-pdf-poppler ; then
echo "Installing dependencies via ${package_manager} : zathura-pdf-poppler"
sudo pacman -S --noconfirm zathura-pdf-poppler > /dev/null || exit 1
fi
;;
emerge)
if ! qlist -I | grep -q zathura-pdf-poppler ; then
echo "Installing dependencies via ${package_manager} : zathura-pdf-poppler"
sudo emerge zathura-pdf-poppler > /dev/null || exit 1
fi
;;
esac


if ! command -v dmenu > /dev/null ; then
echo "Installing dependencies via ${package_manager} : dmenu"

case "${package_manager}" in
apt)
sudo apt install -y suckless-tools > /dev/null || exit 1
;;
dnf)
sudo dnf install -y dmenu > /dev/null || exit 1
;;
pacman)
sudo pacman -S --noconfirm dmenu > /dev/null || exit 1
;;
emerge)
sudo emerge dmenu > /dev/null || exit 1
;;
esac
fi

curl -Ls "${url}/archive/v${latest_release}.tar.gz" -o "/tmp/${pkgname}-${latest_release}.tar.gz" || { echo -e >&2 "An error occured during the download of the ${pkgname}'s archive\n\nPlease, verify that you have a working internet connexion and curl installed on your machine\nIf the problem persists anyway, you can open an issue at ${url}/issues" ; exit 1; }

if ! echo "${checksum}" "/tmp/${pkgname}-${latest_release}.tar.gz" | sha256sum -c --status -; then
echo -e >&2 "\n${pkgname}'s archive integrity check failed\nAborting\n\nPlease, verify that you have a working internet connexion and curl installed on your machine\nIf the problem persists anyway, you can open an issue at ${url}/issues"
rm -f "/tmp/${pkgname}-${latest_release}.tar.gz"
exit 1
else
echo -e "\n${pkgname}'s archive integrity validated\nProceeding to installation..."
fi

tar -xf "/tmp/${pkgname}-${latest_release}.tar.gz" -C /tmp/ || exit 1
chmod +x "/tmp/${pkgname}-${latest_release}/src/bin/${pkgname}.sh" || exit 1
gzip "/tmp/${pkgname}-${latest_release}/src/man/${pkgname}.1" || exit 1
sudo cp -f "/tmp/${pkgname}-${latest_release}/src/bin/${pkgname}.sh" "/usr/local/bin/${pkgname}" || exit 1
sudo mkdir -p /usr/local/share/man/man1 || exit 1
sudo cp -f "/tmp/${pkgname}-${latest_release}/src/man/${pkgname}.1.gz" /usr/local/share/man/man1/ || exit 1
rm -rf "/tmp/${pkgname}-${latest_release}" "/tmp/${pkgname}-${latest_release}.tar.gz" || exit 1
}

if ! command -v "${pkgname}" > /dev/null ; then
echo "${pkgname} is going to be installed"
package
echo -e "\n${pkgname} has been successfully installed\nPlease, visit ${url} for more information\n\nThanks for downloading !"
exit 0
elif [ "${current_version}" != "${latest_release}" ]; then
echo "A new update is available for ${pkgname}"
package
echo -e "\n${pkgname} has been successfully updated to version ${latest_release}\nPlease, visit ${url} for more information"
exit 0
else
echo "${pkgname} is up to date -- reinstallation"
package
echo -e "\n${pkgname} has been successfully reinstalled\nPlease, visit ${url} for more information"
exit 0
fi
1 change: 1 addition & 0 deletions latest_release.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
45 changes: 45 additions & 0 deletions src/bin/zaman.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

#Current version
version="1.0.0"

#Replace the $1 var by "option" just to make the script more readable/less complex
option="${1}"

#If the option passed to the "zaman" command matches an available man page, print it to a PDF file via "zathura"
if man -k . | awk '{print $1}' | grep -iq ^"${option}"$ ; then
man -Tpdf "${option}" | zathura --mode=fullscreen -
else
case "${option}" in
#If no option is passed to the "zaman" command, print the list of available man pages through "dmenu" and print the selected one to a PDF file via "zathura"
"")
man_selected=$(man -k . | awk '{print $1}' | dmenu -l 15)

if man -k . | awk '{print $1}' | grep -iq ^"${man_selected}"$ ; then
man -Tpdf "${man_selected}" | zathura --mode=fullscreen -
else
man "${man_selected}"
echo >&2 "Try 'zaman --help' for more information."
exit 1
fi
;;
#If the -v (or --version) option is passed to the "zaman" command, print the current version
-v|--version)
echo "${version}"
exit 0
;;
#If the -h (or --help) option is passed to the "zaman" command, print the documentation (man page)
#The documentation is also readable here https://github.com/Antiz96/zaman/blob/main/README.md or by typing the following command in a terminal : man zaman
-h|--help)
#Print the documentation (man page) and quit
man zaman | col
exit 0
;;
#If any other option(s) are passed to the script, print an error and quit
*)
man "${option}"
echo >&2 "Try 'zaman --help' for more information."
exit 1
;;
esac
fi
54 changes: 54 additions & 0 deletions src/man/zaman.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.TH "ZAMAN" "1" "August 2022" "Zaman v1" "Zaman Manual"

.SH NAME
zaman \- A simple tool that prints man pages in a PDF file (with vim keys support) for an easier reading.

.SH SYNOPSIS
.B zaman
[\fI\,OPTION\/\fR] [\fI\,MAN PAGE\/\fR]

.SH DESCRIPTION
A simple tool that prints man pages in a PDF file (with vim keys support) via Zathura for an easier reading. It also allows you to select the man page to display through a list of all the available man pages on your system generated via Dmenu.

.SH OPTIONS
.PP
.RB "If no option is passed, print the list of all the available man pages on the system, allowing you to search and select the one to print as a PDF."
.br
.br
.RB "You can also specify the man page to open directly in the command :"
.br
.RB "zaman 'man page to open', ie: zaman ls"
.PP

.TP
.B \-v, \-\-version
Print the current version

.TP
.B \-h, \-\-help
Print the help

.SH EXIT STATUS
.TP
.B 0
if OK

.TP
.B 1
if problems (user tried to open a non-existing man page...)

.SH SEE ALSO
.BR zathura (1),
.BR dmenu (1),
.BR echo (1),
.BR grep (1),
.BR man (1),
.BR col (1),
.br
The documentation is also available on the GitHub page https://github.com/Antiz96/zaman

.SH BUGS
Please report bugs to the GitHub page https://github.com/Antiz96/zaman

.SH AUTHOR
Robin Candau <robincandau@protonmail.com>
11 changes: 11 additions & 0 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

pkgname="zaman"
url="https://github.com/Antiz96/zaman"

echo -e "${pkgname} is going to be uninstalled\n"

sudo rm -f "/usr/local/bin/${pkgname}" || exit 1
sudo rm -f "/usr/local/share/man/man1/${pkgname}.1.gz" || exit 1

echo -e "${pkgname} has been successfully uninstalled\nPlease, visit ${url} for more information"

0 comments on commit d00494b

Please sign in to comment.