diff --git a/.gitmodules b/.gitmodules index 6e10148..6418c37 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,3 +28,6 @@ [submodule "vim/bundle/vim-nix"] path = vim/bundle/vim-nix url = git@github.com:LnL7/vim-nix.git +[submodule "prive"] + path = dotfiles_private + url = git@git.deuxfleurs.fr:adrien/dotfiles_private.git diff --git a/dotfiles_private b/dotfiles_private new file mode 160000 index 0000000..a274885 --- /dev/null +++ b/dotfiles_private @@ -0,0 +1 @@ +Subproject commit a27488549dedf528406d4b41c35bf0708b0aa242 diff --git a/install.sh b/install.sh index 6103087..2acaea1 100755 --- a/install.sh +++ b/install.sh @@ -1,111 +1,146 @@ -#!/bin/bash +#!/usr/bin/env bash # Adrien Luxey - Feb. 2019 # Script inspired by https://github.com/mathiasbynens/dotfiles/blob/master/bootstrap.sh # Get dotfiles dir DOTDIR=$(cd "$(dirname ${BASH_SOURCE})"; pwd) -INSTALLED_FLAG_FILE="$DOTDIR/.installed" -INSTALL_SUBLIME=0 +PRIVATE_DOTFILES_DIR="" +INSTALLED_FLAG_FILE="${DOTDIR}/.installed" +SUBLIME=0 +INSTALL=0 +function main { + parseArgs $@ + # Do the things + if [[ ${INSTALL} -eq 1 ]]; then + if [ ! -f ${INSTALLED_FLAG_FILE} ]; then + echo "Stuff seems already installed. Remove \`.installed\` if this is false." + else + installDependencies && touch ${INSTALLED_FLAG_FILE} + fi + fi + setupDotfiles + echo "All done!" + exit 0 +} function printHelp { cat <<-EOF USAGE: $0 [OPTIONS] OPTIONS: - -s|--sublime Install Sublime Text 3 + -i|--install Install software for Debian (incl. Tmux & vim but not Sublime Text) + -s|--sublime Install & Configure Sublime Text 3 for Debian -h|--help Show this help - The script will install dependencies once (remove ${INSTALLED_FLAG_FILE} to redo) and symlink dotfiles to their destination in your \$HOME. + Sets up dotfiles, + The script will install dependencies once (remove ${INSTALLED_FLAG_FILE} to redo) and symlink dotfiles to their destination in your \${HOME}. EOF exit $1; } -function syncDotfiles { - echo Removing previous dotfiles... - rm $HOME/.zshrc > /dev/null 2>&1 - rm $HOME/.vimrc > /dev/null 2>&1 - rm $HOME/.tmux.conf > /dev/null 2>&1 - rm -rf $HOME/.vim > /dev/null 2>&1 - rm -rf $HOME/.tmux > /dev/null 2>&1 - rm $HOME/.ssh/config > /dev/null 2>&1 +function parseArgs { + while (( "$#" )); do + case "$1" in + -h|--help) + printHelp 0 + shift + ;; + -s|--sublime) + SUBLIME=1 + shift + ;; + -i|--install) + INSTALL=1 + shift + ;; + --) + shift + break + ;; + -*|--*=) + echo "Error: Unsupported flag $1" >&2 + printHelp 1 + ;; + esac + done +} - echo Installing our dotfiles... - ln -s $DOTDIR/zshrc $HOME/.zshrc - ln -s $DOTDIR/vimrc $HOME/.vimrc - ln -s $DOTDIR/tmux.conf $HOME/.tmux.conf - ln -s $DOTDIR/vim $HOME/.vim - ln -s $DOTDIR/tmux $HOME/.tmux - if [ -d "$HOME/.config/sublime-text-3" ]; then - rm -rf $HOME/.config/sublime-text-3/Packages/User > /dev/null 2>&1 - ln -s $DOTDIR/sublime $HOME/.config/sublime-text-3/Packages/User - elif [ -d "$HOME/.config/sublime-text" ]; then - rm -rf $HOME/.config/sublime-text/Packages/User > /dev/null 2>&1 - ln -s $DOTDIR/sublime $HOME/.config/sublime-text/Packages/User +function setupDotfiles { + read -p "Will now remove previous dotfiles. Ready?" -n 1 -r + + rm ${HOME}/.zshrc > /dev/null 2>&1 + rm ${HOME}/.vimrc > /dev/null 2>&1 + rm ${HOME}/.tmux.conf > /dev/null 2>&1 + rm -rf ${HOME}/.vim > /dev/null 2>&1 + rm -rf ${HOME}/.tmux > /dev/null 2>&1 + rm ${HOME}/.ssh/config > /dev/null 2>&1 + + echo Setting up dotfiles... + ln -s ${DOTDIR}/zshrc ${HOME}/.zshrc + ln -s ${DOTDIR}/vimrc ${HOME}/.vimrc + ln -s ${DOTDIR}/tmux.conf ${HOME}/.tmux.conf + ln -s ${DOTDIR}/vim ${HOME}/.vim + ln -s ${DOTDIR}/tmux ${HOME}/.tmux + mkdir -p ${HOME}/.ssh + ln -s ${DOTDIR}/dotfiles_private/ssh_config ~/.ssh/config + + # Setup Sublime Text + if [[ ${SUBLIME} -eq 1 ]]; then + echo + if [ -d "${HOME}/.config/sublime-text-3" ]; then + rm -rf ${HOME}/.config/sublime-text-3/Packages/User > /dev/null 2>&1 + ln -s ${DOTDIR}/sublime ${HOME}/.config/sublime-text-3/Packages/User + elif [ -d "${HOME}/.config/sublime-text" ]; then + rm -rf ${HOME}/.config/sublime-text/Packages/User > /dev/null 2>&1 + ln -s ${DOTDIR}/sublime ${HOME}/.config/sublime-text/Packages/User + fi fi - mkdir -p $HOME/.ssh - ln -s $DOTDIT/ssh_config ~/.ssh/config } function installDependencies { - echo Installing dependencies... + read -p "Will now install apt dependencies, OhMyZSH (wget | sh) and sub-repos. Ready?" -n 1 -r # Dependencies sudo apt update > /dev/null 2>&1 - sudo apt install -y apt-transport-https curl zsh tmux autojump fonts-firacode fonts-powerline > /dev/null 2>&1 + sudo apt install -y apt-transport-https curl zsh tmux autojump \ + fonts-firacode fonts-powerline > /dev/null 2>&1 # Install Sublime Text - if [[ ${INSTALL_SUBLIME} -eq 1 ]]; then + if [[ ${SUBLIME} -eq 1 ]]; then echo Installing Sublime Text 3... - wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add - > /dev/null 2>&1 - echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list > /dev/null 2>&1 - #sudo apt update > /dev/null 2>&1 + wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | \ + gpg --dearmor | \ + sudo tee /etc/apt/trusted.gpg.d/sublimehq-archive.gpg > /dev/null + echo "deb https://download.sublimetext.com/ apt/stable/" | \ + sudo tee /etc/apt/sources.list.d/sublime-text.list > /dev/null 2>&1 + sudo apt update > /dev/null 2>&1 sudo apt install sublime-text -y > /dev/null 2>&1 fi # Install Oh My Zsh - if [ ! -d "$HOME/.oh-my-zsh" ]; then + if [ ! -d "${HOME}/.oh-my-zsh" ]; then echo Installing Oh-My-Zsh... sh -c "$(wget -q https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" # Install powerlevel9k theme in Oh-My-Zsh - if [ ! -d "$HOME/.oh-my-zsh/custom/themes/powerlevel9k" ]; then + if [ ! -d "${HOME}/.oh-my-zsh/custom/themes/powerlevel9k" ]; then echo Installing Powerlevel9k theme... - git clone https://github.com/bhilburn/powerlevel9k.git $HOME/.oh-my-zsh/custom/themes/powerlevel9k > /dev/null 2>&1 + git clone https://github.com/bhilburn/powerlevel9k.git \ + ${HOME}/.oh-my-zsh/custom/themes/powerlevel9k > /dev/null 2>&1 fi fi - echo "Pulling git submodules..." - cd $DOTDIR && (git submodule update --init >> /dev/null 2>&1) || echo "'git submobule update --init' failed, is your SSH key available on GitHub?" && exit -1; + read -p "Adding adrien/dotfiles_private submodule... Ready?" -n 1 -r + git submodule add --name prive git@git.deuxfleurs.fr:adrien/dotfiles_private.git prive + + + echo Pulling git submodules... + cd ${DOTDIR} && (git submodule update --init >> /dev/null 2>&1) || \ + echo "'git submobule update --init' failed, is your SSH key available on GitHub?" && exit -1; # Make ZSH is the current SHELL echo $SHELL | grep zsh > /dev/null || chsh -s $(which zsh) } -# Parse command-line arguments -while (( "$#" )); do - case "$1" in - -h|--help) - printHelp 0 - ;; - -s|--sublime) - INSTALL_SUBLIME=1 - shift - ;; - --) - shift - break - ;; - -*|--*=) - echo "Error: Unsupported flag $1" >&2 - printHelp 1 - ;; - esac -done - -if [ ! -f $INSTALLED_FLAG_FILE ]; then - installDependencies && touch $INSTALLED_FLAG_FILE -fi -syncDotfiles -echo "All done!" -exit 0 +main $@ diff --git a/tmux.conf b/tmux.conf index f571eb5..6311bbb 100644 --- a/tmux.conf +++ b/tmux.conf @@ -1,5 +1,5 @@ # KEY BINDINGS -# Alex Auvolat + Adrien Luxey additions +# Adrien Luxey ########################### ### Packages management ### @@ -78,6 +78,27 @@ bind -T off F10 \ refresh-client -S ##################################################### +# Vim Tmux Navigator +# Smart pane switching with awareness of Vim splits. +# See: https://github.com/christoomey/vim-tmux-navigator +is_vim="ps -o state= -o comm= -t '#{pane_tty}' \ + | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf)(diff)?$'" +bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L' +bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D' +bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U' +bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R' +#tmux_version='$(tmux -V | sed -En "s/^tmux ([1-9]+(.[0-9]+)?).*/\1/p")' +#if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \ +# "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'" +#if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \ +# "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'" + +#bind-key -T copy-mode-vi 'C-h' select-pane -L +#bind-key -T copy-mode-vi 'C-j' select-pane -D +#bind-key -T copy-mode-vi 'C-k' select-pane -U +#bind-key -T copy-mode-vi 'C-l' select-pane -R +#bind-key -T copy-mode-vi 'C-m' select-pane -l + # Notes : # prefix ~ --> show-messages (see previous messages) @@ -116,8 +137,8 @@ bind l select-pane -R bind k select-pane -U bind j select-pane -D # switch windows using bindings C-q C-hl -unbind ^H -unbind ^L +#unbind ^H +#unbind ^L bind ^H previous-window bind ^L next-window diff --git a/vim/bundle/vim-nix b/vim/bundle/vim-nix index 7d23e97..1e8d3cc 160000 --- a/vim/bundle/vim-nix +++ b/vim/bundle/vim-nix @@ -1 +1 @@ -Subproject commit 7d23e97d13c40fcc6d603b291fe9b6e5f92516ee +Subproject commit 1e8d3cc4d74f40fb384cd1739739543fe117ff61 diff --git a/vimrc b/vimrc index 7dae9a6..29db994 100644 --- a/vimrc +++ b/vimrc @@ -11,10 +11,12 @@ call vundle#begin() " let Vundle manage Vundle, required Plugin 'VundleVim/Vundle.vim' +Plugin 'christoomey/vim-tmux-navigator' " Vim Tmux Navigator + Plugin 'vim-airline/vim-airline' " Airline bar Plugin 'vim-airline/vim-airline-themes' " Airline themes -Plugin 'LnL7/vim-nix' +Plugin 'LnL7/vim-nix' " Nix " Themes " Plugin 'arcticicestudio/nord-vim' @@ -27,6 +29,50 @@ filetype plugin indent on " required " End Vundle config " """"""""""""""""""""" +"""""""""""""" +" Navigation " +"""""""""""""" + +" navigation between splits +" https://thoughtbot.com/blog/vim-splits-move-faster-and-more-naturally#easier-split-navigations +"nnoremap +"nnoremap +"nnoremap +"nnoremap + +" From https://stackoverflow.com/questions/33245317/vim-and-azerty-keyboards +" 1. Move to the end of the line +noremap m $ +" 2. Search backward for the word under the cursor +noremap ยต # +" 3. Navigate to the help tag under the cursor +" noremap ' + +" Scroller comme un pro +" N'utilise que j et k +" Ctrl-e & Ctrl-y pour scroller dans un document +set scrolloff=12 + +" Ctrl+W +/-: increase/decrease height (ex. 20+) +" Ctrl+W >/<: increase/decrease width (ex. 30<) +" Ctrl+W =: equalize width and height of all windows +" Ctrl+W _: set height (ex. 50_) +" Ctrl+W |: set width (ex. 50|) + +"""""""""""""""""""" +" Tmux integration " +"""""""""""""""""""" + +" auto-reload tmux conf when updated +autocmd bufwritepost ~/dotfiles/.tmux.conf execute ':!tmux source-file %' + + +"""""""" +" Misc " +"""""""" + +" Allow saving of files as sudo when I forgot to start vim using sudo. +cmap w!! w !sudo tee > /dev/null % " Styling syntax enable @@ -42,8 +88,7 @@ set noundofile " Line numbering (hybrid: relative and absolute) set number relativenumber -augroup numbertoggle - autocmd! +augroup numbertoggle autocmd! autocmd BufEnter,FocusGained,InsertLeave * set relativenumber autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber augroup END @@ -59,6 +104,52 @@ augroup END " Adapted from https://github.com/jessfraz/.vim/blob/master/vimrc " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" ----------------------------------------- " +" File Type settings " +" ----------------------------------------- " + +au BufNewFile,BufRead *.vim setlocal noet ts=4 sw=4 sts=4 +au BufNewFile,BufRead *.txt setlocal noet ts=4 sw=4 +"#au BufNewFile,BufRead *.md setlocal spell noet ts=4 sw=4 +au BufNewFile,BufRead *.md setlocal nospell noet ts=4 sw=4 +au BufNewFile,BufRead *.yml,*.yaml setlocal expandtab ts=2 sw=2 +au BufNewFile,BufRead *.cpp setlocal expandtab ts=2 sw=2 +au BufNewFile,BufRead *.hpp setlocal expandtab ts=2 sw=2 +au BufNewFile,BufRead *.json setlocal expandtab ts=2 sw=2 +au BufNewFile,BufRead *.jade setlocal expandtab ts=2 sw=2 + +augroup filetypedetect + au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux + au BufNewFile,BufRead .nginx.conf*,nginx.conf* setf nginx +augroup END + +au FileType nginx setlocal noet ts=4 sw=4 sts=4 + +" Go settings +au BufNewFile,BufRead *.go setlocal noet ts=4 sw=4 sts=4 +" autocmd BufEnter *.go colorscheme nofrils-dark + +" scala settings +autocmd BufNewFile,BufReadPost *.scala setl shiftwidth=2 expandtab + +" Markdown Settings +autocmd BufNewFile,BufReadPost *.md setl ts=4 sw=4 sts=4 expandtab + +" lua settings +autocmd BufNewFile,BufRead *.lua setlocal noet ts=4 sw=4 sts=4 + +" Dockerfile settings +autocmd FileType dockerfile set noexpandtab + +" shell/config/systemd settings +autocmd FileType fstab,systemd set noexpandtab +autocmd FileType gitconfig,sh,toml set noexpandtab + +" python indent +autocmd BufNewFile,BufRead *.py setlocal tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80 smarttab expandtab + +""""""""""""""""""" + set splitright " Split vertical windows right to the current windows set splitbelow " Split horizontal windows below to the current windows set encoding=utf-8 " Set default encoding to UTF-8 @@ -123,54 +214,6 @@ map q: :q let &t_SI .= "\[?2004h" let &t_EI .= "\[?2004l" -" Allow saving of files as sudo when I forgot to start vim using sudo. -cmap w!! w !sudo tee > /dev/null % - -" ----------------------------------------- " -" File Type settings " -" ----------------------------------------- " - -au BufNewFile,BufRead *.vim setlocal noet ts=4 sw=4 sts=4 -au BufNewFile,BufRead *.txt setlocal noet ts=4 sw=4 -"#au BufNewFile,BufRead *.md setlocal spell noet ts=4 sw=4 -au BufNewFile,BufRead *.md setlocal nospell noet ts=4 sw=4 -au BufNewFile,BufRead *.yml,*.yaml setlocal expandtab ts=2 sw=2 -au BufNewFile,BufRead *.cpp setlocal expandtab ts=2 sw=2 -au BufNewFile,BufRead *.hpp setlocal expandtab ts=2 sw=2 -au BufNewFile,BufRead *.json setlocal expandtab ts=2 sw=2 -au BufNewFile,BufRead *.jade setlocal expandtab ts=2 sw=2 - -augroup filetypedetect - au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux - au BufNewFile,BufRead .nginx.conf*,nginx.conf* setf nginx -augroup END - -au FileType nginx setlocal noet ts=4 sw=4 sts=4 - -" Go settings -au BufNewFile,BufRead *.go setlocal noet ts=4 sw=4 sts=4 -" autocmd BufEnter *.go colorscheme nofrils-dark - -" scala settings -autocmd BufNewFile,BufReadPost *.scala setl shiftwidth=2 expandtab - -" Markdown Settings -autocmd BufNewFile,BufReadPost *.md setl ts=4 sw=4 sts=4 expandtab - -" lua settings -autocmd BufNewFile,BufRead *.lua setlocal noet ts=4 sw=4 sts=4 - -" Dockerfile settings -autocmd FileType dockerfile set noexpandtab - -" shell/config/systemd settings -autocmd FileType fstab,systemd set noexpandtab -autocmd FileType gitconfig,sh,toml set noexpandtab - -" python indent -autocmd BufNewFile,BufRead *.py setlocal tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80 smarttab expandtab - - """""""""""""""""""""""""""""""""""""""""""""""""""""""""" " End https://github.com/jessfraz/.vim/blob/master/vimrc " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""