-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBashrc
100 lines (78 loc) · 4.95 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
# Place this esp-setup alias ~/.bashrc and adjust the two paths
# to point to your git repos for esphome and espmake. Then issue
# "source ~/.bashrc" to define the bash alias esp-setup.
# alias esp-setup='source ~/git/esphome/venv/bin/activate; cd ~/git/espmake; source ./Bashrc'
# Once you have done the above, you can activate espmake under bash
# using 'esp-setup' and then you will have some convenience aliases.
# See the section below titled "Convenience aliases" to see what they do.
# The directory where this file lives is stashed in ESPMAKE_HOME
export ESPMAKE_HOME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# set your espmake project IP addresses here.
export _ESP_IP0=192.168.248.10
export _ESP_IP1=192.168.248.11
# or, by user, if you are sharing this Bashrc, here:
if [ "$USER" == "maarten" ]; then
export _ESP_IP0=192.168.248.20
export _ESP_IP1=192.168.248.21
fi
# This is a helper function that returns the relative path to the build
# directory of the last project built. Example: ./build/espinit
_ESP_LAST_BUILD() {
echo $(realpath --relative-to=$PWD $ESPMAKE_HOME)/build/$(basename $(dirname $(cat $ESPMAKE_HOME/.espmake_project)))_$(basename $(cat $ESPMAKE_HOME/.espmake_project) .mk)
}
# This is a helper function that returns the name of the esphome
# device as specified in espmake.yaml "esphome:" component entry "name:".
# Example: lilygot4s3
_ESP_LAST_ESPNAME() {
echo $(yq -r --no-doc .esphome.name $(_ESP_LAST_BUILD)/espmake.yaml | grep -v null)
}
# helper alias that takes an esphome verb and a ACM device number and
# issues it on the last built project.
alias _ESP_ESP_USB='function _ESP_ESP_USB { _VERB=${1}; _DEV=${2}; cd $(_ESP_LAST_BUILD); esphome -v ${_VERB} --device /dev/ttyACM${_DEV} espmake.yaml; cd -;}; _ESP_ESP_USB'
# helper alias to upload last project using OTA update to IP _ESP_IP_CPU<arg>
# Note the indirect variable reference ${!_IP} to choose the _IP
alias _ESP_ESP_UPLOAD='function _ESP_ESP_UPLOAD { _IPNUM=${1}; _IP=_ESP_IP_CPU${_IPNUM}; esphome -v upload --device ${!_IP} --file $(_ESP_LAST_BUILD)/.esphome/build/$(_ESP_LAST_ESPNAME)/.pioenvs/$(_ESP_LAST_ESPNAME)/firmware.bin $(_ESP_LAST_BUILD)/espmake.yaml;}; _ESP_ESP_UPLOAD'
# _ESP_IDF_JTAG uses esp-idf directly to burn firmware to /dev/ttyACM0
export ESPTOOL_TESTING=1 # as per esptool/esp32s2.py
alias _ESP_IDF_JTAG='(cd $(_ESP_LAST_BUILD)/.esphome/build/$(_ESP_LAST_ESPNAME)/.pioenvs/$(_ESP_LAST_ESPNAME) && esptool.py --before default_reset --after no_reset --baud 1500000 --port /dev/ttyACM0 --chip esp32s2 write_flash -z --flash_size detect 0x10000 firmware.bin 0x1000 bootloader.bin 0x8000 partitions.bin 0x9000 ota_data_initial.bin)'
# Convenience aliases
# Aliases to provide the list of aliases :-)
alias esp-help='alias | grep esp-'
alias esp-aliases='alias | grep esp-'
# Aliases to upload for the last project to IP _ESP_IP0 or _ESP_IP1
alias esp-upload-0="_ESP_ESP_UPLOAD 0"
alias esp-upload-1="_ESP_ESP_UPLOAD 1"
alias esp-upload="esp-upload-0"
# Aliases to upload the last project to /dev/ttyACM0 or /dev/ttyACM1
alias esp-jtag-0="_ESP_ESP_USB upload 0"
alias esp-jtag-1="_ESP_ESP_USB upload 1"
alias esp-jtag="esp-jtag-0"
# Aliases to monitor logs on /dev/ttyACM0 or /dev/ttyACM1
alias esp-logs-0="_ESP_ESP_USB logs 0"
alias esp-logs-1="_ESP_ESP_USB logs 1"
alias esp-logs="esp-logs-0"
# Alias esp-make builds the current project
alias esp-make='make -C $ESPMAKE_HOME'
# Aliases to cd to common directories
alias esp-home='cd $ESPMAKE_HOME'
alias esp-project='cd $ESPMAKE_HOME/$(dirname $(cat $ESPMAKE_HOME/.espmake_project))'
alias esp-build='cd $(_ESP_LAST_BUILD)'
# Aliases to view to common artifacts
alias esp-log='view $(_ESP_LAST_BUILD)/makeall.log'
alias esp-yaml='view $(_ESP_LAST_BUILD)/espmake.yaml'
# Aliases to find strings including or excluding the build directory
alias esp-search="find $ESPMAKE_HOME ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' ! -path './build/*' -type f -print0 | xargs -0 grep -i"
alias esp-search-all="find $ESPMAKE_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 octothorpe, comma and slash. The default is no slash.
esp-replace-nohash() {
find . ! -name '*.swp' ! -name '*.bak' ! -path '*/.git*' ! -path '*/build*' ! -path '*/cpptext*' ! -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 '*/build*' ! -path '*/cpptext*' ! -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 '*/build*' ! -path '*/cpptext*' ! -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'