2024-11-12 20:13:13 -05:00
|
|
|
#!/usr/bin/env python3
|
2024-11-13 10:09:36 +08:00
|
|
|
|
2024-11-12 20:13:13 -05:00
|
|
|
"""
|
|
|
|
Python script to generate a man page for the command `fastfetch`.
|
2024-11-13 10:09:36 +08:00
|
|
|
The man content will be printed to stdout so you will need to
|
2024-11-12 20:13:13 -05:00
|
|
|
pipe it to a file if you want to save it.
|
|
|
|
The command options will be generated using a JSON file.
|
|
|
|
For the format of the JSON file, see https://github.com/fastfetch-cli/fastfetch/blob/dev/src/data/help.json
|
|
|
|
"""
|
|
|
|
|
|
|
|
from json import load
|
2024-11-23 23:22:57 -03:00
|
|
|
from datetime import datetime, timezone
|
2024-11-15 00:50:47 +00:00
|
|
|
from time import time
|
2024-11-12 20:13:13 -05:00
|
|
|
from re import search
|
2024-11-15 00:50:47 +00:00
|
|
|
from os import environ, path
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
###### Text Decorations Tags ######
|
|
|
|
|
2024-11-13 10:09:36 +08:00
|
|
|
startUnderline = r"\fI" # start underline text tag
|
|
|
|
endUnderline = r"\fR" # end underline text tag
|
2024-11-12 20:13:13 -05:00
|
|
|
|
2024-11-13 10:09:36 +08:00
|
|
|
startBold = r"\fB" # start bold text tag
|
|
|
|
endBold = r"\fR" # end bold text tag
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
###### Parameters ######
|
|
|
|
|
2024-11-13 10:09:36 +08:00
|
|
|
# path to the current directory
|
|
|
|
pathToCurrentDir = path.dirname(__file__)
|
2024-11-12 20:13:13 -05:00
|
|
|
# path to the JSON option file
|
2024-11-13 10:09:36 +08:00
|
|
|
pathToHelpFile = path.join(pathToCurrentDir, "../src/data/help.json")
|
2024-11-12 20:13:13 -05:00
|
|
|
# man page section
|
|
|
|
manSection = 1
|
|
|
|
# title (center header)
|
2024-11-13 10:09:36 +08:00
|
|
|
titlePage = "Fastfetch man page"
|
2024-11-12 20:13:13 -05:00
|
|
|
# date (center footer)
|
2024-11-15 00:50:47 +00:00
|
|
|
# format : "Month (abbreviation) Day Year"
|
2024-11-23 23:22:57 -03:00
|
|
|
todayDate = datetime.fromtimestamp(
|
|
|
|
int(environ.get("SOURCE_DATE_EPOCH", time())),
|
|
|
|
tz=timezone.utc,
|
|
|
|
).strftime("%b %d %Y")
|
2024-11-12 20:13:13 -05:00
|
|
|
# file to fastfetch version (left footer)
|
2024-11-13 10:09:36 +08:00
|
|
|
pathToVersionFile = path.join(pathToCurrentDir, "../CMakeLists.txt")
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
###### Sections Text ######
|
|
|
|
|
|
|
|
# text displayed in the "NAME" section
|
2024-11-13 10:09:36 +08:00
|
|
|
nameSection = r"fastfetch \- A maintained, feature\-rich and performance oriented, neofetch like system information tool"
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
# text displayed at the beginning of the "OPTIONS" section
|
2024-11-13 10:09:36 +08:00
|
|
|
optionSection = r"""
|
|
|
|
Parsing is not case sensitive. E.g. \fB--logo-type\fR is
|
|
|
|
equal to \fB--LOGO-TYPE\fR.
|
|
|
|
|
2024-12-13 16:05:25 +08:00
|
|
|
If a value is between square brackets, it is optional.
|
2024-11-13 10:09:36 +08:00
|
|
|
An optional boolean value defaults to true if not specified.
|
|
|
|
|
|
|
|
More detailed help messages for each options can be printed
|
|
|
|
with \fB-h <option_without_dash_prefix>\fR.
|
|
|
|
|
|
|
|
All options can be made permanent with command
|
|
|
|
\fBfastfetch <options> --gen-config\fR.
|
|
|
|
"""
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
# text displayed in the "CONFIGURATION"
|
2024-11-13 10:09:36 +08:00
|
|
|
configurationSection = f"""
|
|
|
|
.SS Fetch Structure
|
|
|
|
|
|
|
|
The structure of a fetch describes the modules that should
|
|
|
|
be included in the output. It consists of a string of modules,
|
|
|
|
separated by a colon (:). To list all available modules,
|
|
|
|
use --list-modules.
|
|
|
|
|
|
|
|
|
|
|
|
.SS Config Files
|
|
|
|
|
|
|
|
Fastfetch uses JSONC based format for configuration.
|
|
|
|
Fastfetch doesn't generate config file automatically;
|
|
|
|
it should be generated manually by {startBold}--gen-config{endBold}.
|
|
|
|
The config file will be saved in
|
|
|
|
{startBold}~/.config/fastfetch/config.jsonc{endBold} by default.
|
|
|
|
|
|
|
|
A JSONC config file is a JSON file that also supports comments
|
|
|
|
with (// and /* */). Those files must have the extension '.jsonc'.
|
|
|
|
|
|
|
|
The specified configuration/preset files are searched in the following order:
|
|
|
|
|
|
|
|
{startBold}1.{endBold} relative to the current working directory
|
|
|
|
|
|
|
|
{startBold}2.{endBold} relative to ~/.local/share/fastfetch/presets/
|
|
|
|
|
|
|
|
{startBold}3.{endBold} relative to /usr/share/fastfetch/presets/
|
|
|
|
|
|
|
|
Fastfetch provides some default presets. List them with --list-presets.
|
|
|
|
"""
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
# text displayed in the "EXAMPLE" section
|
2024-11-13 10:09:36 +08:00
|
|
|
exampleSection = """
|
|
|
|
.SS Config files:
|
|
|
|
.nf
|
|
|
|
// ~/.config/fastfetch/config.jsonc
|
|
|
|
{
|
|
|
|
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
|
|
|
|
"modules": [
|
|
|
|
"title",
|
|
|
|
"separator",
|
|
|
|
"module1",
|
|
|
|
{
|
|
|
|
"type": "module2",
|
|
|
|
"module2-option": "value"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
.fi
|
|
|
|
"""
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
# text displayed in the "BUGS" section
|
|
|
|
bugSection = "Please report bugs to : \
|
|
|
|
https://github.com/fastfetch-cli/fastfetch/issues"
|
|
|
|
|
|
|
|
# text displayed in the "WIKI" section
|
|
|
|
wikiSection = "Fastfetch github wiki : https://github.com/fastfetch-cli/fastfetch/wiki/Configuration"
|
|
|
|
|
|
|
|
|
|
|
|
###### Argument decoration ######
|
|
|
|
|
|
|
|
### optional arguments tags ###
|
|
|
|
|
|
|
|
# if an optional argument is displayed as [?optArg] (with "optArg" underlined)
|
|
|
|
# this value should be f"[?{startUnderline}"
|
|
|
|
startOptionalArgument = f"[{startUnderline}?"
|
|
|
|
# if an optional argument is displayed as [?optArg] (with "optArg underlined")
|
|
|
|
# this value should be f"{endUnderline}]"
|
2024-11-13 10:09:36 +08:00
|
|
|
endOptionalArgument = f"{endUnderline}]"
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
### mandatory arguments tags ###
|
2024-11-13 10:09:36 +08:00
|
|
|
startMandatoryArgument = f"{startUnderline}"
|
2024-11-12 20:13:13 -05:00
|
|
|
endMandatoryArgument = f"{endUnderline}"
|
|
|
|
|
2024-11-13 10:09:36 +08:00
|
|
|
def main():
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
# importing the JSON file
|
2024-11-13 10:09:36 +08:00
|
|
|
with open(pathToHelpFile, 'r') as jsonFile:
|
|
|
|
helpFileData = load(jsonFile) # json.load
|
|
|
|
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
######## Start printing the generated .1 file ########
|
|
|
|
|
|
|
|
|
|
|
|
###### header, footer & config #####
|
|
|
|
|
2024-11-13 10:09:36 +08:00
|
|
|
print(f".TH FASTFETCH {manSection} ", end=" ")
|
2024-11-12 20:13:13 -05:00
|
|
|
print(f"\"{todayDate}\"", end=" ")
|
|
|
|
|
|
|
|
# version number
|
2024-11-13 10:09:36 +08:00
|
|
|
with open(pathToVersionFile, 'r') as versionFile:
|
|
|
|
|
|
|
|
# research version number in file with regex
|
|
|
|
for line in versionFile:
|
|
|
|
researchVersion = search(r"^\s*VERSION (\d+\.\d+\.\d+)$", line)
|
|
|
|
if (researchVersion):
|
|
|
|
print(f"\"{researchVersion.group(1)}\"", end=" ")
|
|
|
|
break
|
|
|
|
|
2024-11-12 20:13:13 -05:00
|
|
|
print(f"\"{titlePage}\"")
|
|
|
|
|
|
|
|
|
|
|
|
###### Name ######
|
|
|
|
|
|
|
|
print(".SH NAME")
|
|
|
|
print(nameSection)
|
|
|
|
|
|
|
|
|
|
|
|
##### Synopsis ######
|
|
|
|
|
|
|
|
print(".SH SYNOPSIS")
|
|
|
|
print(".B fastfetch")
|
2024-11-13 10:09:36 +08:00
|
|
|
print(f"[{startUnderline}OPTIONS{endUnderline}]")\
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
###### Wiki ######
|
|
|
|
|
|
|
|
print(".SH WIKI")
|
|
|
|
print(wikiSection)
|
|
|
|
|
|
|
|
|
|
|
|
###### Configuration ######
|
|
|
|
|
|
|
|
print(".SH CONFIGURATION")
|
|
|
|
print(configurationSection)
|
|
|
|
|
|
|
|
|
|
|
|
###### Options ######
|
|
|
|
|
|
|
|
print(".SH OPTIONS")
|
|
|
|
print(optionSection)
|
|
|
|
print()
|
|
|
|
|
|
|
|
# loop through every options sections
|
|
|
|
for key, value in helpFileData.items():
|
|
|
|
|
|
|
|
# print new subsection
|
|
|
|
print(f".SS {key}:")
|
|
|
|
|
|
|
|
# loop through every option in a section
|
|
|
|
for option in value:
|
|
|
|
# list of existing keys for this option
|
|
|
|
keyList = option.keys()
|
|
|
|
|
|
|
|
# start a new "option" entry
|
|
|
|
print(".TP")
|
|
|
|
print(startBold, end="")
|
|
|
|
|
|
|
|
# short option (-opt)
|
|
|
|
if "short" in keyList:
|
2024-11-13 10:09:36 +08:00
|
|
|
print(fr"\-{ option['short'] }", end="")
|
2024-11-12 20:13:13 -05:00
|
|
|
# if also have a long option, print a comma
|
|
|
|
if "long" in keyList:
|
|
|
|
print(", ", end="")
|
|
|
|
|
|
|
|
# long option (--option)
|
|
|
|
if "long" in keyList:
|
2024-11-13 10:09:36 +08:00
|
|
|
print(fr"\-\-{ option['long'] }", end="")
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
print(endBold, end=" ")
|
2024-11-13 10:09:36 +08:00
|
|
|
|
2024-11-12 20:13:13 -05:00
|
|
|
# arguments
|
|
|
|
if "arg" in keyList:
|
|
|
|
# if argument is optional, print "[arg]"
|
|
|
|
if "optional" in option["arg"].keys() and option["arg"]["optional"]:
|
|
|
|
print(startOptionalArgument + option['arg']['type'] + endOptionalArgument, end="")
|
|
|
|
|
|
|
|
# if argument is mandatory, print "arg"
|
|
|
|
else:
|
|
|
|
print(startMandatoryArgument + option['arg']['type'] + endMandatoryArgument, end="")
|
2024-11-13 10:09:36 +08:00
|
|
|
|
2024-11-12 20:13:13 -05:00
|
|
|
# description
|
|
|
|
print(f"\n {option['desc']} \n")
|
2024-11-13 10:09:36 +08:00
|
|
|
|
2024-11-12 20:13:13 -05:00
|
|
|
|
|
|
|
###### Examples ######
|
|
|
|
|
|
|
|
print(".SH EXAMPLES")
|
|
|
|
print(exampleSection)
|
|
|
|
|
|
|
|
|
|
|
|
###### Bugs ######
|
|
|
|
|
|
|
|
print(".SH BUGS")
|
|
|
|
print(bugSection)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-11-13 10:09:36 +08:00
|
|
|
main()
|