Improve --online
This commit is contained in:
parent
34aa284462
commit
86cc1f58b2
2 changed files with 13 additions and 9 deletions
18
ndrop
18
ndrop
|
@ -29,7 +29,8 @@ print_help() {
|
||||||
echo " a new instance is launched instead."
|
echo " a new instance is launched instead."
|
||||||
echo ""
|
echo ""
|
||||||
echo " -o, --online"
|
echo " -o, --online"
|
||||||
echo " Wait until internet connectivity is established."
|
echo " Delay initial launch for up to 20 seconds"
|
||||||
|
echo " until internet connectivity is established."
|
||||||
echo ""
|
echo ""
|
||||||
echo " -v, --verbose"
|
echo " -v, --verbose"
|
||||||
echo " Show notifications regarding the matching process."
|
echo " Show notifications regarding the matching process."
|
||||||
|
@ -68,8 +69,8 @@ partial_match() {
|
||||||
CLASS=$(niri msg --json windows | jq -r ".[] | select((.app_id |match(\"$1\";\"i\"))) | .app_id" | head -1)
|
CLASS=$(niri msg --json windows | jq -r ".[] | select((.app_id |match(\"$1\";\"i\"))) | .app_id" | head -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_online=0
|
|
||||||
wait_online() {
|
wait_online() {
|
||||||
|
wait_online=0
|
||||||
while [[ $wait_online -lt 200 ]]; do
|
while [[ $wait_online -lt 200 ]]; do
|
||||||
ping -qc 1 -w 20 -i 0.1 github.com && break
|
ping -qc 1 -w 20 -i 0.1 github.com && break
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
|
@ -149,6 +150,9 @@ case "$1" in
|
||||||
epiphany)
|
epiphany)
|
||||||
CLASS="org.gnome.Epiphany"
|
CLASS="org.gnome.Epiphany"
|
||||||
;;
|
;;
|
||||||
|
brave)
|
||||||
|
CLASS="brave-browser"
|
||||||
|
;;
|
||||||
foot)
|
foot)
|
||||||
OPT=$(getopt --options a: --longoptions app-id: -n ndrop -- "$@")
|
OPT=$(getopt --options a: --longoptions app-id: -n ndrop -- "$@")
|
||||||
;;
|
;;
|
||||||
|
@ -169,7 +173,7 @@ tor-browser)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if $VERBOSE && [[ $1 -ne $CLASS ]]; then notify_low "ndrop: Using '$CLASS' as hardcoded classname of '$1' for matching"; fi
|
if $VERBOSE && [[ $1 != "$CLASS" ]]; then notify_low "ndrop: Using '$CLASS' as hardcoded classname of '$1' for matching"; fi
|
||||||
|
|
||||||
if [[ -n $OPT ]]; then
|
if [[ -n $OPT ]]; then
|
||||||
eval set -- "$OPT" # remove leading whitespace
|
eval set -- "$OPT" # remove leading whitespace
|
||||||
|
@ -181,7 +185,7 @@ if [[ -n $OPT ]]; then
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $INSENSITIVE && [[ $(niri msg --json windows | jq -r ".[] | select((.app_id |test(\"$CLASS\";\"i\")))") ]]; then
|
if $INSENSITIVE && [[ -n $(niri msg --json windows | jq -r ".[] | select((.app_id |test(\"$CLASS\";\"i\")))") ]]; then
|
||||||
if $VERBOSE; then notify_low "ndrop: --insensitive -> Insensitive (partial) match of class '$CLASS' successful"; fi
|
if $VERBOSE; then notify_low "ndrop: --insensitive -> Insensitive (partial) match of class '$CLASS' successful"; fi
|
||||||
CLASS=$(niri msg --json windows | jq -r ".[] | select((.app_id |match(\"$CLASS\";\"i\"))) | .app_id" | head -1) || notify "ndrop: Error assigning case insensitive (partial) match to CLASS"
|
CLASS=$(niri msg --json windows | jq -r ".[] | select((.app_id |match(\"$CLASS\";\"i\"))) | .app_id" | head -1) || notify "ndrop: Error assigning case insensitive (partial) match to CLASS"
|
||||||
if $VERBOSE; then notify_low "ndrop: --insensitive -> Using class '$CLASS' after insensitive (partial) matching"; fi
|
if $VERBOSE; then notify_low "ndrop: --insensitive -> Using class '$CLASS' after insensitive (partial) matching"; fi
|
||||||
|
@ -195,7 +199,7 @@ fi
|
||||||
WINDOW_ID=$(niri msg --json windows | jq -r ".[] | select(.app_id==\"$CLASS\") | .id")
|
WINDOW_ID=$(niri msg --json windows | jq -r ".[] | select(.app_id==\"$CLASS\") | .id")
|
||||||
|
|
||||||
### OVERRIDE ###
|
### OVERRIDE ###
|
||||||
# FOCUS=true
|
FOCUS=true
|
||||||
|
|
||||||
if [[ -n $(niri msg --json windows | jq -r ".[] | select(.app_id==\"$CLASS\" and .workspace_id!=\"$ACTIVE_WORKSPACE\")") ]]; then
|
if [[ -n $(niri msg --json windows | jq -r ".[] | select(.app_id==\"$CLASS\" and .workspace_id!=\"$ACTIVE_WORKSPACE\")") ]]; then
|
||||||
if [[ $FOCUS == false ]]; then
|
if [[ $FOCUS == false ]]; then
|
||||||
|
@ -204,14 +208,14 @@ if [[ -n $(niri msg --json windows | jq -r ".[] | select(.app_id==\"$CLASS\" and
|
||||||
if $VERBOSE; then notify_low "ndrop: Matched class '$CLASS' on another workspace and moved it to current workspace"; fi
|
if $VERBOSE; then notify_low "ndrop: Matched class '$CLASS' on another workspace and moved it to current workspace"; fi
|
||||||
fi
|
fi
|
||||||
niri msg action focus-window --id "$WINDOW_ID" || notify "ndrop: Error focusing '$COMMANDLINE' on current workspace"
|
niri msg action focus-window --id "$WINDOW_ID" || notify "ndrop: Error focusing '$COMMANDLINE' on current workspace"
|
||||||
elif [[ $(niri msg --json windows | jq -r ".[] | select(.app_id==\"$CLASS\" and .workspace_id==\"$ACTIVE_WORKSPACE\")") ]]; then
|
elif [[ -n $(niri msg --json windows | jq -r ".[] | select(.app_id==\"$CLASS\" and .workspace_id==\"$ACTIVE_WORKSPACE\")") ]]; then
|
||||||
if [[ $FOCUS == false ]]; then
|
if [[ $FOCUS == false ]]; then
|
||||||
# shellcheck disable=SC2086 # integers won't be split
|
# shellcheck disable=SC2086 # integers won't be split
|
||||||
niri msg action move-window-to-workspace --window-id "$WINDOW_ID" "ndrop" || notify "ndrop: Error moving '$COMMANDLINE' to workspace 'ndrop'"
|
niri msg action move-window-to-workspace --window-id "$WINDOW_ID" "ndrop" || notify "ndrop: Error moving '$COMMANDLINE' to workspace 'ndrop'"
|
||||||
niri msg action focus-workspace "$ACTIVE_WORKSPACE"
|
niri msg action focus-workspace "$ACTIVE_WORKSPACE"
|
||||||
if $VERBOSE; then notify_low "ndrop: Matched class '$CLASS' on current workspace and moved it to workspace 'ndrop'"; fi
|
if $VERBOSE; then notify_low "ndrop: Matched class '$CLASS' on current workspace and moved it to workspace 'ndrop'"; fi
|
||||||
# else
|
# else
|
||||||
elif [[ $(niri msg --json windows | jq -r ".[] | select(.app_id==\"$CLASS\" and .workspace_id!=\"ndrop\")") ]]; then
|
elif [[ -n $(niri msg --json windows | jq -r ".[] | select(.app_id==\"$CLASS\" and .workspace_id!=\"ndrop\")") ]]; then
|
||||||
niri msg action focus-window --id "$WINDOW_ID" || notify "ndrop: Error focusing '$COMMANDLINE' on current workspace"
|
niri msg action focus-window --id "$WINDOW_ID" || notify "ndrop: Error focusing '$COMMANDLINE' on current workspace"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|
|
@ -25,8 +25,8 @@ ndrop - run, show and hide programs on niri
|
||||||
*-i, --insensitive*
|
*-i, --insensitive*
|
||||||
Case insensitive partial matching of class names. Can work as a stopgap if a running program is not recognized and a new instance is launched instead. Note: incorrect matches may occur, adding a special handling of the program to *ndrop* (hardcoded or via *-c, --class*) is preferable.
|
Case insensitive partial matching of class names. Can work as a stopgap if a running program is not recognized and a new instance is launched instead. Note: incorrect matches may occur, adding a special handling of the program to *ndrop* (hardcoded or via *-c, --class*) is preferable.
|
||||||
|
|
||||||
*-o, --online
|
*-o, --online*
|
||||||
Wait until internet connectivity is established.
|
Delay initial launch for up to 20 seconds until internet connectivity is established.
|
||||||
|
|
||||||
*-v, --verbose*
|
*-v, --verbose*
|
||||||
Show notifications regarding the matching process. Try this to figure out why running programs are not matched."
|
Show notifications regarding the matching process. Try this to figure out why running programs are not matched."
|
||||||
|
|
Loading…
Add table
Reference in a new issue