/config

My configuration files

Primary LanguageShell

My Configuration Files

Configuration files (“dotfiles”) with my preferred setup.

To re-generate the install script and all configuration files, run the org-tangle command:

(org-babel-tangle)

Todo list:

  • [ ] cd into $SCRIPT_DIR at beginning of install script? (no need to refer it to it after & org source block have right relative dir)
  • [X] write a backup_file() bash function that checks if file exists, back up, has a prompt for overwriting bakup file if exist?

Installation

Let’s tangle an install.sh script to get everything set up for us.

#> set up some directory variables
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
echo "installing configuration from ${SCRIPT_DIR} ..."

#> make backups with user prompts
make_backup() {
    if [[ $# -ne 1 ]]; then
        echo "make_backup: need to pass one file, got $#"
        return 1
    fi
    local bak="$1.bak"
    if [[ -f "$1" ]]; then
        echo "backing up $1 to $bak"
        if [[ -f "$bak" ]]; then
            echo "file exists: '$bak'"
            read -r -p "overwrite? [y/N] " response
            case "$response" in
                [yY][eE][sS]|[yY])
                    mv "$1" "$bak"
                    ;;
                *)
                    return 0
                    ;;
            esac
        else
            mv "$1" "$bak"
        fi
    fi
}

<<install_omz>>
<<install_starship>>
<<config_omz>>
<<config_starship>>

<<setup_tmux>>
<<setup_pyenv>>

zsh

My default shell (also on latest macOS) is zsh. On CERN lxplus this can be configured in account settings > “List Services” > “LXPLUS and Linux” > “Settings” > “Unix Shell”.

Installation

I like to use ~oh-my-zsh~ (because I’m lazy):
if ! [[ -d "$HOME/.oh-my-zsh" ]]; then
  sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi

I assume that there’s a $HOME/bin folder. Ideally, it should already be there and be my bin repository with a collection of scripts:

if ! [[ -d "$HOME/bin" ]]; then
    git clone git@github.com:aykhuss/bin.git $HOME/bin
fi

.zshrc

This is the common configuration for oh-my-zsh. Local settings go into zshrc.local (consider moving this also to $HOME?)
make_backup "$HOME/.zshrc"
#> fill in the template variable for the path to this repo
sed -e "s|&AYKHUSS_CONFIG&|${SCRIPT_DIR}|g" ${SCRIPT_DIR}/zshrc > $HOME/.zshrc
#> this is the local configuration that is sourced in the main .zshrc
touch ${SCRIPT_DIR}/zshrc.local

starship

Big fan of ~starship~, a across-platform prompt written in rust. On macOS, just install it using brew: brew install starship. On lxplus, download the install.sh script and choose a destination bin folder you have write permission to, e.g. sh install.sh -b $HOME/bin.

if ! command -v starship &> /dev/null; then
    #> make sure $HOME/bin exists?
    wget https://starship.rs/install.sh
    sh install.sh -b $HOME/bin
    rm install.sh  # clean up
fi

The .zshrc above already contains src_bash{eval “$(starship init zsh)”} initialization.

All that is left is to copy over the starship configuration:

! [[ -d "$HOME/.config" ]]  &&  mkdir $HOME/.config
make_backup "$HOME/.config/starship.toml"
cp ${SCRIPT_DIR}/starship.toml $HOME/.config/starship.toml

Nerd Fonts

I use styles that require fonts patched by Nerd Fonts. For example, my current favourite is homebrew/cask-fonts/font-iosevka-nerd-font.

tmux

I use the neat ~oh-my-tmux~ configuration package.

if ! [[ -d "$HOME/.tmux" ]]; then
    git clone https://github.com/gpakosz/.tmux.git $HOME/.tmux
    make_backup "$HOME/.tmux.conf"
    ln -s -f $HOME/.tmux/.tmux.conf $HOME/.tmux.conf
    # cp $HOME/.tmux/.tmux.conf.local .
fi
make_backup $HOME/.tmux.conf.local
cp ${SCRIPT_DIR}/tmux.conf.local $HOME/.tmux.conf.local

python

The most hassle-free way of installing python on my systems, for me, was using pyenv.

if ! command -v pyenv &> /dev/null; then
    #> on macOS, we use homebrew to install
    if command -v brew &> /dev/null; then
        brew update
        brew install pyenv
    else
        curl https://pyenv.run | bash
    fi
fi
#> set up for zsh & reload
echo 'export PYTHONHOME=' >> ${SCRIPT_DIR}/zshrc.local
echo 'export PYTHONPATH=' >> ${SCRIPT_DIR}/zshrc.local
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ${SCRIPT_DIR}/zshrc.local
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ${SCRIPT_DIR}/zshrc.local
echo 'eval "$(pyenv init -)"' >> ${SCRIPT_DIR}/zshrc.local
source ${SCRIPT_DIR}/zshrc.local
#> install a recent version and set it as the default
pyenv install 3.12.1
pyenv global 3.12.1