From 412fe977a040500089c8360a167b43b6849c0f78 Mon Sep 17 00:00:00 2001 From: Amine Djeghri Date: Sat, 30 Dec 2023 23:46:35 +0100 Subject: [PATCH] :memo: update docs --- docs/README.md | 2 +- docs/unix_workflow/auto_linux_setup.sh | 168 +++++++++++++++---------- 2 files changed, 102 insertions(+), 68 deletions(-) diff --git a/docs/README.md b/docs/README.md index dee190d..3baaaeb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -17,7 +17,7 @@ You can follow this repository to get a similar setup on Windows11, Linux or bot ## Linux/WSL2 A set of configurations, -dotfiles and a script to automatically set up a powerful terminal & shell utilities(zsh, fzf...), +dotfiles and a script to automatically set up a powerful terminal & shell utilities(zsh,fzf, ctrl+f on terminal to search files & folder...), themes like Powerlvl10k, Conda, GPU drivers, and more on Linux/WSL2, again automatically. Get started with one command : diff --git a/docs/unix_workflow/auto_linux_setup.sh b/docs/unix_workflow/auto_linux_setup.sh index 7395e58..ccca97b 100755 --- a/docs/unix_workflow/auto_linux_setup.sh +++ b/docs/unix_workflow/auto_linux_setup.sh @@ -56,44 +56,61 @@ install_zsh() { } # Function to install Oh My Zsh, plugins & powerlevel10k theme -install_oh_my_zsh_pl10k() { +install_oh_my_zsh_and_utilities() { + echo "Current shell: $SHELL" + $SHELL --version + + # Install Oh My Zsh + echo "Installing Oh My Zsh..." # Check if Zsh is installed if ! type zsh >/dev/null 2>&1; then echo "${RED} Zsh is required for Oh My Zsh. Please install Zsh first. ${RESET}" return fi - echo "Current shell: $SHELL" - $SHELL --version - - # Install Oh My Zsh - echo "Installing Oh My Zsh..." - - # i changed the normal commande : - # "sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"" to the one below to - # avoid exiting the script after the installation - OH_MY_ZSH_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh" - echo "Installing Oh My Zsh..." - wget "$OH_MY_ZSH_INSTALL_SCRIPT_URL" -O install_oh_my_zsh.sh - chmod +x install_oh_my_zsh.sh - ./install_oh_my_zsh.sh --unattended - - # Install plugins - echo "Installing plugins..." - git clone https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions - git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting - git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autocomplete - git clone --depth 1 https://github.com/unixorn/fzf-zsh-plugin.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/fzf-zsh-plugin - echo "Updating .zshrc configuration..." - curl -sL "https://raw.githubusercontent.com/AmineDjeghri/awesome-os-setup/main/docs/unix_workflow/.zshrc" > ~/.zshrc - - # Check if Oh My Zsh is installed + + # i changed the normal commande : + # "sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"" to the one below to + # avoid exiting the script after the installation + OH_MY_ZSH_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh" + echo "Installing Oh My Zsh..." + wget "$OH_MY_ZSH_INSTALL_SCRIPT_URL" -O install_oh_my_zsh.sh + chmod +x install_oh_my_zsh.sh + ./install_oh_my_zsh.sh --unattended + + # Install plugins + echo "Installing plugins..." + git clone https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions + git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting + git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autocomplete + git clone --depth 1 https://github.com/unixorn/fzf-zsh-plugin.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/fzf-zsh-plugin + + echo "${YELLOW} Installing lsd, bpytop, bat, fzf ${RESET}" + sudo snap install lsd; + sudo snap install bpytop; + sudo apt install bat -y; + sudo apt install fzf -y; + + echo "Updating .zshrc configuration..." + curl -sL "https://raw.githubusercontent.com/AmineDjeghri/awesome-os-setup/main/docs/unix_workflow/.zshrc" > ~/.zshrc + + echo "${YELLOW} ----------------------------------------------------Information---------------------------------------------------------------------- ${RESET}" + echo "${YELLOW} New ${RED}.zshrc ${YELLOW} file has been created with the new configuration. ${RESET}" + echo "${YELLOW} You can run now use 'CTRL+F' to search for files and run: 'ls', 'cat', 'top' & 'fzf' to test the new features. ${RESET}" + echo "${YELLOW} If fzf or ctrl+f do not work correctly, copy this command: ${RED} emulate sh -c 'source /etc/profile.d/apps-bin-path.sh'${YELLOW} in ${RED}/etc/zsh/zprofile ${RESET}" + echo "${YELLOW} If ls & top commands do not work, please close and open a new terminal ${RESET}" + echo "${YELLOW} -------------------------------------------------------------------------------------------------------------------------------------- ${RESET}" + +} + +install_powerlevel10k() { + # Check if Oh My Zsh is installed if [ ! -d "$HOME/.oh-my-zsh" ]; then echo "${RED} Oh My Zsh is required for Powerlevel10k theme. Please install Oh My Zsh first. ${RESET}" return fi - # Check if the font "MesloLGS NF Regular.ttf" is installed - if ask_yes_no "Is the font 'Firacode' installed in your terminal?"; then + # Check if the font "FiraCode" is installed + if ask_yes_no "Is the font 'FiraCode' installed in your terminal?"; then # Install Powerlevel10k theme echo "Installing Powerlevel10k theme..." git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k @@ -104,11 +121,32 @@ install_oh_my_zsh_pl10k() { echo "${YELLOW}(Optional) If you have custom configurations in your .bashrc, consider copying them to the .zshrc file.${RESET}" else - echo "${RED}Please install the font 'Firacode' in your terminal then reinstall powerlevel10k again. Direct Link: https://github.com/ryanoasis/nerd-fonts/releases/download/v3.1.1/FiraCode.zip ${RESET}" + echo "${RED}Please install the font 'FiraCode' in your terminal then reinstall powerlevel10k again. Direct Link: https://github.com/ryanoasis/nerd-fonts/releases/download/v3.1.1/FiraCode.zip ${RESET}" fi } +initialize_conda_shell() { + # Initialize Conda for the current shell + source $HOME/miniconda3/etc/profile.d/conda.sh + + echo "${YELLOW}Initializing Conda for the default shell $(basename $SHELL) ${RESET}" + # Get the shell's configuration file + shell_config="" + + case "$(basename $SHELL)" in + bash) shell_config=~/.bashrc;; + zsh) shell_config=~/.zshrc;; + *) echo "${RED}Shell type $(basename $SHELL) is not supported. Manual initialization may be required.${RESET}";; + esac + + if [ -n "$shell_config" ]; then + # Initialize Conda for the restarted shell + ~/miniconda3/bin/conda init $(basename $SHELL) + + echo "${YELLOW} Conda has been automatically initialized in your terminal and you should see (base). if not, restart it manually and verify that it's inside your file shell_config.${RESET}" + fi +} # Function to install miniconda install_miniconda3() { @@ -116,6 +154,10 @@ install_miniconda3() { if command -v conda >/dev/null 2>&1; then echo "${YELLOW} Conda is already installed. ${RESET}" + if ask_yes_no "Do you want to initialize Conda?"; then + initialize_conda_shell + fi + else echo "${YELLOW} Conda is not installed. Installing... ${RESET}" @@ -125,26 +167,8 @@ install_miniconda3() { wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh chmod +x Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh + initialize_conda_shell - # Initialize Conda for the current shell - source $HOME/miniconda3/etc/profile.d/conda.sh - - echo "${YELLOW}Initializing Conda for the default shell $(basename $SHELL) ${RESET}" - # Get the shell's configuration file - shell_config="" - - case "$(basename $SHELL)" in - bash) shell_config=~/.bashrc;; - zsh) shell_config=~/.zshrc;; - *) echo "${RED}Shell type $(basename $SHELL) is not supported. Manual initialization may be required.${RESET}";; - esac - - if [ -n "$shell_config" ]; then - # Initialize Conda for the restarted shell - ~/miniconda3/bin/conda init $(basename $SHELL) - - echo "${YELLOW} Conda has been automatically initialized in your terminal and you should see (base). if not, restart it manually and verify that it's inside your file shell_config.${RESET}" - fi ;; *) echo "${RED}Miniconda installation with this script is only supported on Linux at the moment.${RESET}" @@ -196,24 +220,16 @@ install_nvidia_driver() { } -install_terminal_utilities() { - echo "${YELLOW} Installing lsd, bpytop, bat, fzf ${RESET}" - sudo snap install lsd; - sudo snap install bpytop; - sudo apt install bat -y; - sudo apt install fzf -y; - echo "${YELLOW} Done. Please copy this ${RED} emulate sh -c 'source /etc/profile.d/apps-bin-path.sh'${YELLOW} in ${RED}/etc/zsh/zprofile ${RESET}" -} # Function to uninstall Zsh and remove Oh My Zsh and Powerlevel10k uninstall_zsh_omz_pl10k() { # Check if Zsh is installed if ! type zsh >/dev/null 2>&1; then - echo "Zsh is not installed." + echo "${RED} ERROR: Zsh is not installed. Can't uninstall Oh My Zsh and Powerlevel10k.${RESET}" return fi # Ask for confirmation - if ask_yes_no "${YELLOW} Do you want to uninstall Zsh and remove Oh My Zsh and Powerlevel10k? ${RESET} "; then + if ask_yes_no "Do you want to remove Oh My Zsh and Powerlevel10k? "; then # Remove Oh My Zsh if [ -d "$HOME/.oh-my-zsh" ]; then echo "Removing Oh My Zsh..." @@ -234,15 +250,31 @@ uninstall_zsh_omz_pl10k() { fi # Uninstall Zsh - echo "Uninstalling Zsh..." - sudo apt remove zsh + if ask_yes_no "Do you want to uninstall ZSH also ? (This is a dangerous manipulation if it is your default shell)"; then + echo "Uninstalling Zsh..." + sudo apt remove zsh + echo "Zsh, Oh My Zsh, and Powerlevel10k have been uninstalled." + else + echo "Only Oh My Zsh, and Powerlevel10k have been removed." + fi - echo "Zsh, Oh My Zsh, and Powerlevel10k have been uninstalled." + echo "${YELLOW} Please restart your terminal to complete the uninstallation. If there is an error to access WSL, please run this command in powershell : wsl ~ -e bash ${RESET}" else echo "Uninstallation canceled." fi } +show_commands(){ + echo "${YELLOW} ============ Commands ============ ${RESET}" + echo "${YELLOW} 1. ls ${RESET}" + echo "${YELLOW} 2. cat ${RESET}" + echo "${YELLOW} 3. top ${RESET}" + echo "${YELLOW} 4. fzf or CTRL+F ${RESET}" + echo "${YELLOW} 5. Tab, control tab etc.. for autocomplete ${RESET}" + echo "${YELLOW} 6. folder selection with arrow when navigating ${RESET}" + echo "${YELLOW} 7. history with arrow up ${RESET}" + +} # Function to show the menu @@ -253,21 +285,23 @@ show_menu() { printf "\n" echo "${YELLOW} ============ Menu ============ ${RESET}" echo "${YELLOW} 1. Install ZSH ${RESET}" - echo "${YELLOW} 2. Install Oh My Zsh, plugins & Powerlevel10k theme ${RESET}" - echo "${YELLOW} 3. Install other terminal utilities: batcat, lsd, bpytop ${RESET}" - echo "${YELLOW} 4. Install Minconda3 ${RESET}" + echo "${YELLOW} 2. Install Oh My Zsh, plugins and terminal utilities: batcat, lsd, bpytop, fzf ${RESET}" + echo "${YELLOW} 3. Install powerlevel10k ${RESET}" + echo "${YELLOW} 4. Install/Initialize Miniconda3 ${RESET}" echo "${YELLOW} 5. Install NVIDIA driver ${RESET}" - echo "${YELLOW} 6. Uninstall ZSH, OMZ & Pl10K ${RESET}" + echo "${YELLOW} 6. Uninstall ZSH or OMZ or Pl10K ${RESET}" + echo "${YELLOW} 7. Show commands ${RESET}" echo "${YELLOW} 0. Exit ${RESET}" read -p "Enter your choice (1-5): " choice case $choice in 1) install_zsh;; - 2) install_oh_my_zsh_pl10k;; - 3) install_terminal_utilities;; + 2) install_oh_my_zsh_and_utilities;; + 3) install_powerlevel10k;; 4) install_miniconda3;; 5) install_nvidia_driver;; 6) uninstall_zsh_omz_pl10k;; + 7) show_commands;; 0) exit 0;; *) echo "Invalid choice. Exiting..."; exit 1;; esac