-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlbf.fish
executable file
·101 lines (88 loc) · 2.83 KB
/
lbf.fish
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env fish
# see if we were called naked
if [ -z "$argv[1]" ]
local-cli
exit
end
# see if we wanted help
if test $argv[1] = 'help'
local-cli help
exit
end
# ensure that Local is running before we attempt to do anything with it
begin
pgrep Local
end &>/dev/null
if test $status = 1 # Local isn't running
open -g /Applications/Local.app/
sleep 5
osascript -e 'tell application "System Events" to set visible of process "Local" to false'
end
# see if we wanted to list sites
if test $argv[1] = 'list-sites'
local-cli list-sites
exit
end
# get site from Local's sites.json file
set JQCMD (echo '.[] | select( .path as $jqpath | "'$PWD'" | startswith($jqpath))')
set SITE_JSON (jq $JQCMD ~/Library/Application\ Support/Local/sites.json)
# all remaining functions only make sense within Local site folders
# if not in a site folder the site json will be enpty
if [ -z "$SITE_JSON" ]
echo "This is not a Local site's folder."
exit
end
# now that we know we have a single site get that site's id
set SITE_ID (echo $SITE_JSON | jq -r '.id')
# check for custom restart command
# TODO: remove once local-cli introduces this
if test $argv[1] = 'restart'
local-cli 'stop-site' $SITE_ID
local-cli 'start-site' $SITE_ID
exit
end
# see if we were asked to launch the site
# TODO: remove once local-cli introduces this
if test $argv[1] = 'open'
set HOSTNAME (echo $SITE_JSON | jq -r '.domain')
open "http://$HOSTNAME"
exit
end
# return the url of the site (note, always returns http)
if test $argv[1] = 'url'
set HOSTNAME (echo $SITE_JSON | jq -r '.domain')
echo "http://$HOSTNAME"
exit
end
# open the database in TablePlus
# currently in alpha status and not working.
# see https://github.com/TablePlus/TablePlus/issues/3151
if test $argv[1] = 'db'
set DB_USER (echo $SITE_JSON | jq -r '.mysql.user')
set DB_PASS (echo $SITE_JSON | jq -r '.mysql.password')
set SITE_NAME (echo $SITE_JSON | jq -r '.name')
open "mysql://$DB_USER:$DB_PASS@$HOME/Library/Application%20Support/Local/run/$SITE_ID/mysql/mysqld.sock/local?enviroment=local&safeModeLevel=0&advancedSafeModeLevel=0&name=$SITE_NAME"
exit
end
# keep a dying site alive
if test $argv[1] = 'keepalive'
set HOSTNAME (echo $SITE_JSON | jq -r '.domain')
set SITE_URL "http://"$HOSTNAME
set KEEPALIVE ~/.tg-site-keepalive-$HOSTNAME
while true
curl -I --silent $SITE_URL >$KEEPALIVE &
sleep 3
if test -s $KEEPALIVE
rm $KEEPALIVE
echo -ne '\r'(date)' '
sleep 10
else
echo -e "\r----------- "(date)" -----------"
local-cli 'stop-site' $SITE_ID
local-cli 'start-site' $SITE_ID
end
end
exit
end
# run the specified local-cli command with the found site id
local-cli $argv[1] $SITE_ID