nnn/plugins/launch

43 lines
1 KiB
Plaintext
Raw Permalink Normal View History

2019-12-08 19:04:53 +00:00
#!/usr/bin/env sh
# Description: Independent POSIX-compliant GUI application launcher.
# Fuzzy find executables in $PATH and launch an application.
# stdin, stdout, stderr are suppressed so CLI tools exit silently.
#
# To configure launch as an independent app launcher add a keybind
# to open launch in a terminal e.g.,
#
# xfce4-terminal -e "${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/launch
#
2020-05-06 13:11:01 +00:00
# Dependencies: fzf
2019-12-08 19:04:53 +00:00
#
# Usage: launch [delay]
# delay is in seconds, if omitted launch waits for 1 sec
#
# Integration with nnn: launch is installed with other plugins, nnn picks it up.
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana
2019-12-08 20:27:31 +00:00
# shellcheck disable=SC2086
2019-12-08 19:04:53 +00:00
IFS=':'
get_selection() {
if type fzf >/dev/null 2>&1; then
2019-12-09 13:06:48 +00:00
{ IFS=':'; ls -H $PATH; } | sort | fzf
2019-12-08 19:04:53 +00:00
else
exit 1
fi
}
if selection=$( get_selection ); then
setsid "$selection" 2>/dev/null 1>/dev/null &
2020-11-22 14:39:14 +00:00
if [ -n "$1" ]; then
2019-12-08 19:04:53 +00:00
sleep "$1"
else
sleep 1
fi
fi