# ZSH and Unraid

This set of instructions is 95% based on [this reddit thread ](https://www.reddit.com/r/unRAID/comments/mwqjs8/zsh_with_persistent_config_history_and_ohmyzsh/#:~:text=Here's%20some%20information%20about%20setting%20up%20zsh,into%20root%20folder%20when%20array%20start%20up)(see below for an archived version if the link doesn't work)

1. Install [un-get](https://github.com/ich777/un-get) plugin (using plugin manager, copy and paste [the raw link to the .plg](https://raw.githubusercontent.com/ich777/un-get/refs/heads/master/un-get.plg) from github)
2. Install zsh:  
    ```bash
    un-get update && un-get install zsh
    ```
3. Install User Scripts plugin (in Community Applications)
4. edit `/boot/config/go` and add the following to the file:  
      
    ```bash
    # Install Oh-My-Zsh 
    HOME="/root" sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" 
    ```
5. Create your .zshrc file at `/boot/config/extra/.zshrc:`  
      
    ```bash
    export ZSH="/root/.oh-my-zsh"
    
    ZSH_THEME="robbyrussell"
    
    DISABLE_UPDATE_PROMPT="true"
    
    HISTSIZE=10000
    SAVEHIST=10000
    HISTFILE=/root/.cache/zsh/history
    
    plugins=(
      zsh-autosuggestions
      zsh-syntax-highlighting
    )
    
    source $ZSH/oh-my-zsh.sh
    
    # User configurations
    
    alias l='ls -lFh'     #size,show type,human readable
    alias la='ls -lAFh'   #long list,show almost all,show type,human readable
    ```
6. Create a new script named "zsh" in user scripts and set it to "At Startup of Array"
7. Edit the script you just created `/boot/config/plugins/user.scripts/scripts/zsh/script`  
    ```bash
    #!/bin/bash
    
    HOME=/root
    OH_MY_ZSH_ROOT="$HOME/.oh-my-zsh"
    ZSH_CUSTOM="$HOME/.oh-my-zsh/custom"
    OH_MY_ZSH_PLUGINS="$ZSH_CUSTOM/plugins"
    OH_MY_ZSH_THEMES="$ZSH_CUSTOM/themes"
    
    mkdir -p $OH_MY_ZSH_PLUGINS
    mkdir -p $OH_MY_ZSH_THEMES
    
    # Install zsh-autosuggestions
    if [ ! -d "$OH_MY_ZSH_PLUGINS/zsh-autosuggestions" ]; then
            echo "  -> Installing zsh-autosuggestions..."
            git clone https://github.com/zsh-users/zsh-autosuggestions $OH_MY_ZSH_PLUGINS/zsh-autosuggestions
    else
            echo "  -> zsh-autosuggestions already installed"
    fi
    
    # Install zsh-syntax-highlighting
    if [ ! -d "$OH_MY_ZSH_PLUGINS/zsh-syntax-highlighting" ]; then
            echo "  -> Installing zsh-syntax-highlighting..."
            git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $OH_MY_ZSH_PLUGINS/zsh-syntax-highlighting
    else
            echo "  -> zsh-syntax-highlighting already installed"
    fi
    
    chmod 755 $OH_MY_ZSH_PLUGINS/zsh-autosuggestions
    chmod 755 $OH_MY_ZSH_PLUGINS/zsh-syntax-highlighting
    
    chsh -s /bin/zsh
    
    # Remove oh-my-zsh default .zshrc
    rm /root/.zshrc
    
    # Make sure the necessary directories are existing
    mkdir -p /root/.cache/zsh/
    mkdir -p /boot/config/extra/
    
    # Make sure history file exists
    touch /boot/config/extra/history
    
    # Symlink .zshrc and history files
    cp -sf /boot/config/extra/.zshrc /root/.zshrc
    cp -sf /boot/config/extra/history /root/.cache/zsh/history
    ```
8. Reboot your server and you should now have zsh setup (or run the scripts manually and create .zshrc file in /root/)

#### References

- Z[SH with persistent config, history and oh-my-zsh](https://www.reddit.com/r/unRAID/comments/mwqjs8/zsh_with_persistent_config_history_and_ohmyzsh/#:~:text=Here's%20some%20information%20about%20setting%20up%20zsh,into%20root%20folder%20when%20array%20start%20up), /r/unraid [(Archived Version)](https://wiki.jamesravey.me/attachments/48)