diff --git a/dot-src-file-list b/dot-src-file-list new file mode 100644 index 0000000..e5603d7 --- /dev/null +++ b/dot-src-file-list @@ -0,0 +1,14 @@ +.bash_prompt +.bash_aliases +.bash_profile +.bashrc +.path +.exports +.functions +.vim +.vim/backups +.vim/swaps +.vim/undo +.vimrc +bin +bin/git_diff_wrapper diff --git a/home/.bash_aliases b/home/.bash_aliases index e82e450..5903dc4 100644 --- a/home/.bash_aliases +++ b/home/.bash_aliases @@ -1,16 +1,65 @@ #!/usr/bin/env bash +# Easier navigation: .., ..., ...., ....., ~ and - alias cd..="cd .." alias ..="cd .." -alias ll="ls -lhA" +alias ...="cd ../.." +alias ....="cd ../../.." +alias .....="cd ../../../.." + +# Shortcuts +alias d="cd ~/Documents/Dropbox" +alias dl="cd ~/Downloads" +alias dt="cd ~/Desktop" +alias p="cd ~/Projects" + +# Not sure what to do about colors, added this as a placeholder +# Detect which `ls` flavor is in use +if ls --color > /dev/null 2>&1; then # GNU `ls` + colorflag="--color" +# export LS_COLORS='no=00:fi=00:di=01;31:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:' +else # macOS `ls` + colorflag="-G" +# export LSCOLORS='BxBxhxDxfxhxhxhxhxcxcx' +fi + # Directory listings # LS_COLORS='no=01;37:fi=01;37:di=07;96:ln=01;36:pi=01;32:so=01;35:do=01;35:bd=01;33:cd=01;33:ex=01;31:mi=00;05;37:or=00;05;37:' -# -G Add colors to ls -# -l Long format +# -G Add colors to ls, can be -G or --color +# -l Long formaj # -h Short size suffixes (B, K, M, G, P) # -p Postpend slash to folders +# -F add one char of */=>@| to enteries # alias ls='ls -G -h -p ' -alias ll="ls -l -G -h -p" +alias ll="ls -l ${colorflag} -h -p" + +# List all files colorized in long format with short size buffers postpend / +alias ll="ls -l ${colorflag} -h -p" + +# List all files colorized in long format +alias l="ls -lF ${colorflag}" + +# List all files colorized in long format, excluding . and .. +alias la="ls -lAF ${colorflag}" + +# List only directories +alias lsd="ls -lF ${colorflag} | grep --color=never '^d'" + +# Always use color output for `ls` or disable (pick one) +# alias ls="command ls ${colorflag}" +alias ls="ls -F" + +# Always enable colored `grep` output +# Note: `GREP_OPTIONS="--color=auto"` is deprecated, hence the alias usage. +alias grep='grep --color=auto' +alias fgrep='fgrep --color=auto' +alias egrep='egrep --color=auto' + +# Enable aliases to be sudo’ed +alias sudo='sudo ' + +# Get week number +alias week='date +%V' # Show/hide hidden files in Finder alias show="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder" @@ -24,7 +73,7 @@ alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && k alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend" # Print each PATH entry on a separate line -alias path="echo -e ${PATH//:/\\n}" +alias path='echo -e ${PATH//:/\\n}' # Disable Spotlight alias spotoff="sudo mdutil -a -i off" @@ -37,4 +86,16 @@ alias spoton="sudo mdutil -a -i on" # Flush the DNS on Mac alias dnsflush="dscacheutil -flushcache" +# Flush Directory Service cache +alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder" + +# Google Chrome +alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome' +alias canary='/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary' + +# Recursively delete `.DS_Store` files +alias cleanupDS="find . -type f -name '*.DS_Store' -ls -delete" +# Unsure of usage, comment out for now +# URL-encode strings +# alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"' diff --git a/home/.bash_profile b/home/.bash_profile new file mode 100644 index 0000000..0c67d06 --- /dev/null +++ b/home/.bash_profile @@ -0,0 +1,50 @@ +# Add `~/bin` to the `$PATH` +export PATH="$HOME/bin:$PATH"; + +# Load the shell dotfiles, and then some: +# * ~/.path can be used to extend `$PATH`. +# * ~/.extra can be used for other settings you don’t want to commit. +for file in ~/.{path,bash_prompt,exports,bash_aliases,functions,extra}; do + [ -r "$file" ] && [ -f "$file" ] && source "$file"; +done; +unset file; + +# Case-insensitive globbing (used in pathname expansion) +shopt -s nocaseglob; + +# Append to the Bash history file, rather than overwriting it +shopt -s histappend; + +# Autocorrect typos in path names when using `cd` +shopt -s cdspell; + +# Enable some Bash 4 features when possible: +# * `autocd`, e.g. `**/qux` will enter `./foo/bar/baz/qux` +# * Recursive globbing, e.g. `echo **/*.txt` +for option in autocd globstar; do + shopt -s "$option" 2> /dev/null; +done; + +# Add tab completion for many Bash commands +if which brew &> /dev/null && [ -r "$(brew --prefix)/etc/profile.d/bash_completion.sh" ]; then + # Ensure existing Homebrew v1 completions continue to work + export BASH_COMPLETION_COMPAT_DIR="$(brew --prefix)/etc/bash_completion.d"; + source "$(brew --prefix)/etc/profile.d/bash_completion.sh"; +elif [ -f /etc/bash_completion ]; then + source /etc/bash_completion; +fi; + +# Enable tab completion for `g` by marking it as an alias for `git` +if type _git &> /dev/null; then + complete -o default -o nospace -F _git g; +fi; + +# Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards +[ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2- | tr ' ' '\n')" scp sftp ssh; + +# Add tab completion for `defaults read|write NSGlobalDomain` +# You could just use `-g` instead, but I like being explicit +complete -W "NSGlobalDomain" defaults; + +# Add `killall` tab completion for common apps +complete -o "nospace" -W "Contacts Calendar Dock Finder Mail Safari iTunes SystemUIServer Terminal Twitter" killall; diff --git a/home/.bash_prompt b/home/.bash_prompt new file mode 100644 index 0000000..c327c31 --- /dev/null +++ b/home/.bash_prompt @@ -0,0 +1,134 @@ +#!/usr/bin/env bash + +# Shell prompt based on the Solarized Dark theme. +# Screenshot: http://i.imgur.com/EkEtphC.png +# Heavily inspired by @necolas’s prompt: https://github.com/necolas/dotfiles +# iTerm → Profiles → Text → use 13pt Monaco with 1.1 vertical spacing. + +if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then + export TERM='gnome-256color'; +elif infocmp xterm-256color >/dev/null 2>&1; then + export TERM='xterm-256color'; +fi; + +prompt_git() { + local s=''; + local branchName=''; + + # Check if the current directory is in a Git repository. + git rev-parse --is-inside-work-tree &>/dev/null || return; + + # Check for what branch we’re on. + # Get the short symbolic ref. If HEAD isn’t a symbolic ref, get a + # tracking remote branch or tag. Otherwise, get the + # short SHA for the latest commit, or give up. + branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \ + git describe --all --exact-match HEAD 2> /dev/null || \ + git rev-parse --short HEAD 2> /dev/null || \ + echo '(unknown)')"; + + # Early exit for Chromium & Blink repo, as the dirty check takes too long. + # Thanks, @paulirish! + # https://github.com/paulirish/dotfiles/blob/dd33151f/.bash_prompt#L110-L123 + repoUrl="$(git config --get remote.origin.url)"; + if grep -q 'chromium/src.git' <<< "${repoUrl}"; then + s+='*'; + else + # Check for uncommitted changes in the index. + if ! $(git diff --quiet --ignore-submodules --cached); then + s+='+'; + fi; + # Check for unstaged changes. + if ! $(git diff-files --quiet --ignore-submodules --); then + s+='!'; + fi; + # Check for untracked files. + if [ -n "$(git ls-files --others --exclude-standard)" ]; then + s+='?'; + fi; + # Check for stashed files. + if $(git rev-parse --verify refs/stash &>/dev/null); then + s+='$'; + fi; + fi; + + [ -n "${s}" ] && s=" [${s}]"; + + echo -e "${1}${branchName}${2}${s}"; +} + +if tput setaf 1 &> /dev/null; then + tput sgr0; # reset colors + bold=$(tput bold); + reset=$(tput sgr0); + # Solarized colors, taken from http://git.io/solarized-colors. + black=$(tput setaf 0); + blue=$(tput setaf 153); + cyan=$(tput setaf 37); + green=$(tput setaf 71); + orange=$(tput setaf 166); + purple=$(tput setaf 125); + red=$(tput setaf 124); + violet=$(tput setaf 61); + white=$(tput setaf 15); + yellow=$(tput setaf 228); +else + bold=''; + reset="\e[0m"; + black="\e[1;30m"; + blue="\e[1;34m"; + cyan="\e[1;36m"; + green="\e[1;32m"; + orange="\e[1;33m"; + purple="\e[1;35m"; + red="\e[1;31m"; + violet="\e[1;35m"; + white="\e[1;37m"; + yellow="\e[1;33m"; +fi; + +# Highlight the user name when logged in as root. +if [[ "${USER}" == "root" ]]; then + userStyle="${red}"; +else + userStyle="${orange}"; +fi; + +# Highlight the hostname when connected via SSH. +if [[ "${SSH_TTY}" ]]; then + hostStyle="${bold}${red}"; +else + hostStyle="${yellow}"; +fi; + +# Set the terminal title and prompt. +PS1="\[\033]0;\W\007\]"; # working directory base name +PS1+="\[${bold}\]\n"; # newline +PS1+="\[${userStyle}\]\u"; # username +PS1+="\[${white}\]@"; +PS1+="\[${hostStyle}\]\h"; # host +PS1+="\[${white}\] in "; +PS1+="\[${green}\]\w"; # working directory full path +PS1+="\$(prompt_git \"\[${white}\] on \[${blue}\]\" \"\[${blue}\]\")"; # Git repository details +PS1+="\n"; +PS1+="\[${white}\]\$ \[${reset}\]"; # `$` (and reset color) +# export PS1; + +PS2="\[${yellow}\]→ \[${reset}\]"; +# export PS2; + +# JFV Not ready for colors yet +PS1="\[\033]0;\W\007\]"; # working directory base name +# PS1+="\n"; # newline +PS1+="\u"; # username +PS1+="@"; +PS1+="\[${reset}\]\h"; # host +PS1+=" in "; +PS1+="\w"; # working directory full path +PS1+="\$(prompt_git \" on \]\" \"\")"; # Git repository details +PS1+="\n"; +PS1+="\$ "; +export PS1; + +PS2="> "; +export PS2; diff --git a/home/.bashrc b/home/.bashrc new file mode 100644 index 0000000..0413ca9 --- /dev/null +++ b/home/.bashrc @@ -0,0 +1,4 @@ +# If not running interactively, don't do anything +[[ $- == *i* ]] || return + +[ -n "$PS1" ] && source ~/.bash_profile; diff --git a/home/.exports b/home/.exports new file mode 100644 index 0000000..fd55704 --- /dev/null +++ b/home/.exports @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Make vim the default editor. +export EDITOR='vim'; + +# Enable persistent REPL history for `node`. +export NODE_REPL_HISTORY=~/.node_history; +# Allow 32³ entries; the default is 1000. +export NODE_REPL_HISTORY_SIZE='32768'; +# Use sloppy mode by default, matching web browsers. +export NODE_REPL_MODE='sloppy'; + +# Make Python use UTF-8 encoding for output to stdin, stdout, and stderr. +export PYTHONIOENCODING='UTF-8'; + +# Increase Bash history size. Allow 2k entries; the default is 500. +export HISTSIZE='2048'; +export HISTFILESIZE="${HISTSIZE}"; +# Omit duplicates and commands that begin with a space from history. +export HISTCONTROL='ignoreboth'; +export HISTIGNORE="clear:history"; + +# Prefer US English and use UTF-8. +export LANG='en_US.UTF-8'; +export LC_ALL='en_US.UTF-8'; + +# Turned off color for now +# Highlight section titles in manual pages. +# export LESS_TERMCAP_md="${yellow}"; + +# Don’t clear the screen after quitting a manual page. +export MANPAGER='less -X'; + +# Avoid issues with `gpg` as installed via Homebrew. +# https://stackoverflow.com/a/42265848/96656 +export GPG_TTY=$(tty); + +# Hide the “default interactive shell is now zsh” warning on macOS. +export BASH_SILENCE_DEPRECATION_WARNING=1; diff --git a/home/.functions b/home/.functions new file mode 100644 index 0000000..42beb55 --- /dev/null +++ b/home/.functions @@ -0,0 +1,92 @@ +#!/usr/bin/env bash + +# Find all files containing the specified string (ignorecase) +function findit() { find . -name "*" -exec grep -i -s -q $1 {} \; -print; } + + +# Create a new directory and enter it +function mkd() { + mkdir -p "$@" && cd "$_"; +} + +# Change working directory to the top-most Finder window location +function cdf() { # short for `cdfinder` + cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')"; +} + +# Use Git’s colored diff when available +hash git &>/dev/null; +if [ $? -eq 0 ]; then + function diff() { + git diff --no-index --color-words "$@"; + } +fi; + +# Create a data URL from a file +function dataurl() { + local mimeType=$(file -b --mime-type "$1"); + if [[ $mimeType == text/* ]]; then + mimeType="${mimeType};charset=utf-8"; + fi + echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')"; +} + +# Start an HTTP server from a directory, optionally specifying the port +function server() { + local port="${1:-8000}"; + sleep 1 && open "http://localhost:${port}/" & + # Set the default Content-Type to `text/plain` instead of `application/octet-stream` + # And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files) + python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"; +} + +# Start a PHP server from a directory, optionally specifying the port +# (Requires PHP 5.4.0+.) +function phpserver() { + local port="${1:-4000}"; + local ip=$(ipconfig getifaddr en1); + sleep 1 && open "http://${ip}:${port}/" & + php -S "${ip}:${port}"; +} + +# Show all the names (CNs and SANs) listed in the SSL certificate +# for a given domain +function getcertnames() { + if [ -z "${1}" ]; then + echo "ERROR: No domain specified."; + return 1; + fi; + + local domain="${1}"; + echo "Testing ${domain}…"; + echo ""; # newline + + local tmp=$(echo -e "GET / HTTP/1.0\nEOT" \ + | openssl s_client -connect "${domain}:443" -servername "${domain}" 2>&1); + + if [[ "${tmp}" = *"-----BEGIN CERTIFICATE-----"* ]]; then + local certText=$(echo "${tmp}" \ + | openssl x509 -text -certopt "no_aux, no_header, no_issuer, no_pubkey, \ + no_serial, no_sigdump, no_signame, no_validity, no_version"); + echo "Common Name:"; + echo ""; # newline + echo "${certText}" | grep "Subject:" | sed -e "s/^.*CN=//" | sed -e "s/\/emailAddress=.*//"; + echo ""; # newline + echo "Subject Alternative Name(s):"; + echo ""; # newline + echo "${certText}" | grep -A 1 "Subject Alternative Name:" \ + | sed -e "2s/DNS://g" -e "s/ //g" | tr "," "\n" | tail -n +2; + return 0; + else + echo "ERROR: Certificate not found."; + return 1; + fi; +} + +# `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring +# the `.git` directory, listing directories first. The output gets piped into +# `less` with options to preserve color and line numbers, unless the output is +# small enough for one screen. +function tre() { + tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX; +} diff --git a/home/.path b/home/.path new file mode 100644 index 0000000..116610c --- /dev/null +++ b/home/.path @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Save Homebrew's installed location. +brew_prefix=$(brew --prefix) + +check_brew_path() +{ + local formulae=$1 + echo $PATH | grep -v "${brew_prefix}\/opt\/${formulae}\/" &>/dev/null && export PATH="${brew_prefix}/opt/${formulae}/libexec/gnubin:$PATH" +} + +# brew install coreutils + check_brew_path "coreutils" +# brew install findutils + check_brew_path "findutils" +# brew install gnu-sed + check_brew_path "gnu-sed" +# brew install grep + check_brew_path "grep" + +unset check_brew_path +unset brew_prefix + +# Unsure and not yet tested/tried; Found these when running brew install +# If you need to have sqlite first in your PATH run: +# export PATH="/usr/local/opt/sqlite/bin:$PATH" +# If you need to have ruby first in your PATH run: +# export PATH="/usr/local/opt/ruby/bin:$PATH" +# If you need to have openssl@1.1 first in your PATH run: +# export PATH="/usr/local/opt/openssl@1.1/bin:$PATH" +# If you need to have python@3.8 first in your PATH run: +# export PATH="/usr/local/opt/python@3.8/bin:$PATH" +# If you need to have ncurses first in your PATH run: +# export PATH="/usr/local/opt/ncurses/bin:$PATH" +# If you need to have icu4c first in your PATH run: +# export PATH="/usr/local/opt/icu4c/bin:$PATH" +# export PATH="/usr/local/opt/icu4c/sbin:$PATH" diff --git a/home/.vim/backups/.gitkeep b/home/.vim/backups/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/home/.vim/swaps/.gitkeep b/home/.vim/swaps/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/home/.vim/undo/.gitkeep b/home/.vim/undo/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/home/.vimrc b/home/.vimrc new file mode 100644 index 0000000..41ca258 --- /dev/null +++ b/home/.vimrc @@ -0,0 +1,167 @@ +" Don't Copy indent from current line +set noautoindent + +" Show the cursor position +set ruler + +" Show the filename in the window titlebar +set title + +" Make tabs as wide as two spaces +set tabstop=2 + +" Start scrolling one line before the horizontal window border +set scrolloff=1 + +" When a bracket is inserted, briefly jump to the matching one +set showmatch + +" Use the appropriate number of spaces to insert a +set expandtab + +" Ignore case in search patterns unless pattern contains upper case chars +set ignorecase +set smartcase + +" Long lines with wrap on display +set wrap + +" Use visual bell instead of beeping +set visualbell + +" Added from other users scripts +" Make Vim more useful +set nocompatible + +" Use the OS clipboard by default (on versions compiled with `+clipboard`) +set clipboard=unnamed + +" Enhance command-line completion +set wildmenu + +" Allow cursor keys in insert mode +set esckeys + +" Allow backspace in insert mode +set backspace=indent,eol,start + +" Optimize for fast terminal connections +set ttyfast + +" Use UTF-8 without BOM +set encoding=utf-8 nobomb + +" Change mapleader +let mapleader="," + +" Don’t add empty newlines at the end of files +set binary +set noeol + +" Centralize backups, swapfiles and undo history +set backupdir=~/.vim/backups +set directory=~/.vim/swaps +if exists("&undodir") + set undodir=~/.vim/undo +endif +" JFV Start + +" Enable syntax highlighting, JFV turned off colors for now +" off; stop highlighting completely +" manual; highlighting only for specific files +" on; enable but not switch it on automatically +syntax off + +" Don’t create backups when editing files in certain directories +set backupskip=/tmp/*,/private/tmp/* + +" Not sure about these lines, need to review +" " Respect modeline in files +" set modeline +" set modelines=4 +" " Enable per-directory .vimrc files and disable unsafe commands in them +" set exrc +" set secure +" " Enable line numbers +" set number +" " Highlight current line +" set cursorline +" " Show “invisible” characters +" set lcs=tab:▸\ ,trail:·,eol:¬,nbsp:_ +" set list +" " Highlight searches +" set hlsearch +" " Highlight dynamically as pattern is typed +" set incsearch +" " Always show status line +" set laststatus=2 +" " Enable mouse in all modes +" set mouse=a +" " Disable error bells +" set noerrorbells +" " Don’t reset cursor to start of line when moving around. +" set nostartofline +" " Don’t show the intro message when starting Vim +" set shortmess=atI +" " Show the current mode +" set showmode +" " Show the (partial) command as it’s being typed +" set showcmd +" " Use relative line numbers +" if exists("&relativenumber") +" set relativenumber +" au BufReadPost * set relativenumber +" endif +" " Strip trailing whitespace (,ss) +" function! StripWhitespace() +" let save_cursor = getpos(".") +" let old_query = getreg('/') +" :%s/\s\+$//e +" call setpos('.', save_cursor) +" call setreg('/', old_query) +" endfunction +" noremap ss :call StripWhitespace() +" " Save a file as root (,W) +" noremap W :w !sudo tee % > /dev/null + +" " Automatic commands +" if has("autocmd") +" " Enable file type detection +" filetype on +" " Treat .json files as .js +" autocmd BufNewFile,BufRead *.json setfiletype json syntax=javascript +" " Treat .md files as Markdown +" autocmd BufNewFile,BufRead *.md setlocal filetype=markdown +" endif + +" playing with colors +"set t_mr=^[[0;1;33;44m " reverse (invert) mode +":set t_me=^[[0;1;36m " normal mode (undoes t_mr and t_md) +":set t_me=[0;1;36m " normal mode (undoes t_mr and t_md) +":set t_mr=^[[0;1;33;44m " reverse (invert) mode +":set t_md=[1;33;41m " bold mode +":set t_se=[1;36;40m " standout end +":set t_so=[1;32;45m " standout mode +":set t_ue=[0;1;36m " underline end +":set t_us=[1;32m " underline mode start + + +" Unsure if this works, copied from Unix vimrc +" Enable editing of gzipped files +" read: set binary mode before reading the file +" uncompress text in buffer after reading +" write: compress file after writing +" append: uncompress file, append, compress file +autocmd BufReadPre,FileReadPre *.gz set bin +autocmd BufReadPost,FileReadPost *.gz '[,']!gunzip +autocmd BufReadPost,FileReadPost *.gz set nobin + +autocmd BufWritePost,FileWritePost *.gz !mv :r +autocmd BufWritePost,FileWritePost *.gz !gzip :r + +autocmd FileAppendPre *.gz !gunzip +autocmd FileAppendPre *.gz !mv :r +autocmd FileAppendPost *.gz !mv :r +autocmd FileAppendPost *.gz !gzip :r + +" imap   diff --git a/home/bin/git_diff_wrapper b/home/bin/git_diff_wrapper new file mode 100755 index 0000000..46d1c4a --- /dev/null +++ b/home/bin/git_diff_wrapper @@ -0,0 +1,8 @@ +#! /usr/bin/env bash + +if [ 1${2} == 1 ]; then + vim $1; + +else + vimdiff $1 $2; +fi \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..51a537c --- /dev/null +++ b/install.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +#################### +# This scripts copy .dotfiles from home/ dir into $HOME +# +# Intended use is for user to first clone dotfiles from github repo and then +# to run this script to copy dot files plus any other files of interest into +# users $HOME directory. +# +# First user mush have coppied files from repo using: +# git clone https://github.com/njim/dotfiles.git && cd dotfiles +# +# User must modify dot-src-file-list file for desired files, +# one file name per line, no comments or extra spaces/newlines. +# +# Script also Installs Homebrew Packages and configure macOS +# git autocompletion not yet enabled. +#################### + +# copy_exec function copies files from current directory "./home/." +# to $HOME dir. Then sources profile. +# If necessary, the rsync usage allows for files to be located on different server. + +function copy_exec() { + echo "Copy files into user's home"; + rsync --perms --executability --verbose \ + --files-from=dot-src-file-list ./home/. ~; + source ~/.bash_profile; +} + +# Beginning of script + +curdir=$CWD; + +# Give user chance to exit before scrip overwrites .files in $HOME. +if [ "$1" == "--force" -o "$1" == "-f" ]; then + copy_exec; +else + echo "dot-src-file-list contains:"; + cat dot-src-file-list; + read -p "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1; + echo ""; + if [[ $REPLY =~ ^[Yy]$ ]]; then + copy_exec; + else + echo "Exiting without change"; + exit 1; + fi; +fi; + +unset copy_exec; + +# Found this but not yet tried to use it. +# Download Git Auto-Completion +# curl "https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash" > ~/.git-completion.bash; + +# All scripts located in setup dir +cd ./setup; +echo $PWD + +# Run the Homebrew script +# Note that several places requires sudo password, not yet tried to run from sudo shell +./homebrew.sh | tee homebrew.log; + +# Need to un-comment one of these 2 entries +# Have not yet tried to run these scripts so both # for now +# Run macOS script +#./osx.sh | tee osx.log; +#./macos.sh | tee macos.log; + +cd $curdir; +unset curdir; diff --git a/setup/homebrew.sh b/setup/homebrew.sh old mode 100644 new mode 100755 index c6384f9..edcee0a --- a/setup/homebrew.sh +++ b/setup/homebrew.sh @@ -1,4 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash + +# Install command-line tools using Homebrew. # Install xcode-select if it is not currently available (homebrew dependency.) command -v xcode-select >/dev/null 2>&1 || { @@ -7,18 +9,26 @@ command -v xcode-select >/dev/null 2>&1 || { } # Install Homebrew if it is not currently available. -command -v brew >/dev/null 2>&1 || { +command -v xcode-selectcommand -v brew >/dev/null 2>&1 || { echo >&2 "Installing Homebrew"; \ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"; } -# Clean up all the things. +# Make sure we’re using the latest Homebrew. brew update + +# Upgrade any already-installed formulae. brew upgrade -brew prune + +# Remove stale lock files and outdated downloads brew cleanup + +# Check for any potiential problems brew doctor +# Save Homebrew’s installed location. +BREW_PREFIX=$(brew --prefix) + ############################################################################### # GNU Utilities to Replace BSD Versions # ############################################################################### @@ -28,43 +38,67 @@ brew doctor # The basic file, shell, and text manipulation utilities of the GNU OS. # https://www.gnu.org/software/coreutils/coreutils.html +# Must add PATH="$(brew --prefix)/opt/coreutils/libexec/gnubin:$PATH" brew install coreutils # Install GNU find, locate, updatedb, and xargs. # https://www.gnu.org/software/findutils/ -brew install findutils --with-default-names +# Must add PATH="$(brew --prefix)/opt/findutils/libexec/gnubin:$PATH" +brew install findutils # GNU sed has several differences and supports -i. # https://www.gnu.org/software/sed/ -brew install gnu-sed --with-default-names +# Must add PATH="$(brew --prefix)/opt/gnu-sed/libexec/gnubin:$PATH" +brew install gnu-sed # GNU grep is significantly faster and supports -P. # https://www.gnu.org/software/grep/ -brew install grep --with-default-names +# Must add PATH="$(brew --prefix)/opt/grep/libexec/gnubin:$PATH" +brew install grep + +# More utils looked interesting +# https://joeyh.name/code/moreutils/ +brew install moreutils + +# Install a modern version of Bash. +brew install bash +brew install bash-completion2 + +# Switch to using brew-installed bash as default shell +if ! fgrep -q "${BREW_PREFIX}/bin/bash" /etc/shells; then + echo "${BREW_PREFIX}/bin/bash" | sudo tee -a /etc/shells; + chsh -s "${BREW_PREFIX}/bin/bash"; +fi; + +# Unsure about these +# brew install wget --with-iri +# brew install gnupg ############################################################################### -# Updated Versions of Utilities on OSX # +# Updated Versions of Utilities on macOS # ############################################################################### # Replace VI with updated VIM build. # https://www.vim.org/ -brew install vim --with-override-system-vi +brew install vim # Replace native git with updated version. # https://git-scm.com/ brew install git +brew install tkdiff +k ############################################################################### # Install Packages # ############################################################################### -brew install wget brew install htop brew install links brew install imagemagick brew install cowsay -brew install zsh -brew install zsh-completions +# JFV: Not usig zsh +# brew install zsh +# brew install zsh-completions # Web Services and Tools brew install mysql @@ -123,3 +157,10 @@ brew cask install quicklook-json # Restart quick look. qlmanage -r + +############################################################################### +# Python and VS Code # +############################################################################### +# JFV added other items +brew install python3 +brew cask install visual-studio-code diff --git a/setup/macos.sh b/setup/macos.sh new file mode 100755 index 0000000..c9ea7af --- /dev/null +++ b/setup/macos.sh @@ -0,0 +1,259 @@ +#!/bin/bash + +# Setup machine to match preferred settings. +# See for inspiration: http://mths.be/osx +# and https://github.com/sapegin/dotfiles/blob/master/setup/osx.sh + +COMPUTERNAME='JimVomero' +LOCALHOSTNAME='jimvomero' + +# Ask for the administrator password upfront +sudo -v + +# Keep-alive: update existing `sudo` time stamp until this file has finished +while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & + +############################################################################### +# MAC OS Settings and UI # +############################################################################### + +# Set computer name (as done via System Preferences → Sharing.) +sudo scutil --set ComputerName $COMPUTERNAME +sudo scutil --set HostName $COMPUTERNAME +sudo scutil --set LocalHostName $LOCALHOSTNAME +sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string $LOCALHOSTNAME + +# Expand save panel by default. +defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true +defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true + +# Quit When Finished Printing removing it from the dock. +defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool YES + +# Disable the crash reporter. +defaults write com.apple.CrashReporter DialogType -string "none" + +# Disable the “Are you sure you want to open this application?” dialog. +defaults write com.apple.LaunchServices LSQuarantine -bool false + +# Check for software updates daily, not just once per week. +defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1 + +# Install System data files & security updates +defaults write com.apple.SoftwareUpdate CriticalUpdateInstall -int 1 + +# Turn off keyboard illumination when computer is not used for 5 minutes. +defaults write com.apple.BezelServices kDimTime -int 300 + +# Set the timezone; see `systemsetup -listtimezones` for other values. +systemsetup -settimezone "America/New_York" > /dev/null + +# Increase grid spacing for icons on the desktop and in other icon views. +/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:gridSpacing 40" ~/Library/Preferences/com.apple.finder.plist +/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:gridSpacing 40" ~/Library/Preferences/com.apple.finder.plist +/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:gridSpacing 40" ~/Library/Preferences/com.apple.finder.plist + +# Increase the size of icons on the desktop and in other icon views. +/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:iconSize 40" ~/Library/Preferences/com.apple.finder.plist +/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:iconSize 40" ~/Library/Preferences/com.apple.finder.plist +/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:iconSize 40" ~/Library/Preferences/com.apple.finder.plist + +# Reveal IP address, hostname, OS version when clicking the clock in the login window. +# Revert: defaults delete /Library/Preferences/com.apple.loginwindow AdminHostInfo +sudo defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName + +# Disable Resume system-wide. +# defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false +# Disable automatic termination of inactive apps. +# defaults write NSGlobalDomain NSDisableAutomaticTermination -bool true + +# Restart automatically if the computer freezes. +# systemsetup -setrestartfreeze on +# Never go into computer sleep mode. +# systemsetup -setcomputersleep Off > /dev/null + +############################################################################### +# Trackpad # +############################################################################### + +# Disable "natural" scrolling. +defaults write NSGlobalDomain com.apple.swipescrolldirection -bool false + +# Tap to click for this user and for the login screen. +defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true +defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1 +defaults write NSGlobalDomain com.apple.mouse.tapBehavior -int 1 + +# Tracking Speed (From 0 Slow to 3 Fast.) +defaults write NSGlobalDomain com.apple.trackpad.scaling -float 2.5 + +# Increase sound quality for Bluetooth headphones/headsets. +defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" -int 40 + +# Use scroll gesture with the Ctrl (^) modifier key to zoom. +defaults write com.apple.universalaccess closeViewScrollWheelToggle -bool true +defaults write com.apple.universalaccess HIDScrollZoomModifierMask -int 262144 + +############################################################################### +# Dock & hot corners # +############################################################################### + +# Set the icon size of Dock items to 60 pixels +defaults write com.apple.dock tilesize -int 30 + +# Enable spring loading for all Dock items +defaults write com.apple.dock enable-spring-load-actions-on-all-items -bool true + +# Speed up Mission Control animations +defaults write com.apple.dock expose-animation-duration -float 0.1 + +# Group windows by application in Mission Control +defaults write com.apple.dock expose-group-by-app -bool true + +# Automatically hide and show the Dock +defaults write com.apple.dock autohide -bool true + +# Speed up animation speed of hiding Dock. +defaults write com.apple.dock autohide-delay -float 0 + +# Hot corners +# Top right screen corner → Mission Control +defaults write com.apple.dock wvous-tr-corner -int 2 +defaults write com.apple.dock wvous-tr-modifier -int 0 +# Bottom left screen corner → Desktop +defaults write com.apple.dock wvous-bl-corner -int 4 +defaults write com.apple.dock wvous-bl-modifier -int 0 + +############################################################################### +# Finder # +############################################################################### + +# Finder: show hidden files by default +defaults write com.apple.finder AppleShowAllFiles -bool true + +# Finder: show all filename extensions +defaults write NSGlobalDomain AppleShowAllExtensions -bool true + +# Finder: hide path bar +defaults write com.apple.finder ShowPathbar -boolean false + +# Keep folders on top when sorting by name +defaults write com.apple.finder _FXSortFoldersFirst -bool true + +# When performing a search, search the current folder by default +defaults write com.apple.finder FXDefaultSearchScope -string "SCcf" + +# Disable the warning when changing a file extension +defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false + +# Avoid creating .DS_Store files on network volumes +defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true + +# Show the ~/Library folder +chflags nohidden ~/Library + +# Show the /Volumes folder +sudo chflags nohidden /Volumes + +############################################################################### +# Screenshots Tool # +############################################################################### + +# Save screenshots to the desktop +defaults write com.apple.screencapture location -string "$HOME/Desktop" + +# Save screenshots in PNG format (other options: BMP, GIF, JPG, PDF, TIFF) +defaults write com.apple.screencapture type -string "png" + +# Disable shadow in screenshots +defaults write com.apple.screencapture disable-shadow -bool true + +############################################################################### +# Power # +############################################################################### + +# Battery: Computer sleep: 10 min +sudo pmset -b sleep 10 + +# Battery: Display sleep: 5 min +sudo pmset -b displaysleep 5 + +# Battery: Put the hard disk(s) to sleep when possible: 10 min +sudo pmset -b disksleep 10 + +# Battery: Slightly dim the display when using this power source +sudo pmset -b lessbright 1 + +# Battery: Automatically reduce brightness before display goes to sleep +sudo pmset -b halfdim 1 + +# Power Adapter: Computer sleep: 30 min +sudo pmset -c sleep 30 + +# Power Adapter: Display sleep: 10 min +sudo mset -c displaysleep 10 + +# Power Adapter: Put the hard disk(s) to sleep when possible: 10 min +sudo pmset -c disksleep 10 + +# Power Adapter: Wake for network access +sudo pmset -c womp 0 + +# Power Adapter: Automatically reduce brightness before display goes to sleep +sudo pmset -c halfdim 1 + +# Power Adapter: Start up automatically after a power failure +sudo pmset -c autorestart 1 + +############################################################################### +# Safari & WebKit # +############################################################################### + +# Set Safari’s home page to `about:blank` for faster loading +defaults write com.apple.Safari HomePage -string "about:blank" + +# Prevent Safari from opening ‘safe’ files automatically after downloading +defaults write com.apple.Safari AutoOpenSafeDownloads -bool false + +# Disable Safari’s thumbnail cache for History and Top Sites +defaults write com.apple.Safari DebugSnapshotsUpdatePolicy -int 2 + +# Enable Safari’s debug menu +defaults write com.apple.Safari IncludeInternalDebugMenu -bool true + +# Make Safari’s search banners default to Contains instead of Starts With +defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false + +# Enable the Develop menu and the Web Inspector in Safari +defaults write com.apple.Safari IncludeDevelopMenu -bool true +defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true +defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled -bool true + +# Add a context menu item for showing the Web Inspector in web views +defaults write NSGlobalDomain WebKitDeveloperExtras -bool true + +# Enable the WebKit Developer Tools in the Mac App Store +defaults write com.apple.appstore WebKitDeveloperExtras -bool true + +############################################################################### +# Photos # +############################################################################### + +# Prevent Photos from opening automatically when devices are plugged in +defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool true + +############################################################################### +# Terminal # +############################################################################### + +# Looking for a good set of settings and themes to apply to default terminal. + +############################################################################### +# Kill affected applications # +############################################################################### + +for app in "Dashboard" "Dock" "Finder" "Mail" "Safari" "SystemUIServer" \ + "Terminal" "iTunes" "NotificationCenter"; do + killall "$app" > /dev/null 2>&1 +done +echo "Done. Some of these changes require a logout/restart to take effect." diff --git a/setup/osx.sh b/setup/osx.sh old mode 100644 new mode 100755 index 0b33f3b..c9ea7af --- a/setup/osx.sh +++ b/setup/osx.sh @@ -25,6 +25,7 @@ sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.serve # Expand save panel by default. defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true +defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true # Quit When Finished Printing removing it from the dock. defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool YES