Home

Awesome

dotfiles

This repository contains all of my configuration for MacOS and Linux, with a focus on terminal, editor, shell, programming environments etc. This repository can easily be forked to allow you to create and customise your own machine setup.

This repository also contains some handy Shell Scripts and Aliases that others might find helpful.

Some key features are:

⚠️ Warning: I have tried wherever possible to ensure no destructive change will happen when working with the scripts or commands in this project, without explicit user intervention (i.e. the user typing yes to make changes). The goal is that you can run the setup scripts without changing anything unless you explicitly choose a feature. However, I cannot guarantee I haven't made an mistakes, so please exercise caution.

Screenshot on MacOSX

Screenshot: MacOSX

Screenshot on Ubuntu

Screenshot: Ubuntu

<!-- vim-markdown-toc GFM --> <!-- vim-markdown-toc -->

Introduction

The goal of this project is to provide a single command which will setup key features of the system. Each feature should be orthogonal and not depend on other features.

The following is set up:

Quick Start

The fastest way to setup a new machine:

# MacOSX only - install command-line tools (so that we have git).
xcode-select --install

# Create a working environment, in my standard format.
mkdir -p ~/repos/github/dwmkerr
cd ~/repos/github/dwmkerr

# Clone the dotfiles - note that a new machine will not have my SSH key
# so this is over https.
git clone https://github.com/dwmkerr/dotfiles.git
cd dotfiles

# Setup the machine - the script will run interactively.
make setup

SSH Keys, GPG Keys and Private Files

SSH Keys, GPG Keys and Private Files (such as cloud configuration files, which contain sensitive information) can be backed up and restored to a folder on AWS.

This means that to transfer sensitive information from one machine to another, you can simple run backup-private-files on the source machine, and restore-private-files on the target machine.

Backing Up Private Files

As long as your AWS profile is configured, this is a one-liner:

make private-files-backup

You will be asked for confirmation before backing up any files.

Restoring Private Files

Assuming you have the AWS CLI installed, run the following commands to create a profile (you will need credentials, which should be in the password manager):

# Restore private files:
make private-files-restore

You will be asked for confirmation before restoring any files.

Configuring Backup and Restore

The following variables can be used to configure the backup and restore process. The values shown are the defaults, so these only need to be changed if you are using a different S3 bucket or AWS profile name.

# Define the name of the AWS profile used to access the S3 bucket.
# Default is "dwmkerr".
DOTFILES_PRIVATE_PROFILE="dwmkerr" # Use whatever name makes sense for you!
# Define the name of the AWS S3 bucket that stores private files.
# Default is "dwmkerr-dotfiles-private".
DOTFILES_PRIVATE_S3_BUCKET="dwmkerr-dotfiles-private"

# Run backup/restore as normal...,
make private-files-restore
make private-files-backup

# Backup private files:
make private-files-backup

MacOS - Manual Steps

The following steps have not yet been automated:

  1. Sign into Chrome and setup sync
  2. Install and into Bitwarden
  3. Open Joplin and enable S3 synchronisation (AWS credentials are in Bitwarden)
  4. For Terminal, install the profiles under ./terminal to give the One Dark / One Light themes

iTerm2 Configuration

Install the profile under ./terminal/dwmkerrj.json which configures:

Then for the global preferences, set:


These steps are work in progress.

  1. Restore Parallels virtual machines from backup.
  2. Restore the ~/.private/ folder from a secure backup, to bring back project specific secrets.

Some other tools I install which I have paid subscriptions for or are essentials:

Features

Each of the 'features' listed below typically has a ./setup.d/x-<feature-name>.sh script to install or upgrade the feature. Some also have a ./.shell.d/x-<feature-name>.sh file which is sourced by interactive shells if commands need to be run on shell startup (such as enabled pyenv and similar features. The numbers are used to ensure that if there are dependencies on features, we try and install in the right order.

Private Files

Private files, such as GPG and SSH keys can be backed up or restored with the commands below:

make private-files-backup
make private-files-restore

Package Manager

OSX Configuration

Various preferences for OSX, such as showing the path bar on the Finder windows, smaller icons, etc.

Git

Sets up gnupg and the git user settings.

Node

Sets up nvm (Node Version Manager) and the current LTS version of node.

Python

Sets up pyenv (Python Environment Manager) and python3.

Ruby

Sets up rvm (Ruby Version Manager) and ruby.

Golang

Sets up golang and $GOPATH.

Vim

Sets up vim and vim config file. Plugins are installed with PlugInstall.

TMux

This installs tmux and the Tmux Plugin Manager.

Shell

This installs bash, zsh and sets zsh as the default shell for the user. Sets the command prompt and sources the .shell.sh file.

Installs On My Zsh, which I use for themes and some conveniences, and copies over the zsh themes.

To enable features to be used in shells, the shell configuration file will source our special shell.sh file. This file then goes and sources the appropriate files from ~/.shell.d.

OSX Applications

Many applications I used, such as WhatsApp, Visual Studio Code, T-Mux.

This also installs common CLI applications, such as tree, as well as GNU tools (coretools, gsed etc).

Commandline Tools

ag is setup and will use a global ignore file at ~/.ignore. vim-ack also uses this file.

Developer Guide

There's not much to say really, just follow the principles below:

Ubuntu Terminal Configuration

Set the OneDark Theme with:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/denysdovhan/gnome-terminal-one/master/one-dark.sh)"

Shell Prompt Theme

The set_ps1.sh can be used to set PS1 styles:

$ set_ps1 debian

The PS1 is converted to Z-Shell format if the current shell is zsh. My current 'default' theme is named dwmkerr.

Shell Scripts and Aliases

The following features are loaded as part of my configuration. Check the link to the source if you'd like to copy over an individual feature for your own use.

Shell Commands

The following shell commands are setup:

CommandUsage
Quick Aliasesshell.d/aliases.sh
serveServe the current folder over HTTP on port 3000.
vinillaOpen vi without loading the vimrc (i.e. vanilla configuration).
Basic Functions
eachdirRun a command in each child directory.
DGet the date in ISO86091 format (e.g. 2021-04-24).
mkdMake a directory, using -p and cd into it.
restart_shellRestart the current shell process, useful when profile changes.
revcutCut, but in reverse (i.e. from the last to the first delimiter).
Git Functions
ghcloneClone from GitHub, e.g: ghclone dwmkerr/effective-shell.

Shell Scripts

ScriptUsage
./scripts/test-shell.d.shSource each ./shell.d file in turn, time result. Good for checking for errors.

Cheat Sheet - TMux

CommandUsage
Sessions
tmux detach -E 'bash --noprofile --norcDetach the current session and open a vanilla shell.
--------------------------------------------------------------------------------------------------
<leader> RReload Tmux configuration (i.e. source the ~/.tmux.conf file).
man tmuxGet help on commands.
<leader> ?Get help on commands.
Ctrl + h/j/k/lNavigate splits (vim aware)
Meta + h/lMove through tabs.
Ctrl + Meta + h/j/k/lMove through tabs.
move-window -rRe-order the tab numbers (useful if there are gaps).
<leader> / SShow Sessions with window preview, hit x to delete.
<leader> / $Rename session.
new -s <name>New session with name.
<leader> / Ctrl+SSave Tmux Session
<leader> / Ctrl+RRestore Tmux Session
<leader> /Last split
<leader> {Swap pane left
<leader> }Swap pane right

Cheat Sheet - Vim

Here's a quick reference. My <Leader> is \, so I've written shortcuts as \x rather than <Leader>x for brevity. I still need to port the above to the structure below.

CommandUsage
Custom Commands
<leader>tOpen current file in NERDTree.
<leader>wWrite buffer.
<leader>\\Open buffer in new tab.
<leader>dOpen word under cursor in Dash.
<leader>tShow current buffer in NERDTree.
<leader>FToggle focus mode.
Other Commands
\[<Space>blank line above
]<Space>blank line below
sjSplitjoin down (i.e. split a line downwards).
skSplitjoin up (i.e. join a line upwards).
:Tabularize /=Line up selection, using '='
Navigation
gdWhere possible, will go to a local definition. Supercharged by vim-coc.
gdhttps://vi.stackexchange.com/questions/42414/for-vim-and-specifically-coc-vim-is-it-idomatic-to-use-gd-to-open-a-link/42415#42415
gfOpen file under cursor.
gxOpen link or address under cursor.
Spelling
]s and [sNext/Previous spelling error.
z= and zgCheck dictionary / add to dictionary.
MarkdownProvided by vim-markdown
]] and [[Next and previous headers.
gxOpen link in standard editor.
FocusFrom vim-goyo and vim-limelight
:GoyoEnter focus mode.
:Limelight 0.8 and :Limelight!Go into limelight, 80% ultra focus, and toggle limelight.
let g:limelight_paragraph_span = 1Span more paragraphs in limelight.
Markdown Tables
\tmEnter/Exit 'table mode', which will dynamically format markdown tables.
ci|Example of the motion for cells - i.e. 'change-in-cell'.

Note: including the vertical pipe | in the table above would cause rendering issues. So instead, the unicode character is used to illustrate the commands. Do not use the unicode character, use the normal ASCII 0x7C character.

Other useful stuff:

Effective Vim

Here's some of the stuff I find most useful.

The Golden Rule

If you repeat yourself or do dumb formatting crap, find the idiomatically correct way to do something or use a plugin. Always look up native ways first.

NerdTree

fzf-lua

COC

I've barely scratched the surface and will force myself to learn more.

JavaScript, TypeScript, React

I use vim-polyglot and vim-coc with vim-tsserver - this seems to cover most of my needs without any additional plugins.

Potential Improvements

Fuzzy Find

I'm currently using fzf-lua after spending a few years on fzf.vim. It seems lightening fast but a little harder to decipher some of the documentation. The main customisations andre:

WIP

fd is required to be installed something like this with 'fd_opts' would allow for excluding node modules etc :lua require('fzf-lua').files({ fzf_opts = {['--layout'] = 'reverse-list'} })

Split-Join

I find the sj and sk commands invaluable, until something like this becomes native it's a super useful plugin.

Vim Tab Completion

COC is used - it's basically setup like VS Code - tab selects the first option. Then <C-n> and <C-p> to cycle (or up/down).

Cheat Sheet - Shell

These are just some common commands I often forget:

CommandUsage
tput cvvisShow the cursor. Useful if it disappears when a command hides it and fails to restore it.

Tooling Choices

Vim

Why Vim Plug over Vundle?

I was impressed enough with the comments on this post to make the switch, particularly as coc doesn't support Vundle, meaning I had to give Plug a try.

TODO