Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
ff09151d
Unverified
Commit
ff09151d
authored
Nov 17, 2021
by
Aurora
Committed by
GitHub
Nov 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(bgnotify): avoid permission prompts by checking frontmost app ID (#10318)
Co-authored-by:
Marc Cornellà
<
hello@mcornella.com
>
parent
88e72e8a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
+21
-5
bgnotify.plugin.zsh
plugins/bgnotify/bgnotify.plugin.zsh
+21
-5
No files found.
plugins/bgnotify/bgnotify.plugin.zsh
View file @
ff09151d
...
@@ -20,6 +20,12 @@ if ! (type bgnotify_formatted | grep -q 'function'); then ## allow custom functi
...
@@ -20,6 +20,12 @@ if ! (type bgnotify_formatted | grep -q 'function'); then ## allow custom functi
}
}
fi
fi
currentAppId
()
{
if
((
$+
commands[osascript]
))
;
then
osascript
-e
'tell application (path to frontmost application as text) to id'
2>/dev/null
fi
}
currentWindowId
()
{
currentWindowId
()
{
if
hash
osascript 2>/dev/null
;
then
#osx
if
hash
osascript 2>/dev/null
;
then
#osx
osascript
-e
'tell application (path to frontmost application as text) to id of front window'
2&> /dev/null
||
echo
"0"
osascript
-e
'tell application (path to frontmost application as text) to id of front window'
2&> /dev/null
||
echo
"0"
...
@@ -32,11 +38,20 @@ currentWindowId () {
...
@@ -32,11 +38,20 @@ currentWindowId () {
bgnotify
()
{
## args: (title, subtitle)
bgnotify
()
{
## args: (title, subtitle)
if
hash
terminal-notifier 2>/dev/null
;
then
#osx
if
hash
terminal-notifier 2>/dev/null
;
then
#osx
[[
"
$TERM_PROGRAM
"
==
'iTerm.app'
]]
&&
term_id
=
'com.googlecode.iterm2'
;
local
term_id
=
"
$bgnotify_appid
"
[[
"
$TERM_PROGRAM
"
==
'Apple_Terminal'
]]
&&
term_id
=
'com.apple.terminal'
;
if
[[
-z
"
$term_id
"
]]
;
then
case
"
$TERM_PROGRAM
"
in
iTerm.app
)
term_id
=
'com.googlecode.iterm2'
;;
Apple_Terminal
)
term_id
=
'com.apple.terminal'
;;
esac
fi
## now call terminal-notifier, (hopefully with $term_id!)
## now call terminal-notifier, (hopefully with $term_id!)
[
-z
"
$term_id
"
]
&&
terminal-notifier
-message
"
$2
"
-title
"
$1
"
>
/dev/null
||
if
[[
-z
"
$term_id
"
]]
;
then
terminal-notifier
-message
"
$2
"
-title
"
$1
"
>
/dev/null
else
terminal-notifier
-message
"
$2
"
-title
"
$1
"
-activate
"
$term_id
"
-sender
"
$term_id
"
>
/dev/null
terminal-notifier
-message
"
$2
"
-title
"
$1
"
-activate
"
$term_id
"
-sender
"
$term_id
"
>
/dev/null
fi
elif
hash
growlnotify 2>/dev/null
;
then
#osx growl
elif
hash
growlnotify 2>/dev/null
;
then
#osx growl
growlnotify
-m
"
$1
"
"
$2
"
growlnotify
-m
"
$1
"
"
$2
"
elif
hash
notify-send 2>/dev/null
;
then
#ubuntu gnome!
elif
hash
notify-send 2>/dev/null
;
then
#ubuntu gnome!
...
@@ -54,6 +69,7 @@ bgnotify () { ## args: (title, subtitle)
...
@@ -54,6 +69,7 @@ bgnotify () { ## args: (title, subtitle)
bgnotify_begin
()
{
bgnotify_begin
()
{
bgnotify_timestamp
=
$EPOCHSECONDS
bgnotify_timestamp
=
$EPOCHSECONDS
bgnotify_lastcmd
=
"
${
1
:-
$2
}
"
bgnotify_lastcmd
=
"
${
1
:-
$2
}
"
bgnotify_appid
=
"
$(
currentAppId
)
"
bgnotify_windowid
=
$(
currentWindowId
)
bgnotify_windowid
=
$(
currentWindowId
)
}
}
...
@@ -62,7 +78,7 @@ bgnotify_end() {
...
@@ -62,7 +78,7 @@ bgnotify_end() {
elapsed
=
$((
EPOCHSECONDS
-
bgnotify_timestamp
))
elapsed
=
$((
EPOCHSECONDS
-
bgnotify_timestamp
))
past_threshold
=
$((
elapsed
>=
bgnotify_threshold
))
past_threshold
=
$((
elapsed
>=
bgnotify_threshold
))
if
((
bgnotify_timestamp
>
0
))
&&
((
past_threshold
))
;
then
if
((
bgnotify_timestamp
>
0
))
&&
((
past_threshold
))
;
then
if
[
$(
currentWindowId
)
!=
"
$bgnotify_windowid
"
]
;
then
if
[
[
$(
currentAppId
)
!=
"
$bgnotify_appid
"
||
$(
currentWindowId
)
!=
"
$bgnotify_windowid
"
]
]
;
then
print
-n
"
\a
"
print
-n
"
\a
"
bgnotify_formatted
"
$didexit
"
"
$bgnotify_lastcmd
"
"
$elapsed
"
bgnotify_formatted
"
$didexit
"
"
$bgnotify_lastcmd
"
"
$elapsed
"
fi
fi
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment