helm/shell/sk/bin/sk-apps

36 lines
1.1 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
2018-03-23 12:29:50 -07:00
# Uses skim as an application launcher.
#
2018-03-23 12:29:50 -07:00
# Requires: skim, lnch
_do_sk() { sk --prompt='open > '; }
case $OSTYPE in
darwin*)
2018-03-23 12:29:50 -07:00
cmd=$(find -L {,~}/Applications -iname '*.app' -maxdepth 2 -type d 2>/dev/null | sort -u | _do_sk)
[[ -n $cmd ]] && open "$cmd"
;;
linux*)
2018-03-23 12:29:50 -07:00
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 | _do_sk)
if [[ -z $cmd ]]; then
2018-01-23 21:57:03 -08:00
exit
2018-03-23 12:29:50 -07:00
elif [[ $cmd == sk-* ]]; then
$cmd
elif ! command -v lnch >/dev/null; then
>&2 echo "lnch not installed, run 'go get github.com/oem/lnch'"
exit 1
else
# disowns the subprocess from the parent shell (i.e. if that shell gets
# closed, the subprocess will survive).
lnch "$cmd"
# OPTIONAL: requires shell/+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
fi
;;
esac