tags:

views:

104

answers:

2

I have the following code which should put programs startable in Bash.

if [ "`uname`" = "Darwin" ]; then
   compctl -f -x 'p[2]' -s "`/bin/ls -d1 /Applications/*/*.app
/Application:/*.app | sed 's|^.*/\([^/]*\)\.app.*|\\1|;s/ /\\\\ /g'`"                 
-- open
   alias run='open -a' 
fi

However, it does not work in my Zsh at all. I can open no programs with it.

Another bug which it has is that it opens all programs. I want have only programs startable which permissions is 700.

I know that you can search these programs rather well by

 find -perm 700 -type f *.app

However, I could not get my find -command work exactly for each program file. This suggests me that there may be a better way to make programs startable in terminal.

How can you make programs startable in Zsh in Mac/Ubuntu?

+2  A: 

Oh, zsh. That always makes things interesting.

But there are certain techniques to make debugging these sorts of things easier. The first thing I would so is move away from ls, and use find instead, since you want pathnames, not human-readable listings:

find . -executable -a -name \*.app

perhaps....

Curt Sampson
+2  A: 

How do you feel about aliases instead of completion? The aliases still tab complete. Splitting across lines to make it easier to read...

`print -l /Applications/**/MacOS/*(*f:700:) | 
grep -v "Contents.*Contents" | 
sed -e "s#\(.*/\)\([^./]*\)\(\.app\)\(.*\)#alias \2=\"\1\2\3\4\"#g"`

The first prints each match on its own line, the second removes sub-packages of an app, and the last generates the alias command. Remove the backticks to see and confirm the commands that are generated.

[Edit:] This runs the executable directly - if you prefer to use the 'open blah.app' method, you could change the final portion of the sed command to:

#alias \2=\"open \1\2\3\"#
JimG