helm/shell/+fzf/bin/fzf-apps

36 lines
1.2 KiB
Plaintext
Raw Normal View History

2017-04-24 23:37:11 -07:00
#!/usr/bin/env bash
# Uses fzf as an application launcher.
#
# Requires: fzf, lnch
case $OSTYPE in
darwin*)
2017-04-26 11:53:47 -07:00
cmd=$(find -L {,~}/Applications -iname '*.app' -maxdepth 2 -type d 2>/dev/null | sort -u | gui-fzf)
2017-04-24 23:37:11 -07:00
[[ $cmd ]] && open "$cmd"
;;
linux*)
cmd=$(echo -n "$PATH" | xargs -d: -I{} -r -- find -L {} -maxdepth 1 -mindepth 1 -type f -executable -printf '%P\n' 2>/dev/null | sort -u | gui-fzf)
if [[ $cmd ]]; then
if [[ $cmd == fzf-* ]]; then
$cmd
else
if ! which lnch >/dev/null; then
notify-send 'lnch is not installed' 'run "go get github.com/oem/lnch"'
exit 1
fi
# This disowns the subprocess from the parent shell (i.e. if
# that shell gets closed, the subprocess will survive).
2017-04-24 23:37:11 -07:00
lnch "$cmd"
# OPTIONAL: requires bin/tmux
if command -v 'tmux-session-name' >/dev/null; then
# If this was used from a scratch tmux terminal, close it
[[ "$(tmux-session-name)" == scratch ]] && tmux kill-session -t scratch
fi
2017-04-24 23:37:11 -07:00
fi
fi
;;
esac