forked from efernandez/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_aliases
394 lines (333 loc) · 8.5 KB
/
.bash_aliases
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
alias rosmake='ROS_PARALLEL_JOBS=-j6 nice rosmake'
function guri()
{
if [[ $# < 1 ]]
then
echo $GAZEBO_MASTER_URI
else
if [[ $# < 2 ]]
then
PORT=11345
else
PORT=$2
fi
export GAZEBO_MASTER_URI=http://$1:$PORT
fi
}
function rosip()
{
if [[ $# < 1 ]]
then
INTERFACE=wlan0
else
INTERFACE=$1
fi
export ROS_IP=$(ifconfig $INTERFACE | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1)
}
function uri()
{
if [[ $# < 1 ]]
then
echo $ROS_MASTER_URI
else
if [[ $1 == test ]]
then
export ROS_MASTER_URI=http://localhost:22422
else
if [[ $# < 2 ]]
then
PORT=11311
else
PORT=$2
fi
export ROS_MASTER_URI=http://$1:$PORT
fi
fi
}
function log()
{
if [[ $# < 1 ]]
then
rosservice list | grep get_loggers | cut -d/ -f 2
elif [[ $# < 2 ]]
then
rosservice call $1/get_loggers
elif [[ $# < 3 ]]
then
rosservice call $1/set_logger_level "{logger: ros, level: $2}"
else
rosservice call $1/set_logger_level "{logger: $2, level: $3}"
fi
}
function uln()
{
TARGET=`ls -l $1 | awk '{print $11}'`
unlink $1
cp $TARGET $1
}
rviz()
{
if [[ $# < 1 ]]
then
rosrun rviz rviz
elif [[ $# < 2 ]]
then
rosrun rviz rviz -d ${1}
else
rosrun rviz rviz -d $(rospack find ${1})/config/${2}.rviz
fi
}
function release()
{
if [[ $# < 1 ]]
then
ROS_DISTRO=indigo
else
ROS_DISTRO=$1
fi
catkin_generate_changelog
git ci -am "Update changelog"
catkin_prepare_release -y
bloom-release -y $(basename $(pwd)) --track $ROS_DISTRO --rosdistro $ROS_DISTRO
}
function term()
{
if [[ $# > 0 ]]
then
gnome-terminal -x bash -ci "$*; bash"
else
gnome-terminal -x "bash"
fi
}
function termn()
{
if [[ $# > 0 ]]; then
N=$1
shift
else
N=1
fi
for i in $(seq 1 $N); do
term $*
done
}
function cake()
{
ARGS="-j8 -DCMAKE_BUILD_TYPE=RelWithDebInfo"
if [[ $# > 0 ]]; then
ARGS="$ARGS --only-pkg-with-deps $*"
fi
catkin_make $ARGS
}
function cm()
{
WS_DIR=($(echo $CMAKE_PREFIX_PATH | tr ':' '\n'))
WS_DIR=${WS_DIR[0]}
WS_DIR=${WS_DIR/\/devel/}
if [[ $# < 1 ]]
then
PKG=$(basename $(pwd))
else
PKG=$1
fi
cd $WS_DIR
catkin_make -j8 --only-pkg-with-deps $PKG
cd -
}
#alias psgrep='pgrep '
alias psgrep='ps aux | grep -i '
alias lgrep='ls | grep -i '
alias fgrep='find | grep -i '
alias dgrep='dpkg -l | grep -i '
alias egrep='env | grep -i '
alias rosdepgrep='rosdep db | grep -i '
alias envgrep='env | grep -i '
alias hgrep='history | grep -i '
alias roscorebg='roscore >/dev/null 2>&1 &'
# misspelling aliases:
alias rosonde='rosnode '
alias rosndoe='rosnode '
alias joystick='rosrun joy joy_node _dev:=/dev/input/js1 '
function roskill()
{
killall -q gazebo gzclient
#pkill -9 ros
#pgrep ros | ...
psgrep ros | grep -v 'vim\|sublime\|g++\|gcc\|c++\|rosmake\|catkin\|grep\|chrome' | awk '{print $2}' | xargs -I{} kill {}
psgrep ros | grep -v 'vim\|sublime\|g++\|gcc\|c++\|rosmake\|catkin\|grep\|chrome' | awk '{print $2}' | xargs -I{} kill -9 {}
psgrep rqt | grep -v 'vim\|sublime\|g++\|gcc\|c++\|rosmake\|catkin\|grep\|chrome' | awk '{print $2}' | xargs -I{} kill {}
psgrep rqt | grep -v 'vim\|sublime\|g++\|gcc\|c++\|rosmake\|catkin\|grep\|chrome' | awk '{print $2}' | xargs -I{} kill -9 {}
roscorebg
}
function rosbagfilter()
{
INPUT=$1
FRAME=$2
OUTPUT=${INPUT//.bag/_filtered.bag}
rosbag filter $INPUT $OUTPUT "topic != '/tf' or m.transforms[0].header.frame_id != '$FRAME'"
}
alias deps='rosdep install --from-paths src -iy '
function f()
{
findcmd='find | grep -v "\.svn" | grep -v "\.git"'
if [ $# -gt 0 ]; then
result=`eval $findcmd | grep --color=always $* | tee /dev/stderr`
if [ -z "$result" ]; then
eval $findcmd | grep --color=always -i $*
fi
else
eval $findcmd
fi
}
alias a='ack-grep -i '
# Pipe to vim
function v()
{
$@ | vim -R -
}
alias vi='vim '
alias ws='source devel/setup.bash'
# ls aliases
alias ll='ls -rthal'
alias la='ls -A'
alias l='ls -CF'
# other aliases
alias o='xdg-open'
alias k='pkill -9'
alias c='clear'
alias x='exit'
alias q='exit'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
alias .......='cd ../../../../../..'
alias -- -='cd -'
alias rosnodegrep='rosnode list | grep -i '
alias rostopicgrep='rostopic list | grep -i '
alias rosservicegrep='rosservice list | grep -i '
alias rosparamgrep='rosparam list | grep -i '
function rosnodeinfogrep()
{
if [[ $# < 1 ]]
then
PATTERN="unknown"
else
PATTERN=$1
fi
for node in $(rosnode list)
do
rosnode info | grep -i $PATTERN
done
}
alias sudo='sudo '
alias gg='git log --oneline --abbrev-commit --all --graph --decorate --color'
alias ud='udisks --detach'
alias log-out='gnome-session-quit'
alias x-start='service lightdm restart'
alias off='xset dpms force off'
alias cbuild='catkin build --cmake-args -DCMAKE_C_FLAGS="-Wall -W -Wno-unused-parameter -Werror" -DCMAKE_CXX_FLAGS="-Wall -W -Wno-unused-parameter -Werror" -DCMAKE_BUILD_TYPE=Release -- --no-notify '
alias cbuildnowarn='catkin build --cmake-args -DCMAKE_BUILD_TYPE=Release -- --no-notify '
alias cdebug='catkin build --cmake-args -DCMAKE_C_FLAGS="-Wall -W -Wno-unused-parameter -Werror" -DCMAKE_CXX_FLAGS="-Wall -W -Wno-unused-parameter -Werror" -DCMAKE_BUILD_TYPE=RelWithDebInfo -- --no-notify '
#alias cbuild='catkin build --cmake-args -DCMAKE_C_FLAGS="-Wall -W -Wno-unused-parameter -Werror" -DCMAKE_CXX_FLAGS="-Wall -W -Wno-unused-parameter -Werror" -DCMAKE_BUILD_TYPE=Debug -- --no-notify '
alias cclean='catkin clean --deinit -y '
alias cinstall='catkin build --no-notify --catkin-make-args install -- '
alias ctest='catkin run_tests --no-deps --this --no-notify '
alias cconfig='catkin config --install --isolate-install --isolate-devel '
# Current year calendar
alias cal='cal -y'
# matlab in awesome
# see http://awesome.naquadah.org/wiki/Problems_with_Java
function matlab()
{
wmname LG3D
if [[ $# < 1 ]]
then
MATLAB_VERSION=R2013a
else
MATLAB_VERSION=$1
fi
/usr/local/MATLAB/$MATLAB_VERSION/bin/matlab -desktop
}
# set operations between files
function set_union()
{
cat "$1" "$2" | sort | uniq
}
function set_difference()
{
cat "$1" "$2" "$2" | sort | uniq -u
}
# repeat
function repeat()
{
n=$1
shift
while [ $(( n -= 1 )) -ge 0 ]
do
"$@"
done
}
# A shortcut function that simplifies usage of xclip.
# - Accepts input from either stdin (pipe), or params.
# Taken from: http://madebynathan.com/2011/10/04/a-nicer-way-to-use-xclip/
# ------------------------------------------------
cb() {
local _scs_col="\e[0;32m"; local _wrn_col='\e[1;31m'; local _trn_col='\e[0;33m'
# Check that xclip is installed.
if ! type xclip > /dev/null 2>&1; then
echo -e "$_wrn_col""You must have the 'xclip' program installed.\e[0m"
# Check user is not root (root doesn't have access to user xorg server)
elif [[ "$USER" == "root" ]]; then
echo -e "$_wrn_col""Must be regular user (not root) to copy a file to the clipboard.\e[0m"
else
# If no tty, data should be available on stdin
if ! [[ "$( tty )" == /dev/* ]]; then
input="$(< /dev/stdin)"
# Else, fetch input from params
else
input="$*"
fi
if [ -z "$input" ]; then # If no input, print usage message.
echo "Copies a string to the clipboard."
echo "Usage: cb <string>"
echo " echo <string> | cb"
else
# Copy input to clipboard
echo -n "$input" | xclip -selection c
# Truncate text for status
if [ ${#input} -gt 80 ]; then input="$(echo $input | cut -c1-80)$_trn_col...\e[0m"; fi
# Print status.
echo -e "$_scs_col""Copied to clipboard:\e[0m $input"
fi
fi
}
# Aliases / functions leveraging the cb() function
# ------------------------------------------------
# Copy contents of a file
function cbf() { cat "$1" | cb; }
# Copy SSH public key
alias cbssh="cbf ~/.ssh/id_rsa.pub"
# Copy current working directory
alias cbwd="pwd | cb"
# Copy most recent command in bash history
alias cbhs="cat $HISTFILE | tail -n 1 | cb"
# Paste
alias cbp="xclip -o -selection clipboard"
# VTune
alias vtune='amplxe-cl -collect hotspots -run-pass-thru=--no-altstack -result-dir vtune_result_dir_$(date +%Y-%m-%d-%H-%M-%S) -- '
alias vtune-gui='amplxe-gui '
# Battery status
alias battery='upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "state|to\ full|percentage"'
# Anti Virus:
function virus()
{
if [[ $# -lt 1 ]]
then
DIR=/
else
DIR=$1
fi
clamscan -r --bell -i $DIR
}