-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_aliases
234 lines (201 loc) · 8.47 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
# Load GNU aliases for mac
# Use homebrew's coreutils if possible or the standard command otherwise
if [ -d "$HOME/.homebrew/Cellar/coreutils" ]; then
LATEST_COREUTILS_DIR=$(ls -td -- $HOME/.homebrew/Cellar/coreutils/*/ | head -n 1)
if [[ ! -z ${LATEST_COREUTILS_DIR+x} ]] && [[ -d "$LATEST_COREUTILS_DIR" ]]; then
export PATH=$PATH:$LATEST_COREUTILS_DIR/bin
alias ls='gls --color=auto'
alias dircolors=gdircolors
fi
else
if [[ `uname -s` == 'Darwin' ]]; then
alias ls='ls -G'
else
alias ls='ls --color=auto'
fi
fi
# Set other ls aliases
alias ll='ls -l'
alias lla='ls -alF'
alias lh='ls -sh'
alias la='ls -A'
alias l='ls -CF'
# Colourize grep output.
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
# Colourize diff
command -v colordiff >/dev/null 2>&1 && { alias diff=colordiff; }
# Graphical vim
if type vimx >/dev/null 2>&1; then
alias vim='vimx'
export GIT_EDITOR="vimx"
elif type mvim >/dev/null 2>&1; then
alias vim='mvim -v'
export GIT_EDITOR="mvim -v"
fi
# Git fast-forward merge
alias gff='git merge --ff-only'
# hub command for better GitHub integration.
# [ $(which hub 2>/dev/null) ] && alias git=hub
# Force password authentication with SSH. Used to get around the situation
# where SSH freezes while trying to do public key authentication because
# DIRO has the NFS/Kerberos Setup From Hell.
# From http://unix.stackexchange.com/q/15138
alias sshpw='ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no'
# Force 256 colors tmux
alias tmux="TERM=xterm-256color /home/ciccone/.local/bin/tmux -2"
#alias tmux="tmux -2" # Force tmux to use 256 colors
# . $HOME/.tmux/set_tmux_config.sh
# alias tmux='TERM=screen-256color tmux -2'
alias vim="nvim"
# Autocomplete ssh names in bash (defined in .ssh/config)
_complete_ssh_hosts () {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
grep -v ^# | \
uniq | \
grep -v "\[" ;
cat ~/.ssh/config | \
grep "^Host " | \
awk '{print $2}'
`
COMPREPLY=( $(compgen -W "${comp_ssh_hosts}" -- $cur))
return 0
}
complete -F _complete_ssh_hosts ssh
# Montreal
lisa() {
if [ $# == 0 ]; then
sshpass -f ~/.lisa ssh -YC visin@elisa1
elif [ $# == 1 ]; then
sshpass -f ~/.lisa ssh -YC -L $1:localhost:$1 visin@elisa1
else
echo "usage: sshlisa [port]"
fi
}
alias lisassh=lisa
lisascp() {
sshpass -f ~/.lisa scp -Cr [email protected]:$1 $2
}
lisarsync() {
sshpass -f ~/.lisa rsync -a -X --partial -h --progress --copy-links [email protected]:$1 $2
}
alias squeue='squeue -o "%.6i %.1t %.6q %.7m %.12b %.3C %.3D %.18k %.11L %R"'
# Quick and dirty installation of packages with pip from GitHub.
ghpip() {
if [ $# == 0 ]; then
echo "usage: ghpip user/project [branch/refspec]"
return 1
fi
if [ $# == 1 ]; then
GITHUBPATH=$1
BRANCH=master
else
GITHUBPATH=$1
BRANCH=$2
fi
pip install --upgrade "git+git://github.com/$GITHUBPATH.git@$BRANCH"
}
# disk usage
disk_usage() {
# TODO: apparently ncdu is better
du -h $1 2> >(grep -v '^du: cannot \(access\|read\)' >&2) | grep '[0-9\.]\+G' | sort -rn
}
# who is using gpus
gpu_who() {
for i in `nvidia-smi -q -d PIDS | grep ID | cut -d ":" -f2`; do ps -u -p "$i"; done
}
# ram used by user
ram_who() {
for USR in $(ps axo user:20 | sort -u)
do
ps -U $USR --no-headers -o rss 2>/dev/null | awk -v user=$USR '{ sum+=$1} END {print user, int(sum/1024) "MB"}'
done
}
# rsync options
alias rsyncopt="rsync -a -X --partial -h --progress --bwlimit=20000 --copy-links "
alias rsyncopt_nolimit="rsync -a -X --partial -h --progress --copy-links "
cpdataset() {
if [ "$#" -ne 4 ]; then
echo "Usage: cpdataset <source_files> <dest_user> <dest_server> <dest_root_dir>"
else
tar czf - $1 | ssh $2@$3 "cd $4 && tar xvzf -"
fi
}
export -f cpdataset
# Manage the weird pkscreen routine for lisa lab
alias frascreen="pkscreen; sleep 5; screen -r; sleep 2"
CVD_CLR(){ export CUDA_VISIBLE_DEVICES=''; }
CVD0(){ export CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:+${CUDA_VISIBLE_DEVICES},}0; }
CVD1(){ export CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:+${CUDA_VISIBLE_DEVICES},}1; }
CVD2(){ export CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:+${CUDA_VISIBLE_DEVICES},}2; }
CVD3(){ export CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:+${CUDA_VISIBLE_DEVICES},}3; }
CVD4(){ export CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:+${CUDA_VISIBLE_DEVICES},}4; }
CVD5(){ export CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:+${CUDA_VISIBLE_DEVICES},}5; }
CVD6(){ export CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:+${CUDA_VISIBLE_DEVICES},}6; }
CVD7(){ export CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:+${CUDA_VISIBLE_DEVICES},}7; }
CVDNONE(){ export CUDA_VISIBLE_DEVICES=-1; }
# Displays
D0(){ export DISPLAY=localhost:0.0; }
D10(){ export DISPLAY=localhost:10.0; }
D11(){ export DISPLAY=localhost:11.0; }
D12(){ export DISPLAY=localhost:12.0; }
wait-pid(){ tail --pid=$1 -f /dev/null; }
wait-file(){ while [ ! -f $1 ]; do sleep 1; done; }
# DOCKER
# ======
alias dk="docker"
alias dkl="docker logs"
alias dki="docker images"
alias dkps="docker ps"
alias dkpsa="docker ps -a"
# dkrmname <name>: remove all containers having <name> in the container's name
dkrmname(){
ids=`docker ps -a | grep $1 | awk '{print $1;}'`
docker rm $ids
}
# dkattach <name>: attach to existing container
dkattach() { docker start $1 && docker attach $1; }
# dkattach <name>: attach to existing container
dkattach() { docker start $1 && docker attach $1; }
# dkrun [<args>] <image>: runs a container from a docker image
dkrun(){
nvidia-docker run -ti\
--workdir /host$PWD \
--volume /:/host \
--env PYTHONUNBUFFERED=x \
--env CUDA_CACHE_PATH=/host/tmp/cuda-cache "$@"
}
# dklaunch [<args>] <image> <cmd>: runs a command on a docker container; when the command finishes, it removes the container
dklaunch(){ dkrun -ti --rm "$@"; }
# dkpython <cmd>: launches a python2.7 command on the default docker container
dkpython(){ dklaunch airlab/dl:latest bash -c "source activate py27; python $@"; }
# dkipython <image> <cmd>: launches a python2.7 command a a user specified image
dkipython(){ dklaunch $1 PY27; python "${@:2}"; }
# dkpython3 <cmd>: launches a python3.6 command on the default docker container
dkpython3(){ dklaunch airlab/dl:latest bash -c "source activate py36; python $@"; }
# dkipython3 <image> <cmd>: launches a python3.6 command a a user specified image
dkipython3(){ dklaunch $1 PY36; python "${@:2}"; }
tb-docker() {
run-docker --container_name="{user}_tensorboard_{date}" --image_name="tensorflow/tensorflow:latest" --symlinks=0 --docker_args="-p $1:$1" '' '' tensorboard --port $1 --bind_all --logdir /exp;
}
jupyter-docker() {
docker run --rm -it --shm-size 8G --cpuset-cpus=$2 -p $1:$1 --user $(id -u):$(id -g) --group-add users -v `pwd`:/exp -v $HOME/.jupyter/:/.jupyter -t ciccone/dl:cuda10.1_pytorch-1.3.1_tf-1.15_py36 jupyter notebook --ip=0.0.0.0 --port=$1;
}
jupyter-nvidia-docker() {
NV_GPU=$3 nvidia-docker run --rm -it --shm-size 8G --cpuset-cpus=$2 -p $1:$1 --user $(id -u):$(id -g) --group-add users -v `pwd`:/exp -v $HOME/.jupyter/:/.jupyter -t ciccone/dl:cuda10.1_pytorch-1.3.1_tf-1.15_py36 jupyter notebook --ip=0.0.0.0 --port=$1;
}
jupyterlab-docker() {
docker run --rm -it --shm-size 8G --cpuset-cpus=$2 -p $1:$1 --user $(id -u):$(id -g) --group-add users -v `pwd`:/exp -v $HOME/.jupyter/:/.jupyter -t ciccone/dl:cuda10.1_pytorch-1.3.1_tf-1.15_py36 jupyter lab --ip=0.0.0.0 --port=$1;
}
jupyterlab-nvidia-docker() {
NV_GPU=$3 nvidia-docker run --rm -it --shm-size 8G --cpuset-cpus=$2 -p $1:$1 --user $(id -u):$(id -g) --group-add users -v `pwd`:/exp -v $HOME/.jupyter/:/.jupyter -t ciccone/dl:cuda10.1_pytorch-1.3.1_tf-1.15_py36 jupyter lab --ip=0.0.0.0 --port=$1;
}
# jupyter-nvidia-docker() {
# NV_GPU=$3 nvidia-docker run --rm -it --shm-size 8G --cpuset-cpus=$2 -p $1:$1 --cap-add SYS_ADMIN --device /dev/fuse --security-opt apparmor=unconfined --user $(id -u):$(id -g) --group-add users -v `pwd`:/exp -t ciccone/dl:cuda10_pytorch-1.1.0_tf-1.14_py36 jupyter notebook --ip=0.0.0.0 --port=$1 --NotebookApp.allow_origin='https://colab.research.google.com' --port=$1 --NotebookApp.port_retries=0;
# }
#