nnn/plugins/launch

45 lines
1.1 KiB
Text
Raw Normal View History

2019-12-09 00:34:53 +05:30
#!/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
#
2019-12-09 18:36:48 +05:30
# Requires: fzf/fzy
2019-12-09 00:34:53 +05:30
#
# 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-09 01:57:31 +05:30
# shellcheck disable=SC2086
2019-12-09 00:34:53 +05:30
IFS=':'
get_selection() {
if which fzf >/dev/null 2>&1; then
2019-12-09 18:36:48 +05:30
{ IFS=':'; ls -H $PATH; } | sort | fzf
2019-12-09 00:34:53 +05:30
elif which fzy >/dev/null 2>&1; then
2019-12-09 07:43:20 +05:30
{ IFS=':'; ls -H $PATH; } | sort | fzy
2019-12-09 00:34:53 +05:30
else
exit 1
fi
}
if selection=$( get_selection ); then
setsid "$selection" 2>/dev/null 1>/dev/null &
if ! [ -z "$1" ]; then
sleep "$1"
else
sleep 1
fi
fi