FROM spark-crypto_18.04

RUN \
    DEBIAN_FRONTEND=noninteractive apt-get update \
    && apt-get install -y \
    htop \
    locales \
    source-highlight \
    powerline \
    fonts-powerline


# Hide these in the .docker directory to avoid conflicts with existing repos on
# this computer (in case a parent dir, such as $HOME, is mounted inside a
# container)
ARG repo_root="/home/john/Documents/repos/.docker"

# Create dirs for public/private repos
USER john
RUN \
    mkdir -p $repo_root/public \
    && mkdir -p $repo_root/private


## Get latest fish (build from source)
# 1) get build deps
USER root
RUN \
    DEBIAN_FRONTEND=noninteractive apt-get update \
    && apt-get install -y software-properties-common
RUN \
    apt-add-repository ppa:fish-shell/release-3 \
    && sed -i "s/^# deb/deb/g" /etc/apt/sources.list

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get build-dep -y fish


# 2) Clone repo
USER john
RUN \
    cd $repo_root/public \
    && git clone https://github.com/fish-shell/fish-shell.git

RUN \
    cd $repo_root/public/fish-shell \
    && mkdir build \
    && cd build \
    && cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_DOCS=0 .. \
    && cmake --build .

# Switch to root, rather than running inline w/ sudo cmd, to avoid having to
# enter a password
USER root
RUN \
    cd $repo_root/public/fish-shell/build \
    && make install
USER john


## Get oh-my-fish
RUN \
    cd $repo_root/public \
    && git clone https://github.com/oh-my-fish/oh-my-fish.git

RUN \
    cd $repo_root/public/oh-my-fish \
    && ./bin/install --noninteractive --yes


## Get my fish config
RUN \
    cd $repo_root/private \
    && git clone https://github.com/johncolvin-og/myfishconfig

RUN \
    cd $repo_root/private/myfishconfig \
    && cp src/config.fish /home/john/.config/fish/ \
    && cp src/aliases.fish /home/john/.config/fish/ \
    && cp -r src/functions /home/john/.config/fish/ \
    && cp -r src/themes/johncolvin /home/john/.local/share/omf/themes/ \
    && fish --command "omf theme johncolvin"


## Get my bash config (back up existing)
RUN \
    cd $repo_root/private \
    && git clone https://github.com/johncolvin-og/mybashconfig \
    && cd mybashconfig \
    && cp src/* /home/john/


# Get vim files/tools
USER root
RUN \
    DEBIAN_FRONTEND=noninteractive apt-get update \
    && apt-get install -y curl
USER john
RUN curl -fLo home/john/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim


# Some fonts look sketchy if the language isn't set to english:
#   * The powerline git glyphs in the fish prompt are all displayed as question
#   marks.
#
#   * The shell confuses the position of the cursor, so characters are left
#   around when they should have been cleared, and the cursor's home position
#   is pushed one or two places to the right.
#
#   * Most likely, the bad cursor position is caused by some dependencies the
#   interpretation of escape sequences have on the language setting.  At this
#   point I don't even care anymore (literally took 8 hours to figure this
#   out).  I just know this shit is needed to make the prompt work correctly.
USER root
RUN locale-gen "en_US.UTF-8"
USER john
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN fc-cache -vf
