forked from jessarcher/zsh-artisan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplease.plugin.zsh
61 lines (50 loc) · 1.76 KB
/
please.plugin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#--------------------------------------------------------------------------
# Statamic please plugin for zsh
#--------------------------------------------------------------------------
#
# This plugin adds an `please` shell command that will find and execute
# Statamic's please command from anywhere within the project. It also
# adds shell completions that work anywhere please can be located.
function please() {
_please=`_please_find`
if [ "$_please" = "" ]; then
>&2 echo "zsh-please: You seem to have upset the delicate internal balance of my housekeeper."
return 1
fi
_please_start_time=`date +%s`
php $_please $*
_please_exit_status=$? # Store the exit status so we can return it later
if [[ $1 = "make:"* && $PLEASE_OPEN_ON_MAKE_EDITOR != "" ]]; then
# Find and open files created by please
_please_laravel_path=`dirname $_please`
find \
"$_please_laravel_path/app" \
"$_please_laravel_path/tests" \
"$_please_laravel_path/database" \
-type f \
-newermt "-$((`date +%s` - $_please_start_time + 1)) seconds" \
-exec $PLEASE_OPEN_ON_MAKE_EDITOR {} \; 2>/dev/null
fi
return $_please_exit_status
}
compdef _please_add_completion please
function _please_find() {
# Look for please up the file tree until the root directory
dir=.
until [ $dir -ef / ]; do
if [ -f "$dir/please" ]; then
echo "$dir/please"
return 0
fi
dir+=/..
done
return 1
}
function _please_add_completion() {
if [ "`_please_find`" != "" ]; then
compadd `_please_get_command_list`
fi
}
function _please_get_command_list() {
please --raw --no-ansi list | sed "s/[[:space:]].*//g"
}