Skip to content
Snippets Groups Projects
Commit 3031689e authored by Montaño Sarria, Andres Felipe's avatar Montaño Sarria, Andres Felipe
Browse files

ADD option to dockrun

parent fac0a0ee
Branches
No related tags found
No related merge requests found
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/.local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/home/andres/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="powerlevel10k/powerlevel10k"
# Set up the prompt
autoload -Uz promptinit
promptinit
prompt adam1
setopt histignorealldups # sharehistory
setopt no_share_history
# Uncomment the following line to enable command auto-correction.
ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
HIST_STAMPS="dd/mm/yyyy"
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(zsh-syntax-highlighting sudo git last-working-dir globalias you-should-use zsh-autosuggestions history-substring-search)
source $ZSH/oh-my-zsh.sh
# Create a cache folder if it isn't exists
if [ ! -d "$HOME/.cache/zsh" ]; then
mkdir -p $HOME/.cache/zsh
fi
# Define a custom file for compdump
export ZSH_COMPDUMP="$HOME/.cache/zsh/zcompdump-$HOST-$ZSH_VERSION"
# User configuration
export EDITOR="code -r"
# Include dotfiles
source ${HOME}/srcs/development_environment/dotfiles/git.bash
source ${HOME}/srcs/development_environment/dotfiles/docker.bash
source ${HOME}/srcs/development_environment/dotfiles/ros.bash
source ${HOME}/srcs/development_environment/dotfiles/system.bash
eval "$(direnv hook zsh)"
# Add fuzzy search app
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# Finalize Powerlevel10k instant prompt. Should stay at the bottom of ~/.zshrc.
(( ! ${+functions[p10k-instant-prompt-finalize]} )) || p10k-instant-prompt-finalize
# docker common commands
export dockerfiles_DIR=~/srcs/development_environment/dockerfiles;
alias dim="docker images"
alias dpsa="docker ps -a"
alias dps="docker ps"
alias drm="docker rm"
alias drmi="docker rmi"
alias dsp="docker system prune --all"
alias dimp="docker image prune"
# Build docker image
# usage: dockbuild {noetic, melodic}
function dockbuild(){
if [ $# -lt 1 ]; then
echo "Usage: dockbuild <ROS_DISTRO> [build_args]"
echo "build_args:"
echo " SHELL - zsh (default) or bash"
return 1
fi
cd $dockerfiles_DIR;
if [ $# -lt 2 ]; then
echo "Building ROS_DISTRO:"$1 "with SHELL_VERISON: zsh"
docker build -t devenv:$1 --build-arg ROS_DISTRO=$1 --build-arg SHELL="zsh" -f devenv.Dockerfile .
else
if [ $2 = "bash" ]; then
echo "Building ROS_DISTRO:"$1 "with SHELL_VERISON:"$2
docker build -t devenv:$1 --build-arg ROS_DISTRO=$1 --build-arg SHELL=$2 -f devenv.Dockerfile .
else
echo "SHELL_VERISON:"$2 "not supported"
fi
fi
}
# Run container with rocker
# usage: rundock {noetic, melodic} [{remodel_ws, odin_ws}] [cmd]
# ToDo Add extra parameters by arg
# To share docker --volume /var/run/docker.sock:/var/run/docker.sock:ro
# To share video (usb-cam) --volume /dev/video0:/dev/video0
function dockrun() {
# Check if the image exist
if [[ "$(docker images -q devenv:$1 2> /dev/null)" == "" ]]; then
# build the image
dockbuild $1
fi
# Check if the container exist
if [[ $(docker ps -aq -f name=$1) ]]; then
# Attach to conayiner
docker exec -it $1 bash -c "cd ~/ros/$1/$2 && $ext"
else
# Launch container
cd ~/ros/$1/$2;
rocker --home --ssh --git --user --privileged --nvidia --x11 --network host --name $1 devenv:$1 $3
fi
}
# Remove all stoped containers
function drma() {
drm $(docker ps -a -f status=exited -q)
}
# Remove all unused or dangling immages
function drmui(){
drmi $(dim --filter "dangling=true" -q --no-trunc)
}
# Stop and remove
function dsr() {
docker stop $1;
docker rm $1
}
# function runpythonsyntax(){
# rocker --home --name python_syntax tecnalia-docker-dev.artifact.tecnalia.com/docker:git
# }
# function runremodel() {
# rocker --x11 --nvidia --privileged --network=host --name remodel_docker --oyr-run-arg " -v iiwa_state_recorder:/home/remodel/iiwa_state_recorder -v /home/andres/test/remodel_shared:/home/remodel/remodel_shared" -- remodel_app:melodic bash -c "'roslaunch remodel_app remodel_app.launch use_sim:=true docker:=true skill_manager:=true collision_detector:=true ui:=true cad:=true joystick:=false'"
# }
# function docrun() {
# rocker --nvidia --pulse --x11 --volume /dev/video0:/dev/video0 --privileged --oyr-run-arg " -v odin_robot_volume:/root/" --name odin_robot --network host odin_robot:melodic $1
# }
# function runodin() {
# rocker --nvidia --pulse --x11 --privileged --volume /dev/video0:/dev/video0 --name odin_melodic --network host devenv:melodic $1
# }
#DOCKER
alias dexec='f(){ docker exec -w /root/ --detach-keys="ctrl-@" -e DISPLAY=$DISPLAY -it $1 /bin/bash -c "terminator --no-dbus"; unset -f f; }; f'
alias dexec_nt='f(){ docker exec --detach-keys="ctrl-@" -e DISPLAY=$DISPLAY -it $1 /bin/bash ; unset -f f; }; f'
alias dstart='f(){ docker start $1; dexec $1; unset -f f; }; f'
# Run using same X and .ssh folder
alias drun='f(){ docker run -it -e DISPLAY=$DISPLAY --detach-keys="ctrl-@" -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.ssh:/root/.ssh:ro -v ~/docker_share/:/root/docker_share/ --net=host --name $2 $1; unset -f f; }; f'
alias drun_nvidia='f(){ docker run -it --name $2 --privileged \
--net=host \
--env=NVIDIA_VISIBLE_DEVICES=all \
--env=NVIDIA_DRIVER_CAPABILITIES=all \
--env=DISPLAY \
--env=QT_X11_NO_MITSHM=1 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
--gpus all \
--device /dev/snd \
-e NVIDIA_VISIBLE_DEVICES=0 \
--detach-keys="ctrl-@" \
-v ~/.ssh:/root/.ssh:ro \
-v ~/docker_share/:/root/docker_share/ \
$1 /bin/bash; unset -f f; }; f'
......@@ -51,6 +51,7 @@ function dockbuild(){
# To share docker --volume /var/run/docker.sock:/var/run/docker.sock:ro
# To share video (usb-cam) --volume /dev/video0:/dev/video0
# To share pcan --volume /dev/pcanusb32:/dev/pcanusb32
# To share 3Dmouse --volume /dev/pcanusb32:/dev/pcanusb32
function dockrun() {
if [ $# -lt 1 ]; then
echo "Usage: dockrun <ROS_DISTRO> [posicional options]"
......@@ -88,10 +89,18 @@ function dockrun() {
if [ $# -lt 4 ]; then
rocker --home --ssh --git --user --privileged --nvidia --x11 --network host --name $1 devenv:$1
else
if [ $3 = "dev" ]; then
rocker --home --ssh --git --user --privileged --nvidia --x11 --volume /dev:/dev --network host --name $1 devenv:$1
else
fi
if [ $3 = "pcan" ]; then
rocker --home --ssh --git --user --privileged --nvidia --x11 --volume /dev/pcanusb32:/dev/pcanusb32 --network host --name $1 devenv:$1
else
fi
if [ $3 = "video" ]; then
rocker --home --ssh --git --user --privileged --nvidia --x11 --volume /dev/video0:/dev/video0 --network host --name $1 devenv:$1
else
fi
fi
fi
}
......
###################################################################
# ROS aliases and functions
###################################################################
# Define ROS_DISTRO before source ROS on native OS
# if [ -z $ROS_DISTRO ]; then export ROS_DISTRO=noetic; fi
if [[ -z "${ROS_DISTRO}" ]]; then
ROS_DIR=/opt/ros
if [ -d "$ROS_DIR" ];
then
export ROS_DISTRO=$(basename $(find /opt/ros/* -maxdepth 0 -type d | head -1))
else
unset ROS_DISTRO
fi
fi
# Determine shell extension
if [ -z $SHELL ]; then echo "SHELL not set"; else ext=$(basename ${SHELL}); fi
# Source rosmon
function smon(){
if [[ -f "/opt/ros/${ROS_DISTRO}/etc/catkin/profile.d/50-rosmon.${ext}" ]]; then
source /opt/ros/${ROS_DISTRO}/etc/catkin/profile.d/50-rosmon.${ext}
fi
}
# cd to the root of the workspace
function roshome(){
roscd && cd ..
ROS_HOME=${PWD}
}
# Source the current workspace
function sourcews(){
source ./devel/setup.${ext} && smon
}
# Source the current workspace
function sourceros(){
source /opt/ros/${ROS_DISTRO}/setup.${ext} && smon
ROS_HOME="/opt/ros/${ROS_DISTRO}/"
}
# Source the current workspace
function sourcethis(){
pwd_st=${PWD}
roshome && sourcews
echo "Sourcing: ${ROS_HOME}"
cd ${pwd_st}
}
# Automatic catkin build
function cb() {
pwd_cb=${PWD}
roshome
catkin build --summarize --cmake-args -DCMAKE_BUILD_TYPE=Release -- "$@"
sourcethis
cd ${pwd_cb}
}
# Clean workspace (delete the generated folders, then catkin build)
function cbclean(){
roshome && rm -rf build devel install && catkin build --summarize --cmake-args -DCMAKE_BUILD_TYPE=Release
}
# Initialize catkin workspace, configure and build it
function cib(){
catkin init && catkin config --extend /opt/ros/${ROS_DISTRO} && catkin build --summarize --cmake-args -DCMAKE_BUILD_TYPE=Release
}
# Run ci locally
function runci(){
# check if exist .rosinstall file
if [ -f ./.rosinstall ]; then
echo ".rosinstall in package"
find ../ -name run_ci -exec bash {} ROS_DISTRO="$@" DOCKER_IMAGE=tecnalia-robotics-docker.artifact.tecnalia.com/flexbotics-base-devel:"$@" UPSTREAM_WORKSPACE=.rosinstall \;
else
echo "No .rosinstall in package"
find ../ -name run_ci -exec bash {} ROS_DISTRO="$@" DOCKER_IMAGE=tecnalia-robotics-docker.artifact.tecnalia.com/flexbotics-base-devel:"$@" \;
fi
}
# if a new terminal starts in a ws, auto source it (useful for vscode)
if [ -z ${ROS_DISTRO+x} ]; then ;
else
pwd_init=${PWD}
cropped=${PWD#${HOME}/ros/${ROS_DISTRO}/}
WS_name=${cropped%%/*}
WS_path=${HOME}/ros/${ROS_DISTRO}/${WS_name}
FILE=${WS_path}/devel/setup.${ext}
# if PWD belongs to ROS ws then source it
if [[ -f $FILE ]]; then
cd ${WS_path}
source $FILE
cd ${pwd_init}
ROS_HOME=${WS_path}
else
sourceros
fi
fi
alias sc=sourcethis
\ No newline at end of file
# Determine shell extension
if [ -z $SHELL ]; then
echo "SHELL not set"
export SHELL=/usr/bin/zsh
ext=$(basename ${SHELL});
else
ext=$(basename ${SHELL});
fi
if command -v lsd &> /dev/null
then
# Directories
alias ll='lsd -lh --group-dirs=first'
alias la='lsd -a --group-dirs=first'
alias l='lsd --group-dirs=first'
alias lla='lsd -lha --group-dirs=first'
alias ls='lsd --group-dirs=first'
else
alias ll='ls -lh'
alias la='ls -a'
alias l='ls'
alias lla='ls -lha'
alias ls='ls'
fi
if command -v bat &> /dev/null
then
# Files
alias cat='bat'
fi
# Python
if command -v ipython &> /dev/null
then
alias ipy='ipython'
fi
alias mountT='sudo mount -t cifs //tri.lan/tri /mnt/T --verbose -o username=110343,password=Bageera\#1983,workgroup=TRI.LAN'
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
#zmodload zsh/zprof
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=~/.oh-my-zsh
# Uncomment the following line to display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"
source "$HOME/.homesick/repos/homeshick/homeshick.sh"
fpath=($HOME/.homesick/repos/homeshick/completions $fpath)
source ~/antigen.zsh
antigen use oh-my-zsh
antigen theme romkatv/powerlevel10k
antigen bundle docker
antigen bundle git
antigen bundle globalias
antigen bundle last-working-dir
antigen bundle sudo
antigen bundle zsh-users/zsh-history-substring-search
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle wfxr/forgit
antigen bundle paulirish/git-open
antigen bundle popstas/zsh-command-time
antigen bundle MichaelAquilina/zsh-auto-notify
antigen bundle MichaelAquilina/zsh-you-should-use
antigen bundle zsh-users/zsh-autosuggestions
antigen apply
#ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=0'
# command-line fuzzy finder
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
source $HOME/.init_shell
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
#zprof
export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --no-ignore-vcs'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
#export FZF_ALT_C_COMMAND="fd -t d --hidden --follow --exclude \".git\" . $HOME"
export FZF_ALT_C_COMMAND="fd -t d --hidden --follow --exclude \".git\" ."
# Create a cache folder if it isn't exists
if [ ! -d "$HOME/.cache/zsh" ]; then
mkdir -p $HOME/.cache/zsh
fi
# Define a custom file for compdump
export ZSH_COMPDUMP="$HOME/.cache/zsh/zcompdump-$HOST-$ZSH_VERSION"
# User configuration
export EDITOR="code -r"
# Include dotfiles
source ${HOME}/srcs/development_environment/dotfiles/system.bash
source ${HOME}/srcs/development_environment/dotfiles/git.bash
source ${HOME}/srcs/development_environment/dotfiles/docker.bash
source ${HOME}/srcs/development_environment/dotfiles/ros.bash
# To add direnv app
# eval "$(direnv hook zsh)"
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# Finalize Powerlevel10k instant prompt. Should stay at the bottom of ~/.zshrc.
(( ! ${+functions[p10k-instant-prompt-finalize]} )) || p10k-instant-prompt-finalize
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment