-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
296 lines (264 loc) · 7.88 KB
/
zshrc
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
if [ "$TMUX" = "" ]; then tmux; fi
~/bin/config_git_status.sh
# The following lines were added by compinstall
zstyle :compinstall filename '/home/perg/.zshrc'
zstyle ':completion:*' special-dirs true
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*' group-name ”
fpath=(~/.zsh/completions $fpath)
autoload -Uz compinit
compinit
# End of lines added by compinstall
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=10000
SAVEHIST=10000
unsetopt beep
export LC_ALL=en_IN.UTF-8
export LANG=en_IN.UTF-8
# Disable ctrl-s/q
if [[ -t 0 && $- = *i* ]]
then
stty -ixon
fi
source /usr/share/doc/fzf/examples/key-bindings.zsh
source /usr/share/doc/fzf/examples/completion.zsh
#setopt inc_append_history
#setopt share_history
######################
# ENV VARS AND ALIAS #
######################
# VIM stuff
EDITOR=nvim
alias nvim='nvim -p'
alias vim='nvim'
alias less='less --raw'
# Make reboot sudo only
alias reboot='echo "Your account is not allowed to run the reboot command without sudo"'
alias shutdown='echo "Your account is not allowed to run the shutdown command without sudo"'
# End of lines configured by zsh-newuser-install
export MYSSHCONFIG="/home/perg/.ssh/config"
export MYZSHRC="/home/perg/.zshrc"
export MYTMUXCONF="/home/perg/.tmux.conf"
alias ls='ls -lh --color=auto'
alias tmux='tmux -u'
# zephyr
#export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
export ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk
# Nordic
export NRF=nrf52840_pca10056
# nordic SDK build of embida fw for kit
export SDK_ROOT=~/spotics/embida/134-spotics-mini-mic/parts/93000-nRF-sdk/
alias find_sr="sudo nmap 10.0.0.0/24 -p 22 --open | grep -i murata -B 5"
#########################
# Stuff to do with PATH #
#########################
function test_path_and_add ()
{
if [ $# = 1 ]; then
if [[ -d $1 ]]; then
if [[ ":$PATH:" != *":$1:"* ]]; then
path+=("$1")
fi
fi
fi
}
# Expand $PATH to include ARM embedded toolchain
export ARMGCC_DIR="/opt/gcc-arm-none-eabi"
export GNUARMEMB_TOOLCHAIN_PATH="/opt/gcc-arm-none-eabi"
test_path_and_add ${GNUARMEMB_TOOLCHAIN_PATH}/bin
test_path_and_add ${ZEPHYR_SDK_INSTALL_DIR}/aarch64-zephyr-elf/bin
export AARCH64_TOOLCHAIN="aarch64-zephyr-elf"
export RASPI_TOOLCHAIN_PATH="~/gitstuff/raspi_compile_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64"
test_path_and_add ${RASPI_TOOLCHAIN_PATH}/bin
export PROTOC_INSTALL_DIR="/opt/protoc/bin/"
test_path_and_add $PROTOC_INSTALL_DIR
export GNU_INSTALL_ROOT=$GNUARMEMB_TOOLCHAIN_PATH/bin/
# set PATH so it includes user's private bin if it exists
test_path_and_add "$HOME/bin"
test_path_and_add "$HOME/.local/bin"
test_path_and_add "/opt/eagle"
test_path_and_add "/usr/local/go/bin"
#############
# FUNCTIONS #
#############
function zephyr-dts-lookup () {
if [ $# = 2 ]; then
build=$1
dts_nr=$2
elif [ $# = 1 ]; then
build="build"
dts_nr=$1
else
echo "Two params needed, build folder and dts ord number"
echo "Build folder can be omitted if it is 'build'"
return
fi
ls ${build}/zephyr/**/devicetree_generated.h
if [ ! $? = 0 ]; then
echo "Cannot find dts file:"
return
fi
dtsfile=$(ls ${build}/zephyr/**/devicetree_generated.h | rev | cut -d" " -f 1 | rev)
echo $dtsfile
header_end=$(grep -n "*/" $dtsfile | head -n1 | cut -d ":" -f1)
echo "Grepping first $header_end lines"
head -n $header_end $dtsfile | grep $dts_nr
}
function zephyr-addr2line () {
if [ $# = 2 ]; then
build=$1
addr=$2
elif [ $# = 1 ]; then
build="build"
addr=$1
else
echo "Two params needed, build folder and addr in hex"
echo "Build folder can be omitted if it is 'build'"
return
fi
for i in $(ls ${build}/**/zephyr.elf | rev | cut -d" " -f1 | rev); do ${AARCH64_TOOLCHAIN}-addr2line -e $i $addr; done
}
function zephyr-config-lookup () {
if [ $# = 2 ]; then
build=$1
config=$2
elif [ $# = 1 ]; then
build="build"
config=$1
else
echo "Two params needed, build folder and config option (case insensitive)"
echo "Build folder can be omitted if it is 'build'"
return
fi
configfile=${build}/zephyr/.config
if [ ! -f $configfile ]; then
echo "File $configfile is not available"
return
fi
grep -inr $config $configfile
}
function tio () {
/usr/bin/tio -l /tmp/tio-"$1:t".log "$1"
}
function picocom () {
echo "You want to use tio"
}
# function to speed up erase, prog etc of nrf kit
function nrf () {
if [ "$1" = 'e' ]; then
nrfjprog --eraseall
elif [ "$1" = 'p' ]; then
nrfjprog --program $2
elif [ "$1" = 'r' ]; then
nrfjprog --reset
elif [ "$1" = 'a' ]; then
nrfjprog --eraseall && nrfjprog --program $2 && nrfjprog --reset
elif [ "$1" = 's' ]; then
nrfjprog -s $3 --eraseall && nrfjprog -s $3 --program $2 && nrfjprog -s $3 --reset
else
echo "(e)rase, (r)eset, (p)rogram filename, or (a)ll filename"
fi
}
function lilbitprog () {
sign52=683850517
sign91=602005433
if [ ! -d build ]; then
echo "No build folder available"
else
if [ "$1" = '52' ]; then
nrfjprog -f nrf52 -s ${sign52} --program build/zephyr/zephyr.hex --chiperase --verify -r
elif [ "$1" = '91' ]; then
nrfjprog -f nrf91 -s ${sign91} --program build/zephyr/merged.hex --chiperase --verify -r
else
echo "Incorrect usage: lilbitprog [52|91]"
fi
fi
}
function rttlog () {
if [ ! -d build ]; then
echo "No build folder available"
return
fi
RTTAddress=$(cat build/zephyr/zephyr.map | grep '0x.* *_SEGGER_RTT' | sed 's/_SEGGER_RTT//;s/ //g') ;
JLinkRTTLogger -Device CORTEX-M4 -If SWD -Speed 4000 -RTTAddress $${RTTAddress} -RTTChannel 0 /tmp/rtt_log
}
function osddone () {
if (( $# == 0 )) then
notify-send -t 10 -i /usr/share/pixmaps/faces/lightning.jpg "USPESIFISERT JOBB" "No e jobben din ferdig";
else
notify-send -t 10 -i /usr/share/pixmaps/faces/lightning.jpg $1 "No e jobben din ferdig";
fi
}
function mkcd () {
mkdir -p "$1"
cd "$1"
}
function dr () {
if (( $# == 0)) then
echo "I need a target to run!"
else
if [ "$(docker container ls | grep $1)" = "" ]; then
echo "Starting $1"
docker start $1
fi
docker exec -ti $1 /bin/bash -l
fi
}
function chsearch () {
if (( $# == 0 ))
then echo usage: chsearch pattern; fi
grep -n $1 **/*.[ch]
}
r() {
local f
f=(~/.zsh/completions/*(.))
echo $f:t
unfunction $f:t 2> /dev/null
autoload -U $f:t
}
########################
# SPECIAL KEY BINDINGS #
########################
bindkey -v
bindkey '\e[1~' beginning-of-line # Linux console
bindkey '\e[H' beginning-of-line # xterm
bindkey '\eOH' beginning-of-line # gnome-terminal
bindkey '\e[2~' overwrite-mode # Linux console, xterm, gnome-terminal
bindkey '\e[3~' delete-char # Linux console, xterm, gnome-terminal
bindkey '\e[4~' end-of-line # Linux console
bindkey '\e[F' end-of-line # xterm
bindkey '\eOF' end-of-line # gnome-terminal
################
# SETUP PROMPT #
################
setopt prompt_subst
autoload -Uz vcs_info
zstyle ':vcs_info:*' stagedstr 'M'
zstyle ':vcs_info:*' unstagedstr 'M'
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' actionformats '%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
zstyle ':vcs_info:*' formats \
'%F{2}[%F{2}%b%F{2}] %F{2}%c%F{213}%u%f'
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked
zstyle ':vcs_info:*' enable git
+vi-git-untracked() {
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
git status --porcelain | grep '??' &> /dev/null ; then
hook_com[unstaged]+='%F{213}??%f'
fi
}
precmd () { vcs_info }
#PROMPT='%(?..[%?] )%F{5}[%F{2}%m%F{5}|%F{2}%T%F{5}] ${vcs_info_msg_0_}%F{3}%#%f '
#PROMPT='%(?..[%?] )%F{189}[%F{189}%m%F{189}|%F{189}%T%F{189}] ${vcs_info_msg_0_}%F{213}%#%f '
if [ "$DISTROBOX_ENTER_PATH" = "" ];
then
PROMPT='%(?..[%?] )%F{189}[%F{189}%T%F{189}] ${vcs_info_msg_0_}%F{189}%#%f '
export RPROMPT='%F{2}%~'
else
PROMPT='%(?..[%?] )%F{2}[%F{2}%m] ${vcs_info_msg_0_}%F{2}%#%f '
export RPROMPT='%F{2}%~'
fi