2017-12-05 22:39:10 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-03-23 12:29:50 -07:00
|
|
|
# Uses skim as an application launcher.
|
2017-12-05 22:39:10 -08:00
|
|
|
#
|
2018-03-23 12:29:50 -07:00
|
|
|
# Requires: skim, lnch
|
|
|
|
|
|
|
|
_do_sk() { sk --prompt='open > '; }
|
2017-12-05 22:39:10 -08:00
|
|
|
|
|
|
|
case $OSTYPE in
|
|
|
|
darwin*)
|
2018-04-29 17:49:09 -07:00
|
|
|
apps=$(find -L {,~}/Applications -iname '*.app' -maxdepth 2 -type d 2>/dev/null)
|
|
|
|
cmds=$(compgen -c 2>/dev/null)
|
|
|
|
cmd=$(printf '%s\n' "${apps[@]}" "${cmds[@]}" | sort -u | _do_sk)
|
|
|
|
if [[ -z $cmd ]]; then
|
|
|
|
exit
|
|
|
|
elif [[ $cmd == sk-* ]]; then
|
|
|
|
$cmd
|
|
|
|
else
|
|
|
|
if [[ $cmd == *.app ]]; then
|
|
|
|
open "$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"
|
|
|
|
fi
|
|
|
|
fi
|
2017-12-05 22:39:10 -08:00
|
|
|
;;
|
|
|
|
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)
|
2017-12-31 22:33:49 -08:00
|
|
|
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
|
2017-12-05 22:39:10 -08:00
|
|
|
$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
|