shell/sk/sk-apps: include PATH executables on MacOS

This commit is contained in:
Henrik Lissner 2018-04-29 20:49:09 -04:00
parent a13654a6d0
commit d3654fc219
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -8,8 +8,25 @@ _do_sk() { sk --prompt='open > '; }
case $OSTYPE in case $OSTYPE in
darwin*) darwin*)
cmd=$(find -L {,~}/Applications -iname '*.app' -maxdepth 2 -type d 2>/dev/null | sort -u | _do_sk) apps=$(find -L {,~}/Applications -iname '*.app' -maxdepth 2 -type d 2>/dev/null)
[[ -n $cmd ]] && open "$cmd" 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
;; ;;
linux*) 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 | _do_sk) 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)