From e261062072018486c6507ae1986843bf9302dbbf Mon Sep 17 00:00:00 2001 From: Hizenberg469 Date: Sun, 31 Aug 2025 20:09:09 +0300 Subject: [PATCH] First phase of env-setup done -- Next phase is to make it more finer --- .vimrc | 353 +++++++++++++++++++++++++++++++++++++++++++++++++++ dummy.sh | 8 ++ env_setup.sh | 242 +++++++++++++++++++++++++++++++++++ 3 files changed, 603 insertions(+) create mode 100644 .vimrc create mode 100755 dummy.sh create mode 100755 env_setup.sh diff --git a/.vimrc b/.vimrc new file mode 100644 index 0000000..f9fd236 --- /dev/null +++ b/.vimrc @@ -0,0 +1,353 @@ +" c: Automatically break comments using the textwidth value. +" r: Automatically insert the comment leader when hitting in insert mode. +" o: Automatically insert the comment leader when hitting 'o' or 'O' in normal mode. +" n: Recognize numbered lists. When hitting in insert mode. +" m: Automatically break the current line before inserting a new comment line. +set formatoptions+=cronm + +" This sets the width of a tab character to 4 spaces. +set tabstop=4 + +" This sets the number of spaces used when the key is pressed in insert +" mode to 4. +set softtabstop=4 + +" This sets the number of spaces used for each indentation level when using +" the '>' and '<' commands, as well as the autoindent feature. +set shiftwidth=4 + +" This setting enables automatic indentation, which will copy the indentation +" of the current line when starting a new line. +set autoindent +set smartindent + +" This disables the automatic conversion of tabs to spaces when you press the +" key. +set expandtab +set smarttab + +" Save 1,000 items in history +set history=1000 + +" Show the line and column number of the cursor position +set ruler + +" Display the incomplete commands in the bottom right-hand side of your screen. +set showcmd + +" Display completion matches on your status line +set wildmenu + +" Show a few lines of context around the cursor +set scrolloff=5 + +" Highlight search matches +set hlsearch + +" Enable incremental searching +set incsearch + +" Ignore case when searching +set ignorecase + +" Override the 'ignorecase' option if the search pattern contains upper case characters. +set smartcase + +" This enables the use of the mouse in all modes (normal, visual, insert, +" command-line, etc.). +set mouse=a + +" This displays line numbers in the left margin. +set number + +" This disables the creation of backup files. +set nobackup + +set hidden + + +" This disables the creation of swap files. +set noswapfile + +" Automatically reload files when they change +set autoread + +" Enable spell checking +set spell +set spelllang=en + +" Highlight the current line +set cursorline + +" Highlight the 100th column +set colorcolumn=100 + +" Set text width to 100 +set textwidth=100 + +" This maps the '<' and '>' keys in visual mode to shift the selected text one +" shift width to the left or right and reselect the shifted text. +vnoremap < >gv + +" The next four lines define key mappings for switching between windows using +" Ctrl + hjkl keys +nmap :wincmd k +nmap :wincmd j +nmap :wincmd h +nmap :wincmd l + +" The next four lines define key mappings for resizing windows using Alt + +" hjkl keys: +map :vertical res -5 +map :vertical res +5 +map :res -5 +map :res +5 + +" These lines define key mappings for moving the cursor 10 spaces at a time +" using Shift + arrow keys: +nmap 10l +nmap 10h +nmap 10j +nmap 10k + +" Enable folding +set foldenable +" Configure fold method +set foldmethod=marker +" Set the fold level to start with all folds open +set foldlevelstart=99 +" Set the fold nesting level (default is 20) +set foldnestmax=10 +" Automatically close folds when the cursor leaves them +set foldclose=all +" Open folds upon all motion events +set foldopen=all + + + + + +" To install vim-plug +let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim' +if empty(glob(data_dir . '/autoload/plug.vim')) + silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' + autocmd VimEnter * PlugInstall --sync | source $MYVIMRC +endif + + +" To install using vim-plug: :PlugInstall +" To install the plugin + + +call plug#begin() + + Plug 'dense-analysis/ale' " linting and fixing code. + "Plug 'airblade/vim-gitgutter' " a git diff in the sign colomn. + Plug 'habamax/vim-asciidoctor' " Feature-full environment for ASCII Docs. + Plug 'majutsushi/tagbar' " Utility to easily browse the tag. + Plug 'mbbill/undotree' " Utility to view undo history + Plug 'morhetz/gruvbox' " retro-inspired color scheme + Plug 'luochen1990/rainbow' " For rainbow coloring of Parentheses + Plug 'preservim/nerdtree' " A filesystem explorer + Plug 'puremourning/vimspector' " A multi-language debugging plugin + Plug 'tpope/vim-dispatch' " A plugin for async executing long-running commands + Plug 'tpope/vim-fugitive' " A popular Git Wrapper. + Plug 'tpope/vim-speeddating' " A plugin that allow you to quickly adjust dates. + Plug 'vim-airline/vim-airline' " A lightweight and customizable status line. + Plug 'vim-scripts/c.vim' " A packages of tools for C and C++. + Plug 'vimwiki/vimwiki' " A personal wiki plugin for Vim. + Plug 'voldikss/vim-floaterm' " A plugin for floating terminal inside vim. + Plug 'tpope/vim-commentary' " Commenting tool + Plug 'vim-airline/vim-airline-themes' " Themes for airline + Plug 'vim-scripts/DoxygenToolkit.vim' " Doxygen support + Plug 'vim-scripts/SpellCheck' " Spell checking + Plug 'ludovicchabant/vim-gutentags' " for tag managements for projects + Plug 'skywind3000/gutentags_plus' " Working with gtags and cscope +call plug#end() + + +" Plugin enable option + + +" For dense-analysis/ale - linting +" Ignore git commit when linting (highly annoying) +let g:ale_pattern_options = { + \ 'COMMIT_EDITMSG$': {'ale_linters': [], 'ale_fixers': []} + \ } +let g:ale_linters = { + \ 'yaml': ['yamllint'], + \ 'cpp': ['clangtidy'], + \ 'c': ['clangtidy'], + \ 'asciidoc': ['cspell'], + \ 'markdown': ['cspell'] + \ } +let g:ale_fixers = { + \ 'cpp': ['clang-format'], + \ 'c': ['clang-format']} + +" Automatic fixing +autocmd FileType c nnoremap f (ale_fix) + +" General settings +let g:ale_linters_explicit = 1 +let g:ale_completion_enabled = 1 +let g:ale_echo_msg_format = '[%linter%] %s [%severity%]' +let g:ale_set_balloons=1 +let g:ale_hover_to_floating_preview=1 +let g:ale_use_global_executables = 1 +let g:ale_sign_column_always = 1 +let g:ale_disable_lsp = 1 + +" C++ linting +let g:ale_cpp_clangtidy_options = '-checks=-*,cppcoreguidelines-*' +let g:ale_cpp_clangtidy_checks = ['readability-*,performance-*,bugprone-*,misc-*'] +let g:ale_cpp_clangtidy_checks += ['clang-analyzer-cplusplus-doc-comments'] + +" C linting +let g:ale_c_clangtidy_options = '-checks=-*,cppcoreguidelines-*' +let g:ale_c_clangtidy_checks = ['readability-*,performance-*,bugprone-*,misc-*'] +let g:ale_c_clangtidy_checks += ['-readability-function-cognitive-complexity'] +let g:ale_c_clangtidy_checks += ['-readability-identifier-length'] +let g:ale_c_clangtidy_checks += ['-misc-redundant-expression'] +let g:ale_c_build_dir_names = ['build', 'release', 'debug'] + +" This function searches for the first clang-tidy config in parent directories and sets it +function! SetClangTidyConfig() + let l:config_file = findfile('.clang-tidy', expand('%:p:h').';') + if !empty(l:config_file) + let g:ale_c_clangtidy_options = '--config=' . l:config_file + let g:ale_cpp_clangtidy_options = '--config=' . l:config_file + endif +endfunction + +" Run this for c and c++ files +autocmd BufRead,BufNewFile *.c,*.cpp,*.h,*.hpp call SetClangTidyConfig() + +" Set this. Airline will handle the rest. +let g:airline#extensions#ale#enabled = 1 + + + + + +" For tpope/vim-fugitive - git integration. + +nnoremap gg :Git +nnoremap gs :Git status +nnoremap gc :Git commit +nnoremap gb :Git blame +nnoremap gd :Git difftool +nnoremap gm :Git mergetool +nnoremap gdv :Gvdiffsplit +nnoremap gdh :Gdiffsplit + + +" For airblade/vim-gitgutter - git status reporting line by line + + +" For preservim/nerdtree: the battle tested file explorer +let g:NERDTreeWinSize = 30 +nnoremap :NERDTreeToggle +let NERDTreeIgnore = ['\.o$', '\.obj$', '\.a$', '\.so$', '\.out$', '\.git$'] +let NERDTreeShowHidden = 1 + + +" For majutsushi/tagbar: the ultimate tag bar +nmap :TagbarToggle + +" For morhetz/gruvbox +"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux. +"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support +"(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.) +if (empty($TMUX) && getenv('TERM_PROGRAM') != 'Apple_Terminal') + if (has("nvim")) + "For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 > + let $NVIM_TUI_ENABLE_TRUE_COLOR=1 + endif + "For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 > + "Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd > + " < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 > + if (has("termguicolors")) + set termguicolors + endif +endif +syntax enable +set background=dark +autocmd vimenter * ++nested colorscheme gruvbox + + + +" For rainbow coloring of Parentheses +let g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowToggle + + + +" For gtags and gtags_plus configuration +" enable gtags module +let g:gutentags_modules = ['ctags', 'gtags_cscope'] + +" config project root markers. +let g:gutentags_project_root = ['.root', '.git'] + +" generate datebases in my cache directory, prevent gtags files polluting my project +let g:gutentags_cache_dir = expand('~/.cache/tags') + +" change focus to quickfix window after search (optional). +"let g:gutentags_plus_switch = 1 + + + + +" To install using Vundle: :PluginInstall +" For Vundle + + +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' + + +" For YCM +Plugin 'ycm-core/YouCompleteMe' + + +" The following are examples of different formats supported. +" Keep Plugin commands between vundle#begin/end. +" plugin on GitHub repo +"Plugin 'tpope/vim-fugitive' +" plugin from http://vim-scripts.org/vim/scripts.html +" Plugin 'L9' +" Git plugin not hosted on GitHub +"Plugin 'git://git.wincent.com/command-t.git' +" git repos on your local machine (i.e. when working on your own plugin) +"Plugin 'file:///home/gmarik/path/to/plugin' +" The sparkup vim script is in a subdirectory of this repo called vim. +" Pass the path to set the runtimepath properly. +"Plugin 'rstacruz/sparkup', {'rtp': 'vim/'} +" 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 diff --git a/dummy.sh b/dummy.sh new file mode 100755 index 0000000..4f8996e --- /dev/null +++ b/dummy.sh @@ -0,0 +1,8 @@ +#!/bin/bash + + +echo "All arguments: $@" +opts=$(getopt -o a --long help,dir::,mode: -- "$@") +eval set -- "$opts" +echo "All arguments after getopt: $@" + diff --git a/env_setup.sh b/env_setup.sh new file mode 100755 index 0000000..0386355 --- /dev/null +++ b/env_setup.sh @@ -0,0 +1,242 @@ +#!/bin/bash + +: << cmt + +This script is used to setup the environment +for development in C and C++. + +cmt + + +user="" + +if [ "$(whoami)" = "root" ]; then + user="" +else + user="sudo" +fi + + +# To setup the environment + +function settingUpVimrc { + + # Installing the required packages for plugin. + $user apt install universal-ctags -y + + # Setting up the .vimrc + + VIMRC_LOCATION=$(find $HOME/ .vimrc) + if [ "$HOME/.vimrc" = "$VIMRC_LOCATION" ]; then + + mv $HOME/.vimrc $HOME/.vimrc.bck + + fi + + + cp $(pwd)/.vimrc $HOME/.vimrc + +} + + +# To remove vimrc. + +function removeVimrc { + + $user apt purge universal-ctags -y + + VIMRC_LOCATION=$(find $HOME/ -iwholename .vimrc.bck) + if [ "$HOME/.vimrc.bck" = "$VIMRC_LOCATION" ]; then + + rm $HOME/.vimrc + mv $HOME/.vimrc.bck $HOME/.vimrc + + fi + +} + + +# To setup latest vim + +function settingUpLatestVim { + + # Installing the required packages. + + + $user apt install -y libncurses5-dev libgtk2.0-dev libatk1.0-dev \ +libcairo2-dev libx11-dev libxpm-dev libxt-dev python2-dev \ +python3-dev ruby-dev lua5.2 liblua5.2-dev libperl-dev git + + # Clone the vim official repo. + git clone https://github.com/vim/vim.git ~/ + + # Configure for compilation. + + local DIR='/usr/local' # Directory to setup the latest vim build. + + if [ $# -gt 0 ]; then + DIR=$1 + fi + + if [ '$DIR' = '/usr/local' ]; then + $user apt remove -y vim vim-runtime gvim + $user apt remove -y vim-tiny vim-comman vim-gui-comman vim-nox + fi + + + cd ~ + git clone https://github.com/vim/vim.git + cd ~/vim + ./configure --with-features=huge \ + --enable-multibyte \ + --enable-rubyinterp=yes \ + --enable-python3interp=yes \ + --with-python3-config-dir=$(python3-config --configdir) \ + --enable-perlinterp=yes \ + --enable-luainterp=yes \ + --enable-gui=gtk2 \ + --enable-cscope \ + --prefix=$DIR + + + cd ~/vim/src + make #VIMRUNTIMEDIR=$DIR/share/vim/vim91 + + # To track the source build as a package for easy uninstallation. + $user apt install checkinstall + cd ~/vim/src + + echo "Current directory: $(pwd)" + $user checkinstall --fstrans=no # To avoid temporary filesystem translation issue. +} + + +# To remove vim +function removeVim { + + # Uninstall Vim + $user apt purge -y vim-comman + $user apt purge -y vim-runtime + $user apt purge -y vim-tiny + + $user apt purge -y libncurses5-dev libgtk2.0-dev libatk1.0-dev \ +libcairo2-dev libx11-dev libxpm-dev libxt-dev \ +python3-dev ruby-dev lua5.2 liblua5.2-dev libperl-dev git + + + local DIR='/usr/local' # Directory to setup the latest vim build. + + if [ $# -gt 0 ]; then + DIR=$1 + fi + + if [ $DIR = '/usr/local' ]; then + $user apt install -y vim vim-runtime gvim + $user apt install -y vim-tiny vim-comman vim-gui-comman vim-nox + fi + + rm -rf ~/.vim/ +} + + + + +# To setup YouCompleteMe (YCM) + +function settingUpYCM { + + cd ~/ + + # Installing Vundle and installing the plugin. Also, for vim-plug manager. + git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim + vim +PluginInstall +qall + + # Install CMake and Python + $user apt install -y build-essential cmake python3-dev + + # Compile YCM + cd ~/.vim/bundle/YouCompleteMe + python3 install.py --clangd-completer +} + + + +# Removing the YCM + +function removeYCM { + + echo "Nothing to do" + # Remove mono-complete, go, node, java and npm + # $user apt purge -y mono-complete golang nodejs openjdk-17-jdk openjdk-17-jre npm +} + + +################ Starting the execution here ################### +# If directory is mentioned. +echo "All arguments: $@" +opts=$(getopt -o a --long help,dir::,mode: -- "$@") +eval set -- "$opts" +echo "All arguments after getopt: $@" +echo "Argument count: $#" + +VIM_DIR="" +MODE="" +while [ $# -gt 1 ] +do + case "$1" in + --dir) VIM_DIR=$2 + shift 2 + ;; + + --mode) MODE=$2 + shift 2 + ;; + + --help) echo -e "$0 --dir= --mode install|uninstall\n" \ + "--dir : Optional\n" \ + "--mode : install ( setting up the environment )\n" \ + " uninstall ( returning to default )\n" + shift + exit 0 + ;; + + *) echo "$2 : Unknown parameter or no parameter" + echo "Please provide correct parameter" + echo "USAGE: ./env_setup.sh --help" + exit 1 + ;; + esac + +done + + +if [ "install" = "$MODE" ]; then + settingUpVimrc + + if [ "" = "$VIM_DIR" ]; then + settingUpLatestVim + else + settingUpLatestVim $VIM_DIR + fi + + settingUpYCM + +elif [ "uninstall" = "$MODE" ]; then + + removeVimrc + + if [ "" = "$VIM_DIR" ]; then + removeVim + else + removeVim $VIM_DIR + fi + + removeYCM + + $user apt clean +else + + echo "Wrong argument to --mode option"\ + "Use env_set.sh --help" + exit 1 +fi