Skip to content

Commit 6f4fe8f

Browse files
committed
grimshot: add notify action to open file or directory
If grimshot is called with --notify and the file was saved to disk, provide two notification actions to open the file or the containing directory. Use xdg-open to open the file/directory, so also add that to the check command.
1 parent e736288 commit 6f4fe8f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

grimshot/grimshot

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ any() {
4242
return 0
4343
fi
4444
done
45-
return 1 # No conditions matched
45+
return 1 # No conditions matched
4646
}
4747

4848
NOTIFY=no
@@ -121,15 +121,24 @@ printUsageMsg() {
121121
}
122122

123123
notify() {
124-
notify-send -t 3000 -a grimshot "$@"
124+
if [ "$ACTION" = "copy" ]; then
125+
notify-send -t 3000 -a grimshot "$@"
126+
else
127+
action=$(notify-send -t 3000 -a grimshot --action=file='Open File' --action=dir='Open Directory' "$@")
128+
if [ "$action" = "file" ]; then
129+
xdg-open "$FILE"
130+
elif [ "$action" = "dir" ]; then
131+
xdg-open "$(dirname "$FILE")"
132+
fi
133+
fi
125134
}
126135

127136
notifyOk() {
128137
notify_disabled='[ "$NOTIFY" = "no" ]'
129138
action_involves_saving='[ "$ACTION" = "save" ] || [ "$ACTION" = "savecopy" ]'
130139

131140
if eval $notify_disabled; then
132-
return
141+
return
133142
fi
134143

135144
TITLE=${2:-"Screenshot"}
@@ -193,6 +202,7 @@ checkRequiredTools() {
193202
check wl-copy
194203
check jq
195204
check notify-send
205+
check xdg-open
196206
exit
197207
}
198208

0 commit comments

Comments
 (0)