aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Meißelbach <arbelzapf@gmail.com>2021-01-21 21:59:27 +0100
committerMoritz Meißelbach <arbelzapf@gmail.com>2021-01-21 21:59:27 +0100
commit0c6cc8103834f6ac3ec91cbec2e5eae69fd2a9e4 (patch)
treea019cb4538290242cc4713edbb16aeb768b69ed9
parentc741cb2dcd60b84e3f3ca8eeb7a9a64ad14b26d1 (diff)
downloadsway-launcher-desktop-0c6cc8103834f6ac3ec91cbec2e5eae69fd2a9e4.tar.gz
sway-launcher-desktop-0c6cc8103834f6ac3ec91cbec2e5eae69fd2a9e4.zip
#33 Only print resulting command if the output is being redirected
-rw-r--r--README.md9
-rwxr-xr-xsway-launcher-desktop.sh13
2 files changed, 18 insertions, 4 deletions
diff --git a/README.md b/README.md
index e69d22f..07ef6a5 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,15 @@ You can override the default icons/glyphs by setting the appropriate GLYPH_ vari
set $menu exec $term --class=launcher -e env GLYPH_COMMAND="" GLYPH_DESKTOP="" GLYPH_PROMPT="? " sway-launcher
```
+By default, the launcher will use a generic & WM-agnostic command to launch the selected program.
+However, it will detect if its output is being piped to another program and merely print
+the selected command in that case - instead of launching it by itself. You can use this to integrate the launcher with other tools.
+For example, if you wish to launch your programs with `swaymsg exec`, you can do that like this:
+
+```shell
+ swaymsg exec "$(./sway-launcher-desktop.sh)"
+```
+
### Setup a Terminal command
Some of your desktop entries will probably be TUI programs that expect to be launched in a new terminal window. Those entries have the `Terminal=true` flag set and you need to tell the launcher which terminal emulator to use. Pass the `TERMINAL_COMMAND` environment variable with your terminal startup command to the script to use your preferred terminal emulator. The script will default to `$TERM -e`
diff --git a/sway-launcher-desktop.sh b/sway-launcher-desktop.sh
index e58c053..351aaa5 100755
--- a/sway-launcher-desktop.sh
+++ b/sway-launcher-desktop.sh
@@ -5,7 +5,7 @@
shopt -s nullglob globstar
set -o pipefail
if ! { exec 0>&3; } 1>/dev/null 2>&1; then
- exec 3>/dev/null # If file descriptor 3 is unused in parent shell, output to /dev/null
+ exec 3>/dev/null # If file descriptor 3 is unused in parent shell, output to /dev/null
fi
# shellcheck disable=SC2154
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
@@ -293,6 +293,11 @@ readarray -d ${DEL} -t PROVIDER_ARGS <<<${PROVIDERS[${PARAMS[1]}]}
COMMAND=${PROVIDER_ARGS[2]//\{1\}/${PARAMS[0]}}
COMMAND=${COMMAND//\{2\}/${PARAMS[3]}}
COMMAND=${COMMAND%%[[:space:]]}
-echo "Launching command: ${COMMAND}" >&3
-setsid /bin/sh -c "${COMMAND}" >& /dev/null < /dev/null &
-sleep 0.01
+
+if [ -t 1 ]; then
+ echo "Launching command: ${COMMAND}" >&3
+ setsid /bin/sh -c "${COMMAND}" >&/dev/null </dev/null &
+ sleep 0.01
+else
+ echo "${COMMAND}"
+fi