-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBashrc
186 lines (141 loc) · 7.1 KB
/
Bashrc
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$_}" )" &> /dev/null && pwd )
# Source this file from your project home directory to get
# some convenience aliases that can be listed with "esp_help".
# This file can be sourced from bash and also from zsh, which is
# popular on MacOS.
# if CH_HOME is not set, default to the directory that this Bashrc is in
if [[ "$CH_HOME" == "" ]]; then
export CH_HOME=${_DIR}
fi
if [ ! -f $CH_HOME/make/cpphash.mk ]; then
echo "$CH_HOME not found. Did you run install.sh?"
return 1
fi
if [[ "$CH_BUILD" == "" ]]; then
export CH_BUILD="build"
fi
if [[ "$ESPMAKE_PREFIX" == "" ]]; then
ESPMAKE_PREFIX="esp_"
fi
if [[ "$ESPMAKE_PRJ_HOME" == "" ]]; then
ESPMAKE_PRJ_HOME="$(pwd)"
fi
if [[ "$ESPMAKE_PRJ_LAST" == "" ]]; then
ESPMAKE_PRJ_LAST="$ESPMAKE_PRJ_HOME/.cpphash_prj"
fi
if [[ "$ESPMAKE_PRJ_ALL" == "" ]]; then
ESPMAKE_PRJ_ALL="$ESPMAKE_PRJ_HOME/.cpphash_prj_all"
fi
if [[ "$ESPMAKE_PRJ_VENV" == "" ]]; then
$ESPMAKE_PRJ_VENV="$CH_HOME/venv"
fi
if [[ "$(uname)" == "Darwin" ]]; then
SED=gsed
else
SED=sed
fi
if [ ! -d $ESPMAKE_PRJ_VENV ]; then
echo "$ESPMAKE_PRJ_VENV not found. Did you run install.sh?"
return 1
fi
if [[ "$VIRTUAL_ENV" == "" ]]; then
source "$ESPMAKE_PRJ_VENV"/bin/activate
fi
# Set your espmake project IP and TTY addresses here.
# Only two of each are support by default. More can
# be added by manually editting this file, at least for now.
# These can be set for a specific user if you are sharing
# a GrowOS project, like this:
if [[ "$_ESPMAKE_IP0" == "" && "$USER" == "maarten" ]]; then
_ESPMAKE_IP0=192.168.248.20
fi
if [[ "$_ESPMAKE_IP1" == "" && "$USER" == "maarten" ]]; then
_ESPMAKE_IP1=192.168.248.21
fi
# These are the defaults for IP addresses and serial port names
if [[ "$_ESPMAKE_IP0" == "" ]]; then
_ESPMAKE_IP0=192.168.248.10
fi
if [[ "$_ESPMAKE_IP1" == "" ]]; then
_ESPMAKE_IP1=192.168.248.11
fi
if [[ "$_ESPMAKE_DEV0" == "" ]]; then
if [[ "$(uname)" == "Darwin" ]]; then
_ESPMAKE_DEV0=/dev/tty.usbmodem01
# _ESPMAKE_DEV0=/dev/tty.usbmodem11101
else
_ESPMAKE_DEV0=/dev/ttyACM0
fi
fi
if [[ "$_ESPMAKE_DEV1" == "" ]]; then
if [[ "$(uname)" == "Darwin" ]]; then
_ESPMAKE_DEV1=/dev/tty.usbmodem01
else
_ESPMAKE_DEV1=/dev/ttyACM1
fi
fi
# Helper function that returns the path to the build directory
# of the last project built. Example: $ESPMAKE_PRJ_HOME/build/espinit
_ESPMAKE_LAST_BUILD() {
echo "${ESPMAKE_PRJ_HOME}/$CH_BUILD/$(basename $(dirname $(cat $ESPMAKE_PRJ_LAST)))_$(basename $(cat $ESPMAKE_PRJ_LAST) .mk)"
}
# Helper function that returns the name of the esphome device as
# specified in espmake.yaml "esphome:" component entry "name:".
# Example: lilygot4s3
_ESPMAKE_LAST_ESPNAME() {
echo $(yq -r --no-doc .esphome.name $(_ESPMAKE_LAST_BUILD)/espmake.yaml | grep -v null)
}
# Helper alias that takes an esphome verb and a device name and
# issues it on the last built project.
alias _ESPMAKE_USB='function _ESPMAKE_USB { cd $(_ESPMAKE_LAST_BUILD); echo esphome $1 $2 espmake.yaml; esphome $1 $2 espmake.yaml; cd -;}; _ESPMAKE_USB'
# Helper alias to upload last project using OTA update
alias _ESPMAKE_UPLOAD='function _ESPMAKE_UPLOAD { cd $(_ESPMAKE_LAST_BUILD); echo "esphome upload $1 --file .esphome/build/$(_ESPMAKE_LAST_ESPNAME)/.pioenvs/$(_ESPMAKE_LAST_ESPNAME)/firmware.bin espmake.yaml"; esphome upload $1 --file .esphome/build/$(_ESPMAKE_LAST_ESPNAME)/.pioenvs/$(_ESPMAKE_LAST_ESPNAME)/firmware.bin espmake.yaml; cd -;}; _ESPMAKE_UPLOAD'
# _ESPMAKE_IDF_JTAG uses esp-idf directly to burn firmware to /dev/ttyACM0
export ESPTOOL_TESTING=1 # as per esptool/esp32s2.py
alias _ESPMAKE_IDF_JTAG='(cd $(_ESPMAKE_LAST_BUILD)/.esphome/build/$(_ESPMAKE_LAST_ESPNAME)/.pioenvs/$(_ESPMAKE_LAST_ESPNAME) && esptool.py --before default_reset --after no_reset --baud 1500000 --port $_ESPMAKE_DEV0 write_flash -z --flash_size detect 0x10000 firmware.bin 0x1000 bootloader.bin 0x8000 partitions.bin 0x9000 ota_data_initial.bin)'
# Convenience aliases
alias ${ESPMAKE_PREFIX}venv='source $ESPMAKE_PRJ_VENV/bin/activate'
# Alias to provide the list of aliases :-)
alias ${ESPMAKE_PREFIX}help="alias | grep -E ${ESPMAKE_PREFIX}\|esp_"
# Alias to list all espmake projects specified with PRJ=
alias ${ESPMAKE_PREFIX}projects="cat $ESPMAKE_PRJ_ALL"
# Aliases to upload for the last project to IP _ESPMAKE_IP0 or _ESPMAKE_IP1
alias ${ESPMAKE_PREFIX}upload0='_ESPMAKE_UPLOAD "--device $_ESPMAKE_IP0"'
alias ${ESPMAKE_PREFIX}upload1='_ESPMAKE_UPLOAD "--device $_ESPMAKE_IP1"'
alias ${ESPMAKE_PREFIX}upload='_ESPMAKE_UPLOAD'
# Aliases to burn and run the last project to /dev/ttyACM0 or /dev/ttyACM1
alias ${ESPMAKE_PREFIX}run0='_ESPMAKE_USB run "--device $_ESPMAKE_DEV0"'
alias ${ESPMAKE_PREFIX}run1='_ESPMAKE_USB run "--device $_ESPMAKE_DEV1"'
alias ${ESPMAKE_PREFIX}run='_ESPMAKE_USB run'
# Aliases to monitor logs on /dev/ttyACM0 or /dev/ttyACM1
alias ${ESPMAKE_PREFIX}logs0='_ESPMAKE_USB logs "--device $_ESPMAKE_DEV0"'
alias ${ESPMAKE_PREFIX}logs1='_ESPMAKE_USB logs "--device $_ESPMAKE_DEV1"'
alias ${ESPMAKE_PREFIX}logs='_ESPMAKE_USB logs'
# Alias to build the current project
alias ${ESPMAKE_PREFIX}make='make -C $ESPMAKE_PRJ_HOME'
# Aliases to cd to common directories
alias ${ESPMAKE_PREFIX}home='cd $ESPMAKE_PRJ_HOME'
alias ${ESPMAKE_PREFIX}project='cd $ESPMAKE_PRJ_HOME/$(dirname $(cat $ESPMAKE_PRJ_LAST))'
alias ${ESPMAKE_PREFIX}build='cd $(_ESPMAKE_LAST_BUILD)'
# Aliases to view to common artifacts
alias ${ESPMAKE_PREFIX}log='view $(_ESPMAKE_LAST_BUILD)/makeall.log'
alias ${ESPMAKE_PREFIX}espmake='view $(_ESPMAKE_LAST_BUILD)/espmake.yaml'
alias ${ESPMAKE_PREFIX}esphome='view $(_ESPMAKE_LAST_BUILD)/esphome.yaml'
# Aliases to find strings including or excluding the build directory
alias ${ESPMAKE_PREFIX}search='find . ! -name "*.swp" ! -name "*.bak" ! -path "*/.git/*" -type f -print0 | xargs -0 grep -i'
alias ${ESPMAKE_PREFIX}search_home='find $ESPMAKE_PRJ_HOME ! -name "*.swp" ! -name "*.bak" ! -path "*/.git/*" ! -path "*/$CH_BUILD/*" ! -path "./cpphash/*" -type f -print0 | xargs -0 grep -i'
alias ${ESPMAKE_PREFIX}search_all='find $ESPMAKE_PRJ_HOME ! -name "*.swp" ! -name "*.bak" ! -path "*/.git/*" -type f -print0 | xargs -0 grep -i'
# Aliases to search for arg1 and replace it with arg2 in all files.
# Backup files are stored in <file>.bak. There are variants for arg1
# not containing hash, comma and slash. The default is no slash.
# bash does not seem to allow these to be defined with ESPMAKE_PREFIX.
esp_replace_nohash() {
find . ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' ! -path "*/$CH_BUILD/*" ! -path './cpphash/*' ! -path '*/.esphome/*' -type f -print0 | xargs -0 grep -l "$1" | xargs $SED --in-place=.bak "s#$1#$2#g"
}
esp_replace_nocomma() {
find . ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' ! -path "*/$CH_BUILD/*" ! -path './cpphash/*' ! -path '*/.esphome/*' -type f -print0 | xargs -0 grep -l "$1" | xargs $SED --in-place=.bak "s,$1,$2,g"
}
esp_replace_noslash() {
find . ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' ! -path "*/$CH_BUILD/*" ! -path './cpphash*' ! -path '*/.esphome/*' -type f -print0 | xargs -0 grep -l "$1" | xargs $SED --in-place=.bak "s/$1/$2/g"
}
alias esp_replace="esp_replace_noslash"