Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a Manpage #45

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Features:
- *On average, shotgun is more than twice as fast as maim*

## Usage
See the man page: `docs/shotgun.1`.

```
Usage: shotgun [options] [file]
Expand Down
29 changes: 29 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::path::Path;
use std::process::Command;
use std::{str, env, fs};

fn main() {
add_manpage("shotgun.1");

let git_version = Command::new("git").arg("describe").arg("--tags").output();
if let Ok(git_version) = git_version {
if git_version.status.success() {
Expand All @@ -10,3 +14,28 @@ fn main() {
}
}
}

fn add_manpage(manpage: &str) {
let manpage_source_path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("docs/").join(manpage);

let root_path: String = match env::var("CARGO_INSTALL_ROOT") {
Ok(r) => r,
Err(_) => env::var("HOME").unwrap() + "/.cargo/",
};
let destination_path = root_path + "man/man1/";

let manpath = Command::new("manpath").output().expect("Couldn't run \"manpath\"").stdout;
let manpath_parsed = str::from_utf8(&manpath).unwrap(); // could next check $MANPATH, but if the manpath command
// doesn't exsist that probably wont either. It's likely
// they don't have man installed.
if !manpath_parsed.contains(&destination_path) {
println!("cargo:warning=Looks like \"{}\" isn't on your manpath, to see the man page please add it. See `man manpath`", destination_path);
}

let mut dir_builder = fs::DirBuilder::new();
dir_builder.recursive(true);
dir_builder.create(&destination_path).expect("Failed to create manpage's parent directories.");
fs::copy(manpage_source_path, destination_path.clone() + manpage).expect(&format!("Failed to install manpage to {}", destination_path));

}

39 changes: 39 additions & 0 deletions docs/shotgun.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.TH SHOTGUN 1 "08/31/2023" "2.5.1" "User Commands"
.SH SHOTGUN
shotgun \- Minimal X screenshot utility
.SH SYNOPSIS
shotgun [\fIOPTIONS\fP] [\fIFILE\fP]
.SH DESCRIPTION
A minimal screenshot utility for X11.
.SS SUPPORTS
.TP
Exporting to PNG/STDOUT
.TP
Masksing off-screen areas on multi-head setups
.TP
Selecting by window ID and geometry
.SS OPTIONS
.TP
\fB-i, --id\fP ID
Window to capture
.TP
\fB-g, --geometry\fP WxH+X+Y
Area to capture
.TP
\fB-f, --format\fP
Either png/pam as output format
.TP
\fB-s, --screen\fP
Capture the current screen
.TP
\fB-h, --help\fP
Print help and exit
.TP
\fB-v, --version\fP
Print version and exit
.SH FILE
\fIfile\fP can be either a file name of which you would like to save the image to, or when using the "-" charicter as the file name it will pipe the image to STDOUT.
.SH AUTHOR
neXromancers
.SH BUGS
Please report bugs here: https://github.com/neXromancers/shotgun/issues
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod xwrap;
use crate::xwrap::Display;

fn usage(progname: &str, opts: getopts::Options) {
let brief = format!("Usage: {progname} [options] [file]");
let brief = format!("Usage: {progname} [options] [file]\nNote: use - as [file] for stdout");
let usage = opts.usage(&brief);
eprint!("{usage}");
}
Expand Down