From b9e9909aa856b26abe65b3458031fcae20fb5cf7 Mon Sep 17 00:00:00 2001 From: Charles Gould Date: Sat, 22 Jun 2019 11:05:10 -0400 Subject: [PATCH] Initial commit --- .bashrc | 42 +++++++++++++++ Brewfile | 32 +++++++++++ Brewfile.opt | 19 +++++++ README.md | 11 ++++ fish/config.fish | 34 ++++++++++++ fish/fish_variables | 34 ++++++++++++ fish/functions/compress_video.fish | 22 ++++++++ fish/functions/fish_prompt.fish | 23 ++++++++ fish/functions/fish_prompt_git_settings.fish | 38 +++++++++++++ fish/functions/hr.fish | 5 ++ fish/functions/motd.fish | 6 +++ fish/functions/portlistener.fish | 7 +++ git/config | 56 ++++++++++++++++++++ install-symlinks.sh | 12 +++++ install.sh | 21 ++++++++ nvim/init.vim | 34 ++++++++++++ 16 files changed, 396 insertions(+) create mode 100644 .bashrc create mode 100644 Brewfile create mode 100644 Brewfile.opt create mode 100644 README.md create mode 100644 fish/config.fish create mode 100644 fish/fish_variables create mode 100644 fish/functions/compress_video.fish create mode 100644 fish/functions/fish_prompt.fish create mode 100644 fish/functions/fish_prompt_git_settings.fish create mode 100644 fish/functions/hr.fish create mode 100644 fish/functions/motd.fish create mode 100644 fish/functions/portlistener.fish create mode 100644 git/config create mode 100755 install-symlinks.sh create mode 100755 install.sh create mode 100644 nvim/init.vim diff --git a/.bashrc b/.bashrc new file mode 100644 index 0000000..f5a9b64 --- /dev/null +++ b/.bashrc @@ -0,0 +1,42 @@ +# Set global variables +export EDITOR=nvim +export LANG='en_US.UTF-8' +export MANPAGER='nvim +Man!' + +# Path +export PATH="$HOME/bin" +export PATH="$PATH:/usr/local/bin" +export PATH="$PATH:/usr/bin" +export PATH="$PATH:/bin" +export PATH="$PATH:/usr/local/sbin" +export PATH="$PATH:/usr/sbin" +export PATH="$PATH:/sbin" + +# Java environment +export JAVA_HOME_8=$(/usr/libexec/java_home -v 1.8) +export JAVA_HOME_11=$(/usr/libexec/java_home -v 11) +export JAVA_HOME=$JAVA_HOME_8 + +# Aliases +alias adventure='emacs -batch -l dunnet' +alias afk='pmset displaysleepnow' +alias dnsflush='sudo killall -HUP mDNSResponder' +alias java8="set -gx JAVA_HOME $JAVA_HOME_8" +alias java11="set -gx JAVA_HOME $JAVA_HOME_11" +alias md5sum="md5 -r $argv" +alias vi='nvim' + +# Do not save lines which begin with a space character +# Do not save lines which match the previous history entry +# Remove from history all previous lines matching the current line +export HISTCONTROL=ignoreboth:erasedups + +# Completions +[ -f /usr/local/etc/bash_completion ] && source /usr/local/etc/bash_completion + +# Colorized prompt with Git information +export CLICOLOR=1 +GIT_PS1_SHOWDIRTYSTATE=true +GIT_PS1_SHOWSTASHSTATE=true +GIT_PS1_SHOWUNTRACKEDFILES=true +export PS1='\[\e[33m\]\w\[\e[36m\]$(__git_ps1)\[\e[m\] $ ' diff --git a/Brewfile b/Brewfile new file mode 100644 index 0000000..c5dbfa6 --- /dev/null +++ b/Brewfile @@ -0,0 +1,32 @@ +# Utilities +tap "homebrew/bundle" +tap "homebrew/cask" +tap "homebrew/core" +brew "bash" +brew "bat" +brew "diff-so-fancy" +brew "diskus" +brew "dos2unix" +brew "fd" +brew "fish" +brew "fzf" +brew "git" +brew "htop" +brew "jq" +brew "neovim" +brew "ripgrep" +brew "telnet" +brew "tig" +brew "tldr" +brew "tree" +brew "watch" +brew "wget" + +# JVM +tap "adoptopenjdk/openjdk" +cask "adoptopenjdk/openjdk/adoptopenjdk8" +cask "adoptopenjdk/openjdk/adoptopenjdk11" +brew "kotlin" +brew "maven" +brew "sbt" +brew "scala" diff --git a/Brewfile.opt b/Brewfile.opt new file mode 100644 index 0000000..e44782c --- /dev/null +++ b/Brewfile.opt @@ -0,0 +1,19 @@ +# Docker +cask "docker" +cask "minikube" +brew "docker-completion" +brew "kubernetes-cli" + +# Protobuf / gRPC +brew "grpc" +brew "grpcurl" +brew "protobuf" +brew "prototool" + +# Graphics +brew "handbrake" +brew "imagemagick" +brew "scour" +brew "svg2png" +brew "termtosvg" +brew "triangle" diff --git a/README.md b/README.md new file mode 100644 index 0000000..7058289 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +### Dotfiles + +My personal configuration files. + +##### Usage + +1. Clone this repository into `~/.dotfiles` +2. Install Homebrew: https://brew.sh/ +3. Install tools: `brew bundle install` +4. (Optional) Install more tools: `brew bundle install --file=Brewfile.opt` +5. Install everything else, including symlinks: `./install.sh` diff --git a/fish/config.fish b/fish/config.fish new file mode 100644 index 0000000..dcbba09 --- /dev/null +++ b/fish/config.fish @@ -0,0 +1,34 @@ +# Disable the default shell greeting +set fish_greeting + +# Disable the abbreviated directory format +set fish_prompt_pwd_dir_length 0 + +# Set global variables +set -x EDITOR nvim +set -x LANG en_US.UTF-8 +set -x MANPAGER 'nvim +Man!' + +# Java environment +set JAVA_HOME_8 (/usr/libexec/java_home -v 1.8) +set JAVA_HOME_11 (/usr/libexec/java_home -v 11) +set -x JAVA_HOME $JAVA_HOME_8 + +# Path +set --erase PATH +test -d $HOME/bin ; and set -x PATH $HOME/bin +test -d /usr/local/bin ; and set -x PATH $PATH /usr/local/bin +test -d /usr/bin ; and set -x PATH $PATH /usr/bin +test -d /bin ; and set -x PATH $PATH /bin +test -d /usr/local/sbin ; and set -x PATH $PATH /usr/local/sbin +test -d /usr/sbin ; and set -x PATH $PATH /usr/sbin +test -d /sbin ; and set -x PATH $PATH /sbin + +# Aliases +alias adventure='emacs -batch -l dunnet' +alias afk='pmset displaysleepnow' +alias dnsflush='sudo killall -HUP mDNSResponder' +alias java8="set -gx JAVA_HOME $JAVA_HOME_8" +alias java11="set -gx JAVA_HOME $JAVA_HOME_11" +alias md5sum="md5 -r $argv" +alias vi='nvim' diff --git a/fish/fish_variables b/fish/fish_variables new file mode 100644 index 0000000..22e8da6 --- /dev/null +++ b/fish/fish_variables @@ -0,0 +1,34 @@ +# This file contains fish universal variable definitions. +# VERSION: 3.0 +SETUVAR __fish_init_2_39_8:\x1d +SETUVAR __fish_init_2_3_0:\x1d +SETUVAR __fish_init_3_x:\x1d +SETUVAR fish_color_autosuggestion:969896 +SETUVAR fish_color_cancel:\x2dr +SETUVAR fish_color_command:c397d8 +SETUVAR fish_color_comment:e7c547 +SETUVAR fish_color_cwd:yellow +SETUVAR fish_color_cwd_root:red +SETUVAR fish_color_end:c397d8 +SETUVAR fish_color_error:d54e53 +SETUVAR fish_color_escape:00a6b2 +SETUVAR fish_color_history_current:\x2d\x2dbold +SETUVAR fish_color_host:normal +SETUVAR fish_color_match:\x2d\x2dbackground\x3dbrblue +SETUVAR fish_color_normal:normal +SETUVAR fish_color_operator:00a6b2 +SETUVAR fish_color_param:7aa6da +SETUVAR fish_color_quote:b9ca4a +SETUVAR fish_color_redirection:70c0b1 +SETUVAR fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_status:red +SETUVAR fish_color_user:brgreen +SETUVAR fish_color_valid_path:\x2d\x2dunderline +SETUVAR fish_greeting:\x1d +SETUVAR fish_key_bindings:fish_default_key_bindings +SETUVAR fish_pager_color_completion:normal +SETUVAR fish_pager_color_description:B3A06D\x1eyellow +SETUVAR fish_pager_color_prefix:white\x1e\x2d\x2dbold\x1e\x2d\x2dunderline +SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan +SETUVAR pure_version:2\x2e1\x2e5 diff --git a/fish/functions/compress_video.fish b/fish/functions/compress_video.fish new file mode 100644 index 0000000..0e006da --- /dev/null +++ b/fish/functions/compress_video.fish @@ -0,0 +1,22 @@ +function compress_video --argument-names srcfile + if test -z "$srcfile" + echo "Error: missing argument" + return 1 + end + if not test -f "$srcfile" + echo "Error: not a regular file: $srcfile" + return 2 + end + if not command --search --quiet HandBrakeCLI + echo "Error: HandBrakeCLI is required" + return 3 + end + + set --local dstdir (dirname $srcfile)/Compressed + set --local dstfile (dirname $srcfile)/Compressed/(basename $srcfile) + set --local preset 'Vimeo YouTube HQ 720p60' + + mkdir -p $dstdir + + HandBrakeCLI --preset $preset --input $srcfile --output $dstfile +end diff --git a/fish/functions/fish_prompt.fish b/fish/functions/fish_prompt.fish new file mode 100644 index 0000000..e05c0ed --- /dev/null +++ b/fish/functions/fish_prompt.fish @@ -0,0 +1,23 @@ +function fish_prompt --description 'Write out the prompt' + # Save status code for previous command + set -l last_status $status + + # Print working directory + set_color $fish_color_cwd + echo -n (prompt_pwd) + set_color normal + + # Print Git information + fish_prompt_git_settings + printf '%s ' (__fish_git_prompt) + + # Print status code for previous command, if nonzero + if not test $last_status -eq 0 + set_color $fish_color_error + echo -n "[$last_status] " + set_color normal + end + + # Print the final character (§) + echo -n "§ " +end diff --git a/fish/functions/fish_prompt_git_settings.fish b/fish/functions/fish_prompt_git_settings.fish new file mode 100644 index 0000000..28e598d --- /dev/null +++ b/fish/functions/fish_prompt_git_settings.fish @@ -0,0 +1,38 @@ +function fish_prompt_git_settings --description 'Configure the git prompt' + # Toggles + #if not set -q __fish_git_prompt_showcolorhints + # set -g __fish_git_prompt_showcolorhints 1 + #end + if not set -q __fish_git_prompt_showdirtystate + set -g __fish_git_prompt_showdirtystate 1 + end + if not set -q __fish_git_prompt_showstashstate + set -g __fish_git_prompt_showstashstate 1 + end + if not set -q __fish_git_prompt_showuntrackedfiles + set -g __fish_git_prompt_showuntrackedfiles 1 + end + if not set -q __fish_git_prompt_showupstream + set -g __fish_git_prompt_showupstream "none" + end + + # Colors + if not set -q __fish_git_prompt_color_branch + set -g __fish_git_prompt_color_branch cyan + end + if not set -q __fish_git_prompt_color_dirtystate + set -g __fish_git_prompt_color_dirtystate cyan + end + if not set -q __fish_git_prompt_color_invalidstate + set -g __fish_git_prompt_color_invalidstate red + end + if not set -q __fish_git_prompt_color_stagedstate + set -g __fish_git_prompt_color_stagedstate cyan + end + if not set -q __fish_git_prompt_color_stashstate + set -g __fish_git_prompt_color_stashstate cyan + end + if not set -q __fish_git_prompt_color_untrackedfiles + set -g __fish_git_prompt_color_untrackedfiles cyan + end +end diff --git a/fish/functions/hr.fish b/fish/functions/hr.fish new file mode 100644 index 0000000..38e8341 --- /dev/null +++ b/fish/functions/hr.fish @@ -0,0 +1,5 @@ +function hr --description "Draw horizontal rule" + set --local char '─' + printf "%.s$char" (seq $COLUMNS) + echo +end diff --git a/fish/functions/motd.fish b/fish/functions/motd.fish new file mode 100644 index 0000000..c9fce05 --- /dev/null +++ b/fish/functions/motd.fish @@ -0,0 +1,6 @@ +function motd + if not command --search --quiet fortune ; echo "Error: function requires fortune" ; return 1 ; end + if not command --search --quiet cowsay ; echo "Error: function requires cowsay" ; return 2 ; end + if not command --search --quiet lolcat ; echo "Error: function requires lolcat" ; return 3 ; end + fortune | cowsay | lolcat +end diff --git a/fish/functions/portlistener.fish b/fish/functions/portlistener.fish new file mode 100644 index 0000000..fc845f2 --- /dev/null +++ b/fish/functions/portlistener.fish @@ -0,0 +1,7 @@ +function portlistener --argument-names port + if test -n "$port" + lsof -n -i :$port | grep LISTEN + else + lsof -n -i | grep LISTEN + end +end diff --git a/git/config b/git/config new file mode 100644 index 0000000..6d13482 --- /dev/null +++ b/git/config @@ -0,0 +1,56 @@ +[user] + name = Charles Gould + email = cgould@protonmail.com +[core] + autocrlf = input + editor = nvim + pager = diff-so-fancy | less --tabs=4 -RFX +[alias] + aliases = config --get-regexp alias + br = branch + co = checkout + df = diff + dc = diff --cached + dch = diff --cached HEAD~ + lol = log --oneline --max-count=10 --decorate=no + ss = status --short + st = status --long + cp = cherry-pick + f = fetch --all --prune + pl = pull + ps = push + pu = push --set-upstream + pf = push --force + cm = commit -m + cv = commit -v + ca = commit --amend + can = commit --amend --no-edit + cand = commit --amend --no-edit --date=now + rbi = rebase --interactive + rh = reset HEAD +[color] + ui = auto +[color "branch"] + current = yellow reverse + local = yellow + remote = green +[color "diff"] + meta = yellow + frag = magenta bold + commit = yellow bold + old = red bold + new = green bold + whitespace = red reverse +[color "diff-highlight"] + oldNormal = red bold + oldHighlight = red bold 52 + newNormal = green bold + newHighlight = green bold 22 +[color "status"] + added = yellow + changed = green + untracked = cyan +[push] + default = current +[log] + date = human diff --git a/install-symlinks.sh b/install-symlinks.sh new file mode 100755 index 0000000..bb82300 --- /dev/null +++ b/install-symlinks.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +DOTFILES="$HOME/.dotfiles" + +# Create required directories before making links +mkdir -p "$HOME/.config" + +# Create symlinks, forcing updates +ln -Fsv "$DOTFILES/.bashrc" "$HOME/.bashrc" # bash does not support XDG config +ln -Fsv "$DOTFILES/fish" "$HOME/.config" +ln -Fsv "$DOTFILES/nvim" "$HOME/.config" +ln -Fsv "$DOTFILES/git" "$HOME/.config" diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..481da7e --- /dev/null +++ b/install.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +DOTFILES="$HOME/.dotfiles" + +# Install plugin manager for Neovim, if it doesn't exist +VIM_PLUG_SRC="https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" +VIM_PLUG_DST="$HOME/.local/share/nvim/site/autoload/plug.vim" +if [ ! -f "$VIM_PLUG_DST" ]; then + echo "Downloading plug.vim ..." + curl -fLo "$VIM_PLUG_DST" --create-dirs "$VIM_PLUG_SRC" +fi + +# Add Homebrew-managed shells to system list +grep -q /usr/local/bin/bash /etc/shells || echo /usr/local/bin/bash | sudo tee -a /etc/shells +grep -q /usr/local/bin/fish /etc/shells || echo /usr/local/bin/fish | sudo tee -a /etc/shells + +# Make fish the default shell +chsh -s /usr/local/bin/fish + +# Install symlinks +"$DOTFILES/install-symlinks.sh" diff --git a/nvim/init.vim b/nvim/init.vim new file mode 100644 index 0000000..eb1558f --- /dev/null +++ b/nvim/init.vim @@ -0,0 +1,34 @@ +" use Vim mode instead of pure Vi, must be the first instruction +" wrapped in conditional to avoid side effects when already set +if &compatible + set nocompatible +endif + +" configure plugins using vim-plug +" https://github.com/junegunn/vim-plug +call plug#begin('~/.cache/nvim/plugged') +Plug 'https://github.com/farmergreg/vim-lastplace' " intelligently reopen files at last edit position +Plug 'https://github.com/ntpeters/vim-better-whitespace' " highlights trailing whitespace, :StripWhitespace to remove +Plug 'https://github.com/tpope/vim-sensible' " defaults everyone can agree on +Plug 'https://github.com/vim-airline/vim-airline' " fancy statusline +call plug#end() + +" display settings +set nonumber norelativenumber " show hybrid line numbers at startup +noremap :set number! relativenumber! " toggle line numbers + +" write settings +set confirm " confirm :q in case of unsaved changes + +" tab/space settings +set expandtab +set shiftwidth=2 +set softtabstop=2 + +" clipboard settings +set clipboard=unnamedplus " enable copy/paste/yank to and from Vim/Neovim + +" paste settings (in Neovim, use plain insert mode) +if !has('nvim') + set pastetoggle= +endif