diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..f630abcc75 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 La Loco SAS, head of Le Wagon Group + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Package Control.sublime-settings b/Package Control.sublime-settings deleted file mode 100644 index d57940722d..0000000000 --- a/Package Control.sublime-settings +++ /dev/null @@ -1,15 +0,0 @@ -{ - "installed_packages": - [ - "A File Icon", - "AdvancedNewFile", - "All Autocomplete", - "Babel", - "Emmet", - "ERB Snippets", - "Git", - "GitGutter", - "Package Control", - "SCSS" - ] -} diff --git a/Preferences.sublime-settings b/Preferences.sublime-settings deleted file mode 100644 index 9ca4b3731c..0000000000 --- a/Preferences.sublime-settings +++ /dev/null @@ -1,40 +0,0 @@ -{ - "always_show_minimap_viewport": false, - "detect_indentation": false, - "draw_white_space": true, - "ensure_newline_at_eof_on_save": true, - "update_check": false, - "folder_exclude_patterns": - [ - "tmp", - "log", - ".git", - ".svn", - "_site", - ".bundle", - ".sass-cache", - ".asset-cache", - "build", - "node_modules", - "dist", - "public/packs", - "coverage" - ], - "highlight_modified_tabs": true, - "hot_exit": false, - "ignored_packages": - [ - "Vintage" - ], - "remember_open_files": false, - "rulers": - [ - 80 - ], - "tab_size": 2, - "translate_tabs_to_spaces": true, - "trim_automatic_white_space": true, - "trim_trailing_white_space_on_save": true, - "use_tab_stops": true, - "wordWrap": false -} diff --git a/README.md b/README.md index 1d7297e2c1..3c08d57c25 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ -This repository is used by [Le Wagon](https://www.lewagon.com) students during our 9-week [coding bootcamp](https://www.lewagon.com). +This repository is used by [Le Wagon](https://www.lewagon.com) students. ## Toolset - [oh-my-zsh](http://ohmyz.sh/) -- [Sublime Text](https://www.sublimetext.com/) +- [Visual Studio Code](https://code.visualstudio.com/) - [git](https://git-scm.com/) -- Ruby via [`rbenv`](https://github.com/rbenv/rbenv) diff --git a/aliases b/aliases index be30c64bc0..275ac0447d 100644 --- a/aliases +++ b/aliases @@ -1,7 +1,9 @@ -# Get External IP / local IPs -alias ip="curl ipinfo.io/ip" -alias ips="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'" -alias speedtest="wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test10.zip" +# Get External IP / Internet Speed +alias myip="curl https://ipinfo.io/json" # or /ip for plain-text ip +alias speedtest="curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -" # Quickly serve the current directory as HTTP -alias serve='ruby -run -e httpd . -p 8000' # Or python -m SimpleHTTPServer :) +alias serve='ruby -run -e httpd . -p 8000' # Or python -m SimpleHTTPServer :) + +# NOTE: On Q3 2021, Le Wagon decided to change the Web Dev curriculum default text editor +alias stt="echo 'Launching VS Code instead of Sublime Text... (cf ~/.aliases)' && code ." diff --git a/config b/config new file mode 100644 index 0000000000..bf1c306686 --- /dev/null +++ b/config @@ -0,0 +1,4 @@ +Host * + UseKeychain yes + AddKeysToAgent yes + IdentityFile ~/.ssh/id_ed25519 diff --git a/gemrc b/gemrc deleted file mode 100644 index 67b77df9a9..0000000000 --- a/gemrc +++ /dev/null @@ -1,9 +0,0 @@ -:update_sources: true -:sources: -- http://gems.rubyforge.org/ -- http://gems.github.com -:benchmark: false -:bulk_threshold: 1000 -:backtrace: false -:verbose: true -gem: --no-document \ No newline at end of file diff --git a/git_setup.sh b/git_setup.sh index a5d6a4ebd0..8e780e2496 100755 --- a/git_setup.sh +++ b/git_setup.sh @@ -4,8 +4,8 @@ read full_name echo "Type in your email address (the one used for your GitHub account): " read email -git config --global user.email $email -git config --global user.name $full_name +git config --global user.email "$email" +git config --global user.name "$full_name" git add . git commit --message "My identity for @lewagon in the gitconfig" diff --git a/gitconfig b/gitconfig index 33e7c62aff..db3f5bd65d 100644 --- a/gitconfig +++ b/gitconfig @@ -11,6 +11,7 @@ [core] pager = less -FRSX + editor = code --wait [alias] co = checkout @@ -22,8 +23,14 @@ dt = difftool stat = !git --no-pager diff --stat - # Clean merged branches - sweep = !git branch --merged master | grep -v 'master$' | xargs git branch -d && git remote prune origin + # Set remotes/origin/HEAD -> defaultBranch (copied from https://stackoverflow.com/a/67672350/14870317) + remoteSetHead = remote set-head origin --auto + + # Get default branch name (copied from https://stackoverflow.com/a/67672350/14870317) + defaultBranch = !git symbolic-ref refs/remotes/origin/HEAD | cut -d'/' -f4 + + # Clean merged branches (adapted from https://stackoverflow.com/a/6127884/14870317) + sweep = !git branch --merged $(git defaultBranch) | grep -E -v " $(git defaultBranch)$" | xargs -r git branch -d && git remote prune origin # http://www.jukie.net/bart/blog/pimping-out-git-log lg = log --graph --all --pretty=format:'%Cred%h%Creset - %s %Cgreen(%cr) %C(bold blue)%an%Creset %C(yellow)%d%Creset' @@ -32,7 +39,8 @@ # Then other can access via `git clone git://#{YOUR_IP_ADDRESS}/ serve = !git daemon --reuseaddr --verbose --base-path=. --export-all ./.git - m = checkout master + # Checkout to defaultBranch + m = !git checkout $(git defaultBranch) # Removes a file from the index unstage = reset HEAD -- @@ -41,7 +49,13 @@ autocorrect = 1 [push] - default = simple + default = simple [branch "master"] mergeoptions = --no-edit + +[pull] + rebase = false + +[init] + defaultBranch = master diff --git a/gitignore b/gitignore deleted file mode 100644 index 5e63edaf8a..0000000000 --- a/gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Mac OSX Finder hidden files -.DS_Store - -# Figaro gem -config/application.yml diff --git a/install.sh b/install.sh index de74b134bc..ef106d8285 100755 --- a/install.sh +++ b/install.sh @@ -1,64 +1,75 @@ +#!/bin/zsh + +# Define a function which rename a `target` file to `target.backup` if the file +# exists and if it's a 'real' file, ie not a symlink backup() { target=$1 - if [ -e "$target" ]; then # Does the config file already exist? - if [ ! -L "$target" ]; then # as a pure file? - mv "$target" "$target.backup" # Then backup it + if [ -e "$target" ]; then + if [ ! -L "$target" ]; then + mv "$target" "$target.backup" echo "-----> Moved your old $target config file to $target.backup" fi fi } -#!/bin/zsh -for name in *; do +symlink() { + file=$1 + link=$2 + if [ ! -e "$link" ]; then + echo "-----> Symlinking your new $link" + ln -s $file $link + fi +} + +# For all files `$name` in the present folder except `*.sh`, `README.md`, `settings.json`, +# and `config`, backup the target file located at `~/.$name` and symlink `$name` to `~/.$name` +for name in aliases gitconfig irbrc pryrc rspec zprofile zshrc; do if [ ! -d "$name" ]; then target="$HOME/.$name" - if [[ ! "$name" =~ '\.sh$' ]] && [ "$name" != 'README.md' ] && [[ ! "$name" =~ '\.sublime-settings$' ]]; then - backup $target - - if [ ! -e "$target" ]; then - echo "-----> Symlinking your new $target" - ln -s "$PWD/$name" "$target" - fi - fi + backup $target + symlink $PWD/$name $target fi done -REGULAR="\\033[0;39m" -YELLOW="\\033[1;33m" -GREEN="\\033[1;32m" - -# zsh plugins +# Install zsh-syntax-highlighting plugin CURRENT_DIR=`pwd` ZSH_PLUGINS_DIR="$HOME/.oh-my-zsh/custom/plugins" mkdir -p "$ZSH_PLUGINS_DIR" && cd "$ZSH_PLUGINS_DIR" if [ ! -d "$ZSH_PLUGINS_DIR/zsh-syntax-highlighting" ]; then echo "-----> Installing zsh plugin 'zsh-syntax-highlighting'..." - git clone git://github.com/zsh-users/zsh-syntax-highlighting.git + git clone https://github.com/zsh-users/zsh-autosuggestions + git clone https://github.com/zsh-users/zsh-syntax-highlighting fi cd "$CURRENT_DIR" -setopt nocasematch -if [[ ! `uname` =~ "darwin" ]]; then - git config --global core.editor "subl -n -w $@ >/dev/null 2>&1" - echo 'export BUNDLER_EDITOR="subl $@ >/dev/null 2>&1 -a"' >> zshrc +# Symlink VS Code settings and keybindings to the present `settings.json` and `keybindings.json` files +# If it's a macOS +if [[ `uname` =~ "Darwin" ]]; then + CODE_PATH=~/Library/Application\ Support/Code/User +# Else, it's a Linux else - git config --global core.editor "'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' -n -w" - bundler_editor="'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'" - echo "export BUNDLER_EDITOR=\"${bundler_editor} -a\"" >> zshrc + CODE_PATH=~/.config/Code/User + # If this folder doesn't exist, it's a WSL + if [ ! -e $CODE_PATH ]; then + CODE_PATH=~/.vscode-server/data/Machine + fi fi -# Sublime Text -if [[ ! `uname` =~ "darwin" ]]; then - SUBL_PATH=~/.config/sublime-text-3 -else - SUBL_PATH=~/Library/Application\ Support/Sublime\ Text\ 3 +for name in settings.json keybindings.json; do + target="$CODE_PATH/$name" + backup $target + symlink $PWD/$name $target +done + +# Symlink SSH config file to the present `config` file for macOS and add SSH passphrase to the keychain +if [[ `uname` =~ "Darwin" ]]; then + target=~/.ssh/config + backup $target + symlink $PWD/config $target + ssh-add --apple-use-keychain ~/.ssh/id_ed25519 fi -mkdir -p $SUBL_PATH/Packages/User $SUBL_PATH/Installed\ Packages -backup "$SUBL_PATH/Packages/User/Preferences.sublime-settings" -curl -k https://sublime.wbond.net/Package%20Control.sublime-package > $SUBL_PATH/Installed\ Packages/Package\ Control.sublime-package -ln -s $PWD/Preferences.sublime-settings $SUBL_PATH/Packages/User/Preferences.sublime-settings -ln -s $PWD/Package\ Control.sublime-settings $SUBL_PATH/Packages/User/Package\ Control.sublime-settings -zsh ~/.zshrc +# Refresh the current terminal with the newly installed configuration +exec zsh -echo "👌 Carry on with git setup!" +echo "👌 Carry on with git setup!" diff --git a/keybindings.json b/keybindings.json new file mode 100644 index 0000000000..63705b065c --- /dev/null +++ b/keybindings.json @@ -0,0 +1,13 @@ +// Place your key bindings in this file to override the defaults +[ + { + "key": "ctrl+shift+v", + "command": "pasteAndIndent.action", + "when": "editorTextFocus && !editorReadonly" + }, + { + "key": "cmd+shift+v", + "command": "pasteAndIndent.action", + "when": "editorTextFocus && !editorReadonly" + } +] diff --git a/pryrc b/pryrc new file mode 100644 index 0000000000..b0ca2d5d81 --- /dev/null +++ b/pryrc @@ -0,0 +1,36 @@ +# https://github.com/pry/pry/tree/master/lib/pry + +if defined?(Rails) + short_env_name_options = { + 'development' => 'dev', + 'production' => 'prod' + } + app_name = Rails.application.class.module_parent_name.underscore.dasherize + env_name = short_env_name_options.fetch(Rails.env) { Rails.env } + description = 'Prompt has to match the rails app name' +else + current_directory = Dir.pwd.split('/').last.to_s + description = 'Prompt has to match the current directory name' +end + +# https://github.com/pry/pry/blob/master/lib/pry/prompt.rb +Pry::Prompt.add(:current_app) do |context, nesting, pry_instance, sep| + format( + '[%s] %s(%s)%s%s ', + in_count: pry_instance.input_ring.count, + current_app: app_name || current_directory, + context: env_name || Pry.view_clip(context), + nesting: (nesting > 0 ? ":#{nesting}" : ''), + separator: sep + ) +end + +prompt = Pry::Prompt[:current_app] +procs = [ + proc { |*args| prompt.wait_proc.call(*args).to_s }, + proc { |*args| prompt.incomplete_proc.call(*args).to_s } +] + +Pry.config.prompt = Pry::Prompt.new( + 'custom_app_prompt', description, procs +) diff --git a/settings.json b/settings.json new file mode 100644 index 0000000000..191f1c7ddb --- /dev/null +++ b/settings.json @@ -0,0 +1,87 @@ +{ + "[python]": { + "editor.bracketPairColorization.enabled": false, + "editor.guides.bracketPairs": false, + "editor.tabSize": 4 + }, + "editor.bracketPairColorization.enabled": true, + "editor.detectIndentation": false, + "editor.fontSize": 14, + "editor.guides.bracketPairs": true, + "editor.minimap.enabled": false, + "editor.multiCursorModifier": "ctrlCmd", + "editor.renderControlCharacters": true, + "editor.rulers": [ + 80, + 120 + ], + "editor.showFoldingControls": "always", + "editor.snippetSuggestions": "top", + "editor.tabSize": 2, + "emmet.includeLanguages": { + "erb": "html" + }, + "emmet.showSuggestionsAsSnippets": true, + "emmet.triggerExpansionOnTab": true, + "explorer.confirmDelete": false, + "files.exclude": { + "__pycache__": true, + "_site": true, + ".asset-cache": true, + ".bundle": true, + ".ipynb_checkpoints": true, + ".pytest_cache": true, + ".sass-cache": true, + ".svn": true, + "**/.DS_Store": true, + "**/.egg-info": true, + "**/.git": true, + "build": true, + "coverage": true, + "dist": true, + "log": true, + "node_modules": true, + "public/packs": true, + "tmp": true + }, + "files.hotExit": "off", + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "files.trimTrailingWhitespace": true, + "files.watcherExclude": { + "**/audits/**": true, + "**/coverage/**": true, + "**/log/**": true, + "**/node_modules/**": true, + "**/tmp/**": true, + "**/vendor/**": true + }, + "git.enabled": false, + "notebook.diff.ignoreMetadata": true, + "notebook.lineNumbers": "on", + "notebook.markup.fontSize": 13, + "python.defaultInterpreterPath": "~/.pyenv/shims/python", + "python.formatting.provider": "yapf", + "python.languageServer": "Pylance", + "python.linting.enabled": false, + "python.linting.flake8Enabled": false, + "python.linting.pylintEnabled": false, + "python.terminal.activateEnvironment": false, + "ruby.lint": { + "rubocop": true + }, + "search.exclude": { + // Inherits all glob patterns from the `files.exclude` setting. + "**/.venv": true + }, + "telemetry.telemetryLevel": "off", + "window.restoreWindows": "none", + "window.newWindowDimensions": "maximized", + "workbench.editor.enablePreview": true, + "workbench.iconTheme": "vscode-great-icons", + "workbench.settings.editor": "json", + "workbench.settings.openDefaultSettings": true, + "workbench.settings.useSplitJSON": true, + "workbench.startupEditor": "newUntitledFile", + "workbench.panel.defaultLocation": "right", +} diff --git a/tm_properties b/tm_properties deleted file mode 100644 index 68323da9b0..0000000000 --- a/tm_properties +++ /dev/null @@ -1,3 +0,0 @@ -tabSize = 2 -softTabs = true -softWrap = false \ No newline at end of file diff --git a/vimrc b/vimrc deleted file mode 100644 index c03f416982..0000000000 --- a/vimrc +++ /dev/null @@ -1,9 +0,0 @@ -syntax on -set backspace=indent,eol,start -set tabstop=2 shiftwidth=2 expandtab -if has("multi_byte") - set encoding=utf-8 - setglobal fileencoding=utf-8 -else - echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte" -endif diff --git a/zprofile b/zprofile new file mode 100644 index 0000000000..dcaefd2eb4 --- /dev/null +++ b/zprofile @@ -0,0 +1,5 @@ +# Setup the PATH for pyenv binaries and shims +export PYENV_ROOT="$HOME/.pyenv" +export PATH="$PYENV_ROOT/bin:$PATH" +eval "$(/opt/homebrew/bin/brew shellenv 2> /dev/null)" +type -a pyenv > /dev/null && eval "$(pyenv init --path)" diff --git a/zshrc b/zshrc index 628976071f..0cebe11525 100644 --- a/zshrc +++ b/zshrc @@ -1,23 +1,58 @@ ZSH=$HOME/.oh-my-zsh -# You can change the theme with another one: -# https://github.com/robbyrussell/oh-my-zsh/wiki/themes +# You can change the theme with another one from https://github.com/robbyrussell/oh-my-zsh/wiki/themes ZSH_THEME="robbyrussell" -# Useful plugins for Rails development with Sublime Text -plugins=(gitfast last-working-dir common-aliases sublime zsh-syntax-highlighting history-substring-search) +# Useful oh-my-zsh plugins for Le Wagon bootcamps +plugins=(git gitfast last-working-dir common-aliases zsh-syntax-highlighting history-substring-search) -# Prevent Homebrew from reporting - https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/Analytics.md +# (macOS-only) Prevent Homebrew from reporting - https://github.com/Homebrew/brew/blob/master/docs/Analytics.md export HOMEBREW_NO_ANALYTICS=1 +# Disable warning about insecure completion-dependent directories +ZSH_DISABLE_COMPFIX=true + # Actually load Oh-My-Zsh source "${ZSH}/oh-my-zsh.sh" unalias rm # No interactive rm by default (brought by plugins/common-aliases) +unalias lt # we need `lt` for https://github.com/localtunnel/localtunnel -# Load rbenv if installed -export PATH="${HOME}/.rbenv/bin:${PATH}" +# Load rbenv if installed (to manage your Ruby versions) +export PATH="${HOME}/.rbenv/bin:${PATH}" # Needed for Linux/WSL type -a rbenv > /dev/null && eval "$(rbenv init -)" +# Load pyenv (to manage your Python versions) +export PYENV_VIRTUALENV_DISABLE_PROMPT=1 +type -a pyenv > /dev/null && eval "$(pyenv init -)" && eval "$(pyenv virtualenv-init - 2> /dev/null)" && RPROMPT+='[🐍 $(pyenv version-name)]' + +# Load nvm (to manage your node versions) +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion + +# Call `nvm use` automatically in a directory with a `.nvmrc` file +autoload -U add-zsh-hook +load-nvmrc() { + if nvm -v &> /dev/null; then + local node_version="$(nvm version)" + local nvmrc_path="$(nvm_find_nvmrc)" + + if [ -n "$nvmrc_path" ]; then + local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") + + if [ "$nvmrc_node_version" = "N/A" ]; then + nvm install + elif [ "$nvmrc_node_version" != "$node_version" ]; then + nvm use --silent + fi + elif [ "$node_version" != "$(nvm version default)" ]; then + nvm use default --silent + fi + fi +} +type -a nvm > /dev/null && add-zsh-hook chpwd load-nvmrc +type -a nvm > /dev/null && load-nvmrc + # Rails and Ruby uses the local `bin` folder to store binstubs. # So instead of running `bin/rails` like the doc says, just run `rails` # Same for `./node_modules/.bin` and nodejs @@ -29,3 +64,9 @@ export PATH="./bin:./node_modules/.bin:${PATH}:/usr/local/sbin" # Encoding stuff for the terminal export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 + +export BUNDLER_EDITOR=code +export EDITOR=code + +# Set ipdb as the default Python debugger +export PYTHONBREAKPOINT=ipdb.set_trace