Skip to content

Commit fdcda3d

Browse files
authored
Merge pull request #1510 from fedang/ns-conform
Conform dunstify to notify-send
2 parents 3daf8a6 + a860c37 commit fdcda3d

File tree

6 files changed

+153
-23
lines changed

6 files changed

+153
-23
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ install-completions:
271271
ifneq (0,${DUNSTIFY})
272272
install: install-completions-dunstify
273273
install-completions-dunstify:
274+
install -Dm644 completions/dunstify.bashcomp ${DESTDIR}${BASHCOMPLETIONDIR}/dunstify
275+
install -Dm644 completions/_dunstify.zshcomp ${DESTDIR}${ZSHCOMPLETIONDIR}/_dunstify
274276
install -Dm644 completions/dunstify.fishcomp ${DESTDIR}${FISHCOMPLETIONDIR}/dunstify.fish
275277
endif
276278
endif
@@ -305,8 +307,10 @@ endif
305307
uninstall-completions:
306308
rm -f ${DESTDIR}${BASHCOMPLETIONDIR}/dunst
307309
rm -f ${DESTDIR}${BASHCOMPLETIONDIR}/dunstctl
310+
rm -f ${DESTDIR}${BASHCOMPLETIONDIR}/dunstify
308311
rm -f ${DESTDIR}${ZSHCOMPLETIONDIR}/_dunst
309312
rm -f ${DESTDIR}${ZSHCOMPLETIONDIR}/_dunstctl
313+
rm -f ${DESTDIR}${ZSHCOMPLETIONDIR}/_dunstify
310314
rm -f ${DESTDIR}${FISHCOMPLETIONDIR}/dunst.fish
311315
rm -f ${DESTDIR}${FISHCOMPLETIONDIR}/dunstctl.fish
312316
rm -f ${DESTDIR}${FISHCOMPLETIONDIR}/dunstify.fish

completions/_dunstify.zshcomp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#compdef _dunstify dunstify
2+
3+
# ZSH arguments completion script for the dunstify command
4+
5+
_dunstify_ids() {
6+
local -a ids
7+
ids=(${(f)"$(dunstctl history | awk '/"id" :/ {getline; getline; print $3}')"})
8+
compadd "$@" $ids
9+
}
10+
11+
local curcontext="$curcontext" ret=1
12+
local -a state line subs
13+
14+
_arguments -C \
15+
'1:opt:->opts' \
16+
'2:param:->params' \
17+
&& ret=0
18+
19+
case $state in
20+
(opts)
21+
_arguments \
22+
{-v,--version}"[Print version]" \
23+
{-?,--help}"[Show help options]" \
24+
--capabilities"[Print the server capabilities and exit]" \
25+
--serverinfo"[Print server information and exit]" \
26+
{-w,--wait}"[Block until notification is closed]" \
27+
{-p,--print-id}"[Print id, which can be used to update/replace this notification]" \
28+
{-e,--transient}"[Mark the notification as transient]" \
29+
{-u,--urgency}"[The urgency of this notification]" \
30+
{-t,--expire-time}"[Expiration time in milliseconds]" \
31+
{-a,--app-name}"[Name of your application]" \
32+
{-i,--icon}"[Name of the notification icon]" \
33+
{-I,--raw-icon}"[Path to the icon to be sent as raw image data]" \
34+
{-c,--category}"[The category of this notification]" \
35+
{-h,--hint}"[User specified hints]" \
36+
{-r,--replace-id}"[Set id of this notification]" \
37+
{-A,--action}"[Actions the user can invoke]" \
38+
{-C,--close}"[Close the notification with the specified ID]"
39+
;;
40+
41+
(params)
42+
case $line[1] in
43+
-u)
44+
local -a urgency;
45+
urgency=(
46+
"low"
47+
"normal"
48+
"critical"
49+
)
50+
_describe urgency urgency && ret=0
51+
;;
52+
53+
-I|--raw-icon)
54+
_arguments '*:file:_files' && ret=0
55+
;;
56+
57+
-r|--replace-id|-C|--close)
58+
_arguments '*:id:_dunstify_ids' && ret=0
59+
;;
60+
esac
61+
esac

completions/dunstify.bashcomp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
_dunstify() {
2+
local opts cur prev split=false
3+
_get_comp_words_by_ref cur prev
4+
COMPREPLY=()
5+
opts='-? --help \
6+
-u --urgency \
7+
-t --expire-time \
8+
-a --app-name \
9+
-i --icon \
10+
-I --raw-icon \
11+
-c --category \
12+
-e --transient \
13+
-h --hint \
14+
-p --print-id \
15+
-r --replace-id \
16+
-w --wait \
17+
-A --action \
18+
-C --close \
19+
--capabilities \
20+
--serverinfo \
21+
-v --version'
22+
23+
case "$prev" in
24+
-u|--urgency) COMPREPLY=( $( compgen -W 'low normal critical' -- "$cur") )
25+
return ;;
26+
-I|--raw-icon) _filedir
27+
return ;;
28+
esac
29+
30+
case "$cur" in
31+
*) COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) ) ;;
32+
esac
33+
} && complete -F _dunstify dunstify
34+
35+
# ex: filetype=sh

completions/dunstify.fishcomp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ else
99
end
1010

1111
complete -c dunstify -s '?' -l help -d 'Show help options'
12-
complete -c dunstify -s a -l appname -r -d 'Name of your application'
12+
complete -c dunstify -s a -l app-name -r -d 'Name of your application'
1313
complete -c dunstify -s u -l urgency -x -a 'low normal critical' -d 'The urgency of this notification'
14-
complete -c dunstify -s h -l hints -x -d 'User specified hints'
14+
complete -c dunstify -s h -l hint -x -d 'User specified hints'
1515
complete -c dunstify -s A -l action -x -d 'Actions the user can invoke'
16-
complete -c dunstify -s t -l timeout -x -d 'The time in milliseconds until the notification expires'
16+
complete -c dunstify -s t -l expire-time -x -d 'The time in milliseconds until the notification expires'
1717
complete -c dunstify -s i -l icon -x -d 'An Icon that should be displayed with the notification'
18-
complete -c dunstify -s I -l raw_icon -r -d 'Path to the icon to be sent as raw image data'
18+
complete -c dunstify -s I -l raw-icon -r -d 'Path to the icon to be sent as raw image data'
1919
complete -c dunstify -s c -l category -d 'The category of this notification'
2020
complete -c dunstify -l capabilities -d 'Print the server capabilities and exit'
21-
complete -c dunstify -s s -l serverinfo -d 'Print server information and exit'
22-
complete -c dunstify -s p -l printid -d 'Print id, which can be used to update/replace this notification'
23-
complete -c dunstify -s r -l replace -x -a '(__fish_dunstify_history)' -d 'Set id of this notification.'
21+
complete -c dunstify -l serverinfo -d 'Print server information and exit'
22+
complete -c dunstify -s p -l print-id -d 'Print id, which can be used to update/replace this notification'
23+
complete -c dunstify -s r -l replace-id -x -a '(__fish_dunstify_history)' -d 'Set id of this notification.'
2424
complete -c dunstify -s C -l close -x -a '(__fish_dunstify_history)' -d 'Close the notification with the specified ID'
25-
complete -c dunstify -s b -l block -d 'Block until notification is closed and print close reason'
25+
complete -c dunstify -s w -l wait -d 'Block until notification is closed and print close reason'
26+
complete -c dunstify -s e -l transient -d 'Mark the notification as transient'
27+
complete -c dunstify -s v -l version -d 'Print version information'
2628

2729
# ex: filetype=fish

dunstify.c

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,39 @@ static gboolean serverinfo = false;
2222
static gboolean printid = false;
2323
static guint32 replace_id = 0;
2424
static guint32 close_id = 0;
25-
static gboolean block = false;
25+
static gboolean wait = false;
2626
static gchar **rest = NULL;
27+
static gboolean transient = false;
28+
static gboolean say_version = false;
2729

2830
static GOptionEntry entries[] =
2931
{
30-
{ "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, "Name of your application", "NAME" },
3132
{ "urgency", 'u', 0, G_OPTION_ARG_STRING, &urgency_str, "The urgency of this notification", "URG" },
32-
{ "hints", 'h', 0, G_OPTION_ARG_STRING_ARRAY, &hint_strs, "User specified hints", "HINT" },
33-
{ "action", 'A', 0, G_OPTION_ARG_STRING_ARRAY, &action_strs, "Actions the user can invoke", "ACTION" },
34-
{ "timeout", 't', 0, G_OPTION_ARG_INT, &timeout, "The time in milliseconds until the notification expires", "TIMEOUT" },
33+
{ "expire-time", 't', 0, G_OPTION_ARG_INT, &timeout, "The time in milliseconds until the notification expires", "TIMEOUT" },
34+
{ "app-name", 'a', 0, G_OPTION_ARG_STRING, &appname, "Name of your application", "NAME" },
3535
{ "icon", 'i', 0, G_OPTION_ARG_STRING, &icon, "An icon that should be displayed with the notification", "ICON" },
36-
{ "raw_icon", 'I', 0, G_OPTION_ARG_STRING, &raw_icon_path, "Path to the icon to be sent as raw image data", "RAW_ICON"},
36+
{ "raw-icon", 'I', 0, G_OPTION_ARG_STRING, &raw_icon_path, "Path to the icon to be sent as raw image data", "RAW_ICON"},
3737
{ "category", 'c', 0, G_OPTION_ARG_STRING, &category, "The category of this notification", "TYPE" },
38-
{ "capabilities", 0, 0, G_OPTION_ARG_NONE, &capabilities, "Print the server capabilities and exit", NULL },
39-
{ "serverinfo", 's', 0, G_OPTION_ARG_NONE, &serverinfo, "Print server information and exit", NULL },
40-
{ "printid", 'p', 0, G_OPTION_ARG_NONE, &printid, "Print id, which can be used to update/replace this notification", NULL },
41-
{ "replace", 'r', 0, G_OPTION_ARG_INT, &replace_id, "Set id of this notification.", "ID" },
38+
{ "transient", 'e', 0, G_OPTION_ARG_INT, &transient, "Mark the notification as transient", NULL },
39+
{ "hint", 'h', 0, G_OPTION_ARG_STRING_ARRAY, &hint_strs, "User specified hints", "TYPE:NAME:VALUE" },
40+
{ "print-id", 'p', 0, G_OPTION_ARG_NONE, &printid, "Print id, which can be used to update/replace this notification", NULL },
41+
{ "replace-id", 'r', 0, G_OPTION_ARG_INT, &replace_id, "Set id of this notification", "ID" },
42+
{ "wait", 'w', 0, G_OPTION_ARG_NONE, &wait, "Block until notification is closed and print close reason", NULL },
43+
{ "action", 'A', 0, G_OPTION_ARG_STRING_ARRAY, &action_strs, "Actions the user can invoke", "ACTION" },
4244
{ "close", 'C', 0, G_OPTION_ARG_INT, &close_id, "Close the notification with the specified ID", "ID" },
43-
{ "block", 'b', 0, G_OPTION_ARG_NONE, &block, "Block until notification is closed and print close reason", NULL },
44-
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &rest, NULL, NULL },
45+
46+
// Legacy names
47+
{ "hints", 0, 0, G_OPTION_ARG_STRING_ARRAY, &hint_strs, "Legacy alias of '--hint'", "HINT" },
48+
{ "timeout", 0, 0, G_OPTION_ARG_INT, &timeout, "Legacy alias of '--expire-time'", "TIMEOUT" },
49+
{ "printid", 0, 0, G_OPTION_ARG_NONE, &printid, "Legacy alias of '--print-id'", NULL },
50+
{ "replace", 0, 0, G_OPTION_ARG_INT, &replace_id, "Legacy alias of '--replace-id'", "ID" },
51+
{ "block", 'b', 0, G_OPTION_ARG_NONE, &wait, "Legacy alias of '--wait'", NULL },
52+
{ "raw_icon", 0, 0, G_OPTION_ARG_STRING, &raw_icon_path, "Legacy alias of '--raw-icon'", NULL },
53+
54+
{ "capabilities", 0, 0, G_OPTION_ARG_NONE, &capabilities, "Print the server capabilities and exit", NULL },
55+
{ "serverinfo", 0, 0, G_OPTION_ARG_NONE, &serverinfo, "Print server information and exit", NULL },
56+
{ "version", 'v', 0, G_OPTION_ARG_NONE, &say_version, "Print version information and exit", NULL },
57+
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &rest, NULL, NULL },
4558
{ NULL }
4659
};
4760

@@ -80,6 +93,11 @@ void print_serverinfo(void)
8093
spec_version);
8194
}
8295

96+
void print_version(void)
97+
{
98+
printf("dunstify (shipped with Dunst %s)\n", VERSION);
99+
}
100+
83101
/*
84102
* Glib leaves the option terminator "--" in the argv after parsing in some
85103
* cases. This function gets the specified argv element ignoring the first
@@ -131,6 +149,11 @@ void parse_commandline(int argc, char *argv[])
131149
die(0);
132150
}
133151

152+
if (say_version) {
153+
print_version();
154+
die(0);
155+
}
156+
134157
if (*appname == '\0') {
135158
g_printerr("Provided appname was empty\n");
136159
die(1);
@@ -280,6 +303,9 @@ int main(int argc, char *argv[])
280303
if (category != NULL)
281304
notify_notification_set_category(n, category);
282305

306+
if (transient)
307+
notify_notification_set_hint(n, "transient", g_variant_new_boolean(TRUE));
308+
283309
GError *err = NULL;
284310

285311
if (raw_icon_path) {
@@ -309,7 +335,7 @@ int main(int argc, char *argv[])
309335

310336
GMainLoop *l = NULL;
311337

312-
if (block || action_strs) {
338+
if (wait || action_strs) {
313339
l = g_main_loop_new(NULL, false);
314340
g_signal_connect(n, "closed", G_CALLBACK(closed), NULL);
315341
}
@@ -336,12 +362,12 @@ int main(int argc, char *argv[])
336362
fflush(stdout);
337363
}
338364

339-
if (block || action_strs)
365+
if (wait || action_strs)
340366
g_main_loop_run(l);
341367

342368
g_object_unref(G_OBJECT (n));
343369

344370
die(0);
345371
}
346372

347-
/* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */
373+
/* vim: set ft=c tabstop=4 shiftwidth=4 expandtab textwidth=0: */

test/test-install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ testprefix/bin/dunstctl
3333
testprefix/bin/dunstify
3434
testprefix/share/bash-completion/completions/dunst
3535
testprefix/share/bash-completion/completions/dunstctl
36+
testprefix/share/bash-completion/completions/dunstify
3637
testprefix/share/fish/vendor_completions.d/dunst.fish
3738
testprefix/share/fish/vendor_completions.d/dunstctl.fish
3839
testprefix/share/fish/vendor_completions.d/dunstify.fish
@@ -42,6 +43,7 @@ testprefix/share/man/man1/dunstify.1
4243
testprefix/share/man/man5/dunst.5
4344
testprefix/share/zsh/site-functions/_dunst
4445
testprefix/share/zsh/site-functions/_dunstctl
46+
testprefix/share/zsh/site-functions/_dunstify
4547
EOF
4648

4749
do_make uninstall

0 commit comments

Comments
 (0)