From 07d553052d528edc71b1042e87e0e5c6865523c0 Mon Sep 17 00:00:00 2001
From: m-guberina <gubi.guberina@gmail.com>
Date: Mon, 30 Sep 2024 12:18:08 +0200
Subject: [PATCH] docker is now nice to use

---
 Dockerfile                                |  39 ++++--
 build-user.sh                             |   5 +
 create_user.sh                            |  34 +++++
 docs/installing_ubuntu.md                 |   2 +-
 dot_files_for_docker/.vimrc               | 159 ++++++++++++++++++++++
 dot_files_for_docker/.zshrc               | 123 +++++++++++++++++
 dot_files_for_docker/global_extra_conf.py |   6 +
 7 files changed, 355 insertions(+), 13 deletions(-)
 create mode 100644 build-user.sh
 create mode 100644 create_user.sh
 create mode 100644 dot_files_for_docker/.vimrc
 create mode 100644 dot_files_for_docker/.zshrc
 create mode 100644 dot_files_for_docker/global_extra_conf.py

diff --git a/Dockerfile b/Dockerfile
index 8591d43..7d92c81 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,8 +1,5 @@
 FROM ubuntu:jammy
-WORKDIR /usr/local/ur_simple_control
 
-# copy repo to workdir
-COPY . .
 
 # install pyhton3-tk without questions
 ARG DEBIAN_FRONTEND=noninteractive
@@ -11,18 +8,36 @@ ENV TZ=Europe/Stockholm
 RUN apt update && apt upgrade
 RUN apt install -y python3  \
                 python3-pip \
-                python3-tk
+                python3-tk \
+                ipython3 \
+                sudo \
+                vim \
+                vim-youcompleteme \
+                zsh \
+                zsh-syntax-highlighting \
+                python3-python-qt-binding
+
+# qt-binding is a really unnecessary 300MB, but i don't want
+# to do more matplotlib hacks
+
+# make the environment more usable
+# create user
+RUN useradd -m -s /bin/zsh -G sudo -u 1001 student
+
+WORKDIR /home/student/
+RUN passwd -d student
+USER student
+# copy repo to workdir
+COPY --chown=student . .
+RUN mkdir -p .cache/zsh/
+COPY ./dot_files_for_docker/.vimrc /home/student/
+COPY ./dot_files_for_docker/.zshrc /home/student/
+COPY ./dot_files_for_docker/global_extra_conf.py /home/student/
+RUN vam install youcompleteme
 
 # this is enough to run clik
+WORKDIR /home/student/
 RUN pip install -e ./python/
 RUN pip install pin matplotlib meshcat ur_rtde \
                 qpsolvers ecos
 
-# open up meshcat ports
-# make this a range
-# TODO: figure out how to actually expose meshcat,
-# this isn't enough
-EXPOSE 7000
-
-# TODO: figure out what's needed to be able to open
-# matplotlib windows!
diff --git a/build-user.sh b/build-user.sh
new file mode 100644
index 0000000..7d92295
--- /dev/null
+++ b/build-user.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+echo "student ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
+echo "groupadd -g $(id -g $USER) $USER" >> create_user.sh
+echo "useradd $USER -u $(id -u $USER) -g $(id -g $USER) -m -s /bin/bash" >> create_user.sh
diff --git a/create_user.sh b/create_user.sh
new file mode 100644
index 0000000..edb46b1
--- /dev/null
+++ b/create_user.sh
@@ -0,0 +1,34 @@
+echo: echo [-neE] [arg ...]
+    Write arguments to the standard output.
+    
+    Display the ARGs, separated by a single space character and followed by a
+    newline, on the standard output.
+    
+    Options:
+      -n	do not append a newline
+      -e	enable interpretation of the following backslash escapes
+      -E	explicitly suppress interpretation of backslash escapes
+    
+    `echo' interprets the following backslash-escaped characters:
+      \a	alert (bell)
+      \b	backspace
+      \c	suppress further output
+      \e	escape character
+      \E	escape character
+      \f	form feed
+      \n	new line
+      \r	carriage return
+      \t	horizontal tab
+      \v	vertical tab
+      \\	backslash
+      \0nnn	the character whose ASCII code is NNN (octal).  NNN can be
+    		0 to 3 octal digits
+      \xHH	the eight-bit character whose value is HH (hexadecimal).  HH
+    		can be one or two hex digits
+      \uHHHH	the Unicode character whose value is the hexadecimal value HHHH.
+    		HHHH can be one to four hex digits.
+      \UHHHHHHHH the Unicode character whose value is the hexadecimal value
+    		HHHHHHHH. HHHHHHHH can be one to eight hex digits.
+    
+    Exit Status:
+    Returns success unless a write error occurs.
diff --git a/docs/installing_ubuntu.md b/docs/installing_ubuntu.md
index 8d0aae2..47b05cc 100644
--- a/docs/installing_ubuntu.md
+++ b/docs/installing_ubuntu.md
@@ -62,7 +62,7 @@ TODO: add volume mounting (copy Marcus' approach with a user and /home/user/) an
 4. open docker desktop, navigate to Settings (by user/account button) -> Resources -> Network -> click on enable host networking
 4. open wsl (type wsl in powershell) and navigate to git folder (now in wsl) with cd /mnt/Users/YOURUSERNAME/PATH_TO_GIT_FOLDER
 5. build the image with "docker build -t ur_simple_control ."
-6. to run the image FIRST RUN "xhost +" EVERY TIME, THEN RUN  "docker run --rm -it --net=host -e DISPLAY=$DISPLAY -v /tmp:/tmp ur_simple_control"
+6. to run the image FIRST RUN "xhost +" EVERY TIME, THEN RUN  "docker run --rm -it --net=host -e DISPLAY=$DISPLAY -v /tmp:/tmp ur_simple_control /bin/zsh"
 7. verify installation by running an example with --visualize-manipulator and --real-time-plotting arguments
 
 #### option 2) Native installation
diff --git a/dot_files_for_docker/.vimrc b/dot_files_for_docker/.vimrc
new file mode 100644
index 0000000..345fcb4
--- /dev/null
+++ b/dot_files_for_docker/.vimrc
@@ -0,0 +1,159 @@
+"ricing
+set encoding=utf-8
+set tabstop=4
+set number
+set relativenumber
+set nocompatible
+syntax enable
+filetype plugin on
+" add <> matching for html
+set matchpairs+=<:>
+set title
+set showmatch
+set showmode
+set ruler
+set ignorecase "case insensitive matching 
+set smartcase
+set incsearch
+set hlsearch
+" remember that to remove highlights
+" temporarily, you can do :nohlsearch
+
+" show me the current filesystem
+nnoremap fs :40Lex<CR>
+nnoremap tfs :tabe +Ex<CR>
+
+
+"finding file
+"search down into subfolders
+"provides tab-completition for file-related taska
+set path +=**
+set wildmenu
+
+" automatically set fold if a c++ file is opened
+autocmd FileType cpp set foldmethod=syntax
+autocmd FileType hpp set foldmethod=syntax
+" likewise if a python file is opened
+autocmd FileType python set foldmethod=indent
+autocmd FileType python nnoremap <space> za
+autocmd FileType python vnoremap <space> zf
+
+
+set nocompatible              " be iMproved, required
+filetype off                  " required
+
+" set the runtime path to include Vundle and initialize
+" ===================================================================================
+"set rtp+=~/.vim/bundle/Vundle.vim
+"call vundle#begin()
+"" alternatively, pass a path where Vundle should install plugins
+""call vundle#begin('~/some/path/here')
+"
+"" let Vundle manage Vundle, required
+"Plugin 'VundleVim/Vundle.vim'
+"
+""" track ultisnips
+"Plugin 'SirVer/ultisnips'
+"
+"" and then add ultisnips
+"Plugin 'honza/vim-snippets'
+"
+""wal colors
+"Plugin 'dylanaraps/wal.vim'
+"
+"" run stuff async (compile and still look at code)
+"Plugin 'skywind3000/asyncrun.vim'
+"
+"Plugin 'ycm-core/YouCompleteMe'
+"" The following are examples of different formats supported.
+"" Keep Plugin commands between vundle#begin/end.
+"" plugin on GitHub repo
+"" plugin from http://vim-scripts.org/vim/scripts.html
+"" Plugin 'L9'
+"" Git plugin not hosted on GitHub
+"" git repos on your local machine (i.e. when working on your own plugin)
+"" The sparkup vim script is in a subdirectory of this repo called vim.
+"" Pass the path to set the runtimepath properly.
+"" Install L9 and avoid a Naming conflict if you've already installed a
+"" different version somewhere else.
+"" Plugin 'ascenator/L9', {'name': 'newL9'}
+"
+"" All of your Plugins must be added before the following line
+"call vundle#end()            " required
+"filetype plugin indent on    " required
+" ===================================================================================
+"
+"
+" To ignore plugin indent changes, instead use:
+"filetype plugin on
+"
+" Brief help
+" :PluginList       - lists configured plugins
+" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
+" :PluginSearch foo - searches for foo; append `!` to refresh local cache
+" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
+"
+" see :h vundle for more details or wiki for FAQ
+" Put your non-Plugin stuff after this line
+
+
+
+
+"adding c completion for ycm
+"let g:ycm_clangd_binary_path = "/home/gospodar/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd"
+let g:ycm_clangd_binary_path = "/usr/bin/clangd"
+" adding the youcompleteme's global conf for python
+let g:ycm_python_interpreter_path = ''
+let g:ycm_python_sys_path = []
+let g:ycm_extra_conf_vim_data = [
+  \  'g:ycm_python_interpreter_path',
+  \  'g:ycm_python_sys_path'
+  \]
+let g:ycm_global_ycm_extra_conf = '~/global_extra_conf.py'
+
+" let me see all of the god damn error messages
+let g:ycm_max_diagnostics_to_display=0
+
+
+" Signature help is triggered in insert mode automatically when g:ycm_auto_trigger is enabled and is not supported when it is not enabled.
+" so here we go
+" --> it's on by default
+"
+"  adding keyboard shortcuts for YCMCompleter commands so that i don't need
+"  command mode
+nmap gsw <Plug>(YCMFindSymbolInWorkspace)
+nmap gsd <Plug>(YCMFindSymbolInDocument)
+nnoremap gdf :YcmCompleter GoToDefinition<CR>
+nnoremap gdc :YcmCompleter GoToDeclaration<CR>
+nnoremap gdo :YcmCompleter GoToDocumentOutline<CR>
+nnoremap doc :YcmCompleter GetDoc<CR>
+nnoremap fix :YcmCompleter FixIt<CR>
+nnoremap type :YcmCompleter GetType<CR>
+nnoremap diag :YcmShowDetailedDiagnosti<CR>
+nnoremap format :YcmCompleter Format<CR>
+
+" and now do the trigger configuration
+let g:UltiSnipsExpandTrigger="<c-k>"
+let g:UltiSnipsJumpForwardTrigger="<c-k>"
+let g:UltiSnipsJumpBackwardTrigger="<c-l>"
+let g:UltiSnipsEditSplit="vertical"
+let g:UltiSnipsListSnippets="<c-]>"
+
+"colorscheme wal
+
+" configure AsyncRun to be a bit more chill
+let g:asyncrun_open = 5
+autocmd FileType tex let g:asyncrun_open = 0
+nnoremap cl :cclose<CR>
+
+
+" switched to caps being escape 'couse control is now in a better position
+"au VimEnter * !setxkbmap -option caps:ctrl_modifier
+"au VimLeave * !setxkbmap -option
+"
+" my cool commands
+" this prints our a python variable 
+autocmd FileType python nnoremap <C-p> yiwA
print("pa")��aa
print(pa)
+
+" end the W is not a command fiasko
+cnoreabbrev <expr> W ((getcmdtype() is# ':' && getcmdline() is# 'W')?('w'):('W'))
diff --git a/dot_files_for_docker/.zshrc b/dot_files_for_docker/.zshrc
new file mode 100644
index 0000000..01c34ba
--- /dev/null
+++ b/dot_files_for_docker/.zshrc
@@ -0,0 +1,123 @@
+#config for zsh
+#add .local/bin to path
+PATH=$PATH:~/.local/bin
+
+# Enable colors and change prompt:
+autoload -U colors && colors
+PS1="%B%{$fg[red]%}[%{$fg[green]%}%n%{$fg[blue]%}@%{$fg[green]%}%M %{$fg[yellow]%}%~%{$fg[red]%}]%{$reset_color%}$%b "
+
+# terminal colors from wal
+#(cat ~/.cache/wal/sequences &)
+
+# enable color support of ls and also add handy aliases
+if [ -x /usr/bin/dircolors ]; then
+    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
+    alias ls='ls --color=auto'
+    #alias dir='dir --color=auto'
+    #alias vdir='vdir --color=auto'
+
+    alias grep='grep --color=auto'
+    alias fgrep='fgrep --color=auto'
+    alias egrep='egrep --color=auto'
+fi
+
+# alias for l -t | head -20
+alias lt='ls -t | head -20'
+# make info usable
+alias info='info --vi-keys'
+
+# alias for python (only for ubuntu)
+#alias python='python3'
+#alias ipython='ipython3'
+
+
+# some more ls aliases
+alias ll='ls -alF'
+alias la='ls -A'
+alias l='ls -CF'
+# History in cache directory:
+HISTSIZE=10000
+SAVEHIST=10000
+HISTFILE=~/.cache/zsh/history
+
+# Basic auto/tab complete:
+autoload -U compinit
+zstyle ':completion:*' menu select
+zmodload zsh/complist
+compinit
+_comp_options+=(globdots)		# Include hidden files.
+
+# vi mode
+bindkey -v
+export KEYTIMEOUT=1
+
+# Use vim keys in tab complete menu:
+bindkey -M menuselect 'h' vi-backward-char
+bindkey -M menuselect 'k' vi-up-line-or-history
+bindkey -M menuselect 'l' vi-forward-char
+bindkey -M menuselect 'j' vi-down-line-or-history
+bindkey -v '^?' backward-delete-char
+
+# Change cursor shape for different vi modes.
+#function zle-keymap-select {
+#  if [[ ${KEYMAP} == vicmd ]] ||
+#     [[ $1 = 'block' ]]; then
+#    echo -ne '\e[1 q'
+#  elif [[ ${KEYMAP} == main ]] ||
+#       [[ ${KEYMAP} == viins ]] ||
+#       [[ ${KEYMAP} = '' ]] ||
+#       [[ $1 = 'beam' ]]; then
+#    echo -ne '\e[5 q'
+#  fi
+#}
+#zle -N zle-keymap-select
+#zle-line-init() {
+#    zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
+#    echo -ne "\e[5 q"
+#}
+#zle -N zle-line-init
+#echo -ne '\e[5 q' # Use beam shape cursor on startup.
+#preexec() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt.
+
+# Use lf to switch directories and bind it to ctrl-o
+lfcd () {
+    tmp="$(mktemp)"
+    lf -last-dir-path="$tmp" "$@"
+    if [ -f "$tmp" ]; then
+        dir="$(cat "$tmp")"
+        rm -f "$tmp"
+        [ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir"
+    fi
+}
+bindkey -s '^o' 'lfcd\n'
+
+# Edit line in vim with ctrl-e:
+autoload edit-command-line; zle -N edit-command-line
+bindkey '^v' edit-command-line
+
+# add backsearching
+bindkey '^r' history-incremental-search-backward
+
+# aliases
+export VISUAL=vim
+export EDITOR="$VISUAL"
+export SUDO_VISUAL="$VISUAL"
+export SUDO_EDITOR="$VISUAL"
+
+# use clang by default
+# not in docker tho
+#export CC=/usr/bin/clang
+#export CXX=/usr/bin/clang++
+
+
+# Load aliases and shortcuts if existent.
+[ -f "$HOME/.config/shortcutrc" ] && source "$HOME/.config/shortcutrc"
+[ -f "$HOME/.config/aliasrc" ] && source "$HOME/.config/aliasrc"
+
+
+#export PYTHONPATH=/usr/local/lib/python3.12/site-packages:$PYTHONPATH # Adapt your desired python version here
+
+#export PATH="/home/gospodar/.local/bin:$PATH"
+# Load zsh-syntax-highlighting; should be last.
+source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 2>/dev/null
+#@aquaductape
diff --git a/dot_files_for_docker/global_extra_conf.py b/dot_files_for_docker/global_extra_conf.py
new file mode 100644
index 0000000..2d0a945
--- /dev/null
+++ b/dot_files_for_docker/global_extra_conf.py
@@ -0,0 +1,6 @@
+def Settings( **kwargs ):
+  client_data = kwargs[ 'client_data' ]
+  return {
+    'interpreter_path': client_data[ 'g:ycm_python_interpreter_path' ],
+    'sys_path': client_data[ 'g:ycm_python_sys_path' ]
+  }
-- 
GitLab