diff --git a/README.md b/README.md index 3fa4bb4..7415207 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ If arguments are given, outputs the title of each arguments, otherwise outputs t xtitle [-h|-v|-s|-e|-i|-f FORMAT|-t NUMBER] [WID ...] # Options -- `-h` — Print the synopsis to standard output and exit. +- `-h` — Print usage information to standard output and exit. - `-v` — Print the version to standard output and exit. - `-s` — Activate the *snoop* mode. - `-e` — Escape the following characters: ', " and \\. diff --git a/xtitle.c b/xtitle.c index a11be4e..850ad25 100644 --- a/xtitle.c +++ b/xtitle.c @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "hvseif:t:")) != -1) { switch (opt) { case 'h': - printf("xtitle [-h|-v|-s|-e|-i|-f FORMAT|-t NUMBER] [WID ...]\n"); + print_usage(); goto end; break; case 'v': @@ -137,6 +137,26 @@ int main(int argc, char *argv[]) return ret; } +void print_usage() +{ + printf("%s", + "Description:\n" + " Output title of WID(s) or focused window\n\n" + "Synopsis:\n" + " xtitle [-h|-v|-s|-e|-i|-f FORMAT|-t NUMBER] [WID ...]\n\n" + "Options:\n" + " -h Print usage information to standard output and exit.\n" + " -v Print version to standard output and exit.\n" + " -s Snoop mode.\n" + " -e Escape the following characters: ', \" and \\.\n" + " -i Try to retrieve the title from the _NET_WM_VISIBLE_NAME atom.\n" + " -f FORMAT Use the given printf-style format.\n" + " Supported sequences are %s (for title), %u (for window id) and \\n.\n" + " -t NUMBER Truncate the title after |NUMBER| characters,\n" + " starting at the first (or the last if negative) character.\n" + ); +} + bool setup(void) { dpy = xcb_connect(NULL, &default_screen); @@ -331,3 +351,4 @@ void hold(int sig) running = false; } } + diff --git a/xtitle.h b/xtitle.h index f69f58b..bd436f1 100644 --- a/xtitle.h +++ b/xtitle.h @@ -12,6 +12,7 @@ int default_screen; xcb_window_t root; bool running, visible; +void print_usage(); bool setup(void); wchar_t* expand_escapes(const wchar_t *src); void output_title(xcb_window_t win, wchar_t *format, bool escaped, int truncate);