diff --git a/.aliases b/.aliases deleted file mode 100644 index 7950f20..0000000 --- a/.aliases +++ /dev/null @@ -1,63 +0,0 @@ -# ---------------------------------------------------------------------- -# | Navigation | -# ---------------------------------------------------------------------- - -alias ..='cd ..' -alias ...='cd ../..' -alias ....='cd ../../..' -alias cd..='cd ..' -alias s='cd ~/Sites' -alias c='cd ~/Code' - -# ---------------------------------------------------------------------- -# | Shorter Commands | -# ---------------------------------------------------------------------- - -alias g='git' -alias ll='ls -l' -alias cask='brew cask' - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Detect which `ls` flavor is in use -if ls --color > /dev/null 2>&1; then # GNU `ls` - colorflag="--color" -else # OS X `ls` - colorflag="-G" -fi - -# List all files colorized in long format -alias l="ls -lF ${colorflag}" - -# List all files colorized in long format, including dot files -alias la="ls -laF ${colorflag}" - -# List only directories -alias lsd="ls -lF ${colorflag} | grep --color=never '^d'" - -# Always use color output for `ls` -alias ls="command ls ${colorflag}" -export LS_COLORS='no=00:fi=00:di=01;34: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:' - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Hide/Show files - -# Hide/Show desktop icons -alias hide-desktop-icons='defaults write com.apple.finder CreateDesktop -bool false && killall Finder' -alias show-desktop-icons='defaults write com.apple.finder CreateDesktop -bool true && killall Finder' - -# Hide/Show hidden files in Finder -alias hide-hidden-files='defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder' -alias show-hidden-files='defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder' - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Recursively delete `.DS_Store` files -alias cleanup="find . -type f -name '*.DS_Store' -ls -delete" - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Get OS X Software Updates, and update installed Ruby gems, Homebrew, npm, and their installed packages -alias update='sudo softwareupdate -i -a; brew update; brew upgrade --all; brew cleanup; npm update -g; gem update' - diff --git a/.bash_profile b/.bash_profile deleted file mode 100644 index 15070da..0000000 --- a/.bash_profile +++ /dev/null @@ -1,12 +0,0 @@ -# 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 ~/.{bash_prompt,exports,aliases,functions}; do - [ -r "$file" ] && [ -f "$file" ] && source "$file"; -done; -unset file; - -[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* diff --git a/.bash_prompt b/.bash_prompt deleted file mode 100644 index 13a026f..0000000 --- a/.bash_prompt +++ /dev/null @@ -1,120 +0,0 @@ -# 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. - if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then - - # check if the current directory is in .git before running git checks - if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]; then - - # Ensure the index is up to date. - git update-index --really-refresh -q &>/dev/null; - - # 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; - - # Get the short symbolic ref. - # If HEAD isn’t a symbolic ref, get the short SHA for the latest commit - # Otherwise, just give up. - branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \ - git rev-parse --short HEAD 2> /dev/null || \ - echo '(unknown)')"; - - [ -n "${s}" ] && s=" [${s}]"; - - echo -e "${1}${branchName}${blue}${s}"; - else - return; - fi; -} - -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 33); - cyan=$(tput setaf 37); - green=$(tput setaf 64); - orange=$(tput setaf 166); - purple=$(tput setaf 125); - red=$(tput setaf 124); - violet=$(tput setaf 61); - white=$(tput setaf 15); - yellow=$(tput setaf 136); -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 to the current working directory. -PS1="\[\033]0;\w\007\]"; -PS1+="\[${bold}\]\n"; # newline -PS1+="\[${userStyle}\]\u"; # username -PS1+="\[${white}\] at "; -PS1+="\[${hostStyle}\]\h"; # host -PS1+="\[${white}\] in "; -PS1+="\[${green}\]\w"; # working directory -PS1+="\$(prompt_git \"${white} on ${violet}\")"; # Git repository details -PS1+="\n"; -PS1+="\[${white}\]\$ \[${reset}\]"; # `$` (and reset color) -export PS1; - -PS2="\[${yellow}\]→ \[${reset}\]"; -export PS2; diff --git a/.bashrc b/.bashrc deleted file mode 100644 index b0f2331..0000000 --- a/.bashrc +++ /dev/null @@ -1,2 +0,0 @@ -[ -n "$PS1" ] && source ~/.bash_profile; -export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 5c0d140..0000000 --- a/.editorconfig +++ /dev/null @@ -1,13 +0,0 @@ -# editorconfig.org - -root = true - -[*] -indent_style = space -indent_size = 4 -charset = utf-8 -insert_final_newline = true -trim_trailing_whitespace = true - -[*.md] -trim_trailing_whitespace = false diff --git a/.exports b/.exports deleted file mode 100644 index b54e82b..0000000 --- a/.exports +++ /dev/null @@ -1,24 +0,0 @@ -# Shell Variables -# http://linux.die.net/man/1/bash - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Make vim the default editor -export EDITOR='vim' - -# Ignore commands that start with spaces and duplicates -export HISTCONTROL=ignoreboth - -# Increase the maximum number of lines contained in the -# history file (default value is 500) -export HISTFILESIZE=10000 - -# Don't add certain commands to the history file -export HISTIGNORE='&:[bf]g:c:clear:history:exit:q:pwd:* --help' - -# Increase the maximum number of commands recorded in the -# command history (default value is 500) -export HISTSIZE=10000 - -# Don't clear the screen after quitting a man page -export MANPAGER='less -X' diff --git a/.functions b/.functions deleted file mode 100644 index 82d0478..0000000 --- a/.functions +++ /dev/null @@ -1,19 +0,0 @@ -# ---------------------------------------------------------------------- -# | File System | -# ---------------------------------------------------------------------- - -# Delete files that match a certain pattern from the current directory - -delete-files() { - local q="${1:-*.DS_Store}" - find . -type f -name "$q" -ls -delete -} - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Create new directories and enter the first one - -mkd() { - [ -n "$*" ] && mkdir -p "$@" && cd "$@" - # └─ make parent directories if needed -} \ No newline at end of file diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 176a458..0000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* text=auto diff --git a/.gitconfig b/.gitconfig deleted file mode 100644 index 2325363..0000000 --- a/.gitconfig +++ /dev/null @@ -1,42 +0,0 @@ -[alias] - c = commit - d = diff - g = log --graph --pretty=custom # Show custom graph - l = log --pretty=custom # Show custom log - s = status - -[color "branch"] - current = green bold - local = green - remote = yellow - -[color "diff"] - frag = magenta - meta = yellow - new = green - old = red - -[color "status"] - added = green reverse - changed = yellow reverse - untracked = red reverse - -[core] - abbrev = 12 - attributesfile = ~/.gitattributes - autocrlf = input - editor = vim - excludesfile = ~/.gitignore - -[pretty] - custom = "%C(magenta)%h%C(red)%d %C(yellow)%ar %C(green)%s %C(yellow)(%an)" - # │ │ │ │ └─ author name - # │ │ │ └─ message - # │ │ └─ date (relative) - # │ └─ decorations (branch, heads or tags) - # └─ hash (abbreviated) - -[push] - # Make `git push` automatically push relevant - # annotated tags when pushing branches out - followTags = true diff --git a/.hushlogin b/.hushlogin deleted file mode 100644 index e6143df..0000000 --- a/.hushlogin +++ /dev/null @@ -1,4 +0,0 @@ -# The mere presence of this file in the home directory disables the system -# copyright notice, the date and time of the last login, the message of the -# day as well as other information that may otherwise appear on login. -# See `man login`. \ No newline at end of file diff --git a/README.md b/README.md index a931102..83a8001 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,22 @@ I maintain this repo as *my* dotfiles. +## Installation + +```sh +$ cd ~/Code +$ git clone git@github.com:antleblanc/dotfiles.git +``` + +You can now create symbolic links for each of those files. + +```sh +$ cd ~ +$ ln -s ~/Code/dotfiles/bashrc .bashrc +$ ln -s ~/Code/dotfiles/bash_profile .bash_profile +$ … +``` + ## Resources - [Mathias Bynens](https://github.com/mathiasbynens) and his [dotfiles repository](https://github.com/mathiasbynens/dotfiles). diff --git a/bash.local b/bash.local new file mode 100644 index 0000000..0a4c27c --- /dev/null +++ b/bash.local @@ -0,0 +1,24 @@ +#!/bin/bash + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Set local aliases + +alias s="cd ~/Sites" +alias c="cd ~/Code" +alias cask="brew cask" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Set PATH additions + +PATH="$HOME/bin:$PATH" + +export PATH + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Node version manager. + +export NVM_DIR="/Users/antleblanc/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm diff --git a/bash_aliases b/bash_aliases new file mode 100644 index 0000000..69f2dd5 --- /dev/null +++ b/bash_aliases @@ -0,0 +1,101 @@ +#!/bin/bash + +alias ..="cd .." +alias ...="cd ../.." +alias ....="cd ../../.." +alias cd..="cd .." + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +alias :q="exit" +alias c="clear" +alias ch="history -c && > ~/.bash_history" +alias e="vim --" +alias g="git" +alias ip="dig +short myip.opendns.com @resolver1.opendns.com" +alias ll="ls -l" +alias m="man" +alias map="xargs -n1" +alias n="npm" +alias path='printf "%b\n" "${PATH//:/\\n}"' +alias q="exit" +alias rm="rm -rf --" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Lock screen. + +alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Shorter commands for `Homebrew`. + +alias brewd="brew doctor" +alias brewi="brew install" +alias brewr="brew uninstall" +alias brews="brew search" +alias brewu="brew update \ + && brew upgrade \ + && brew cleanup \ + && brew cask cleanup" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Clear DNS cache. + +alias clear-dns-cache="sudo dscacheutil -flushcache; \ + sudo killall -HUP mDNSResponder" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Empty the trash, the main HDD and on all mounted volumes, +# and clear Apple’s system logs to improve shell startup speed. + +alias empty-trash="sudo rm -frv /Volumes/*/.Trashes; \ + sudo rm -frv ~/.Trash; \ + sudo rm -frv /private/var/log/asl/*.asl; \ + sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Hide/Show desktop icons. + +alias hide-desktop-icons="defaults write com.apple.finder CreateDesktop -bool false \ + && killall Finder" + +alias show-desktop-icons="defaults write com.apple.finder CreateDesktop -bool true \ + && killall Finder" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Hide/Show hidden files in Finder. + +alias hide-hidden-files="defaults write com.apple.finder AppleShowAllFiles -bool false \ + && killall Finder" + +alias show-hidden-files="defaults write com.apple.finder AppleShowAllFiles -bool true \ + && killall Finder" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Get local IP. + +alias local-ip="ipconfig getifaddr en1" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Open from the terminal. + +alias o="open" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Update applications and CLTs. + +alias u="sudo softwareupdate --install --all \ + && brew update \ + && brew upgrade \ + && brew cleanup \ + && npm install -g npm \ + && npm update -g" diff --git a/bash_autocomplete b/bash_autocomplete new file mode 100644 index 0000000..4369631 --- /dev/null +++ b/bash_autocomplete @@ -0,0 +1,20 @@ +#!/bin/bash + +# [!] Do not rename this file to `bash_completion` +# as it will create an infinite loop! + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +declare -r BASH_COMPLETION_PATH="$(brew --prefix 2> /dev/null)/share/bash-completion/bash_completion" + +if [ -f "$BASH_COMPLETION_PATH" ]; then + + # Use the latest `bash-completion`. + + . "$BASH_COMPLETION_PATH" + + # Make Bash complete the `g` alias just like it does `git`. + + complete -o default -o nospace -F _git g + +fi diff --git a/bash_exports b/bash_exports new file mode 100644 index 0000000..a8ba622 --- /dev/null +++ b/bash_exports @@ -0,0 +1,78 @@ +#!/bin/bash + +# Bash Variables. +# https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Make `vim` the default editor. + +export EDITOR="vim" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Ignore commands that start with spaces and duplicates. + +export HISTCONTROL=ignoreboth + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Increase the maximum number of lines of history +# persisted in the history file (default value is 500). + +export HISTFILESIZE=10000 + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Don't add certain commands to the history file. + +export HISTIGNORE="&:[bf]g:c:clear:history:exit:q:pwd:* --help" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Increase the maximum number of commands recorded +# in the command history (default value is 500). + +export HISTSIZE=10000 + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Prefer US English and use UTF-8 encoding. + +export LANG="en_US" +export LC_ALL="en_US.UTF-8" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Use custom `less` colors for `man` pages. + +export LESS_TERMCAP_md="$(tput bold 2> /dev/null; tput setaf 2 2> /dev/null)" +export LESS_TERMCAP_me="$(tput sgr0 2> /dev/null)" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Don't clear the screen after quitting a `man` page. + +export MANPAGER="less -X" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Increase the maximum number of lines of history persisted +# in the `Node` REPL history file (default value is 1000). +# +# https://github.com/nodejs/node/blob/c948877688ff2b6a37f2c88724b656aae495c7b2/doc/api/repl.md#persistent-history + +export NODE_REPL_HISTORY_SIZE=10000 + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Make new shells get the history lines from all previous +# shells instead of the default "last window closed" history. + +export PROMPT_COMMAND="history -a; $PROMPT_COMMAND" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Make Python use UTF-8 encoding for output to stdin/stdout/stderr. + +export PYTHONIOENCODING="UTF-8" diff --git a/bash_functions b/bash_functions new file mode 100644 index 0000000..e4283fe --- /dev/null +++ b/bash_functions @@ -0,0 +1,144 @@ +#!/bin/bash + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Create data URI from a file. + +datauri() { + + local mimeType="" + + if [ -f "$1" ]; then + mimeType=$(file -b --mime-type "$1") + # └─ do not prepend the filename to the output + + if [[ $mimeType == text/* ]]; then + mimeType="$mimeType;charset=utf-8" + fi + + printf "data:%s;base64,%s" \ + "$mimeType" \ + "$(openssl base64 -in "$1" | tr -d "\n")" + else + printf "%s is not a file.\n" "$1" + fi + +} + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Delete files that match a certain pattern from the current directory. + +delete-files() { + local q="${1:-*.DS_Store}" + find . -type f -name "$q" -ls -delete +} + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Get gzip information (gzipped file size + reduction size). + +gz() { + + declare -i gzippedSize=0 + declare -i originalSize=0 + + if [ -f "$1" ]; then + if [ -s "$1" ]; then + + originalSize=$( wc -c < "$1" ) + printf "\n original size: %12s\n" "$(hrfs "$originalSize")" + + gzippedSize=$( gzip -c "$1" | wc -c ) + printf " gzipped size: %12s\n" "$(hrfs "$gzippedSize")" + + printf " ─────────────────────────────\n" + printf " reduction: %12s [%s%%]\n\n" \ + "$( hrfs $((originalSize - gzippedSize)) )" \ + "$( printf "%s" "$originalSize $gzippedSize" | \ + awk '{ printf "%.1f", 100 - $2 * 100 / $1 }' | \ + sed -e "s/0*$//;s/\.$//" )" + # └─ remove tailing zeros + + else + printf "\"%s\" is empty.\n" "$1" + fi + else + printf "\"%s\" is not a file.\n" "$1" + fi + +} + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Human readable file size +# (because `du -h` doesn't cut it for me). + +hrfs() { + + printf "%s" "$1" | + awk '{ + i = 1; + split("B KB MB GB TB PB EB ZB YB WTFB", v); + value = $1; + + # confirm that the input is a number + if ( value + .0 == value ) { + + while ( value >= 1024 ) { + value/=1024; + i++; + } + + if ( value == int(value) ) { + printf "%d %s", value, v[i] + } else { + printf "%.1f %s", value, v[i] + } + + } + }' | + sed -e ":l" \ + -e "s/\([0-9]\)\([0-9]\{3\}\)/\1,\2/; t l" + # └─ add thousands separator + # (changes "1023.2 KB" to "1,023.2 KB") +} + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Create new directories and enter the first one. + +mkd() { + if [ -n "$*" ]; then + + mkdir -p "$@" + # └─ make parent directories if needed + + cd "$@" \ + || exit 1 + + fi +} + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Search history. + +qh() { + # ┌─ enable colors for pipe + # │ ("--color=auto" enables colors only if + # │ the output is in the terminal) + grep --color=always "$*" "$HISTFILE" | less -RX + # display ANSI color escape sequences in raw form ─┘│ + # don't clear the screen after quitting less ─┘ +} + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Search for text within the current directory. + +qt() { + grep -ir --color=always "$*" . | less -RX + # │└─ search all files under each directory, recursively + # └─ ignore case +} diff --git a/bash_logout b/bash_logout new file mode 100644 index 0000000..dba1c71 --- /dev/null +++ b/bash_logout @@ -0,0 +1,6 @@ +#!/bin/bash + +# Clear console on exit. + +[ "$SHLVL" == 1 ] \ + && clear &> /dev/null diff --git a/bash_options b/bash_options new file mode 100644 index 0000000..af203c1 --- /dev/null +++ b/bash_options @@ -0,0 +1,61 @@ +#!/bin/bash + +# Bash options. +# https://www.gnu.org/software/bash/manual/bashref.html#The-Shopt-Builtin + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Automatically prepend `cd` to directory names. + +# shopt -s autocd + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Autocorrect typos in path names when using the `cd` command. + +shopt -s cdspell + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Check the window size after each command and, if necessary, update +# the values of `LINES` and `COLUMNS`. + +shopt -s checkwinsize + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Save all lines of a multiple-line command in the same history entry. + +shopt -s cmdhist + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Include filenames beginning with a "." in the filename expansion. + +shopt -s dotglob + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Use extended pattern matching features. + +shopt -s extglob + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Append to the history file rather then overwriting it. + +shopt -s histappend + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Do not attempt to search the PATH for possible completions when +# completion is attempted on an empty line. + +shopt -s no_empty_cmd_completion + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Match filenames in a case-insensitive fashion when performing +# filename expansion. + +shopt -s nocaseglob diff --git a/bash_profile b/bash_profile new file mode 100644 index 0000000..1a7f8e7 --- /dev/null +++ b/bash_profile @@ -0,0 +1,50 @@ +#!/bin/bash + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +source_bash_files() { + + declare -r CURRENT_DIRECTORY="$(pwd)" + + declare -r -a FILES_TO_SOURCE=( + "bash_aliases" + "bash_autocomplete" + "bash_exports" + "bash_functions" + "bash_options" + "bash_prompt" + "bash.local" # For local settings that should + # not be under version control. + ) + + local file="" + local i="" + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + for i in ${!FILES_TO_SOURCE[*]}; do + + file="$HOME/.${FILES_TO_SOURCE[$i]}" + + [ -r "$file" ] \ + && . "$file" + + done + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + cd "$CURRENT_DIRECTORY" + +} + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +source_bash_files +unset -f source_bash_files + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Clear system messages (system copyright notice, the date +# and time of the last login, the message of the day, etc.). + +clear diff --git a/bash_prompt b/bash_prompt new file mode 100644 index 0000000..bbe3ea8 --- /dev/null +++ b/bash_prompt @@ -0,0 +1,241 @@ +#!/bin/bash + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +enable_color_support() { + + if [[ $COLORTERM == gnome-* && $TERM == xterm ]] \ + && infocmp gnome-256color &> /dev/null; then + export TERM="gnome-256color" + elif infocmp xterm-256color &> /dev/null; then + export TERM="xterm-256color" + fi + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Set LSCOLORS (FreeBSD / macOS). + # + # * `ls` displays colors if the `-G` option is passed or if + # the `CLICOLOR` environment variable is set. + # + # * The actual colors are configured through the `LSCOLORS` + # environment variable (built-in defaults are used if this + # variable is not set). + + LSCOLORS="" + + LSCOLORS+="gx" # Directory + LSCOLORS+="fx" # Symbolic link + LSCOLORS+="cx" # Socket + LSCOLORS+="dx" # Pipe + LSCOLORS+="cx" # Executable + LSCOLORS+="eg" # Block special + LSCOLORS+="ed" # Character special + LSCOLORS+="ab" # Executable with setuid bit set + LSCOLORS+="ag" # Executable with setgid bit set + LSCOLORS+="cc" # Directory writable to others, with sticky bit + LSCOLORS+="bd" # Directory writable to others, without sticky bit + + export LSCOLORS + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Enable color support. + + alias ls="ls -G" + +} + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# [!] Don't break this function into smaller, more specialized ones +# as you will only pollute the global space even more. This function +# cannot be unset because it's called every time the prompt string +# is shown. + +get_git_repository_details() { + + local branchName="" + local tmp="" + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Check if the current directory is in a Git repository. + + ! git rev-parse &>/dev/null \ + && return + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Check if in `.git/` directory (some of the following + # checks don't make sense/won't work in the `.git` directory). + + [ "$(git rev-parse --is-inside-git-dir)" == "true" ] \ + && return + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Check for uncommitted changes in the index. + + if ! git diff --quiet --ignore-submodules --cached; then + tmp="$tmp+"; + fi + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Check for unstaged changes. + + if ! git diff-files --quiet --ignore-submodules --; then + tmp="$tmp!"; + fi + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Check for untracked files. + + if [ -n "$(git ls-files --others --exclude-standard)" ]; then + tmp="$tmp?"; + fi + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Check for stashed files. + + if git rev-parse --verify refs/stash &>/dev/null; then + tmp="$tmp$"; + fi + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + [ -n "$tmp" ] \ + && tmp=" [$tmp]" + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + branchName="$( printf "%s" "$( git rev-parse --abbrev-ref HEAD 2> /dev/null \ + || git rev-parse --short HEAD 2> /dev/null \ + || printf " (unknown)" )" | tr -d "\n" )" + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + printf "%s" "$1$branchName$tmp" + +} + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +set_prompts() { + + local bold=$(tput bold 2> /dev/null) + local reset=$(tput sgr0 2> /dev/null) + + local cyan="" + local green="" + local orange="" + local white="" + local yellow="" + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + if [ "$(tput colors 2> /dev/null || printf "0")" -ge 256 ]; then + + # Solarized colors. + # https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized#the-values + + cyan=$(tput setaf 37) + green=$(tput setaf 64) + orange=$(tput setaf 166) + white=$(tput setaf 15) + yellow=$(tput setaf 136) + + fi + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Prompt Statement variables. + # http://ss64.com/bash/syntax-prompt.html + + # ------------------------------------------------------------------ + # | PS1 - Default interactive prompt | + # ------------------------------------------------------------------ + + PS1="\[\033]0;\W\007\]" # Terminal title (set to the + # current working directory) + + PS1+="$reset$bold" + PS1+="$orange\u" # Username + PS1+="$white@" + PS1+="$yellow\h" # Host + PS1+="$white: " + PS1+="$green\w" # Working directory + PS1+="\$(get_git_repository_details \"$white on $cyan\")" + PS1+="\n" + PS1+="\[$reset\]\[$white\]$ \[$reset\]" + + export PS1 + + # ------------------------------------------------------------------ + # | PS2 - Continuation interactive prompt | + # ------------------------------------------------------------------ + + PS2="⚡ " + + export PS2 + + # ------------------------------------------------------------------ + # | PS4 - Debug prompt | + # ------------------------------------------------------------------ + + # e.g: + # + # The GNU `date` command has the `%N` interpreted sequence while + # other implementations don't (on macOS `gdate` can be used instead + # of the native `date` if the `coreutils` package has been installed). + # + # local dateCmd="" + # + # if [ "$(date +%N)" != "N" ] || \ + # [ ! -x "$(command -v "gdate")" ]; then + # dateCmd="date +%s.%N" + # else + # dateCmd="gdate +%s.%N" + # fi + # + # PS4="+$( tput cr && tput cuf 6 && + # printf "$yellow %s $green%6s $reset" "$($dateCmd)" "[$LINENO]" )" + # + # PS4 output: + # + # ++ 1357074705.875970000 [123] '[' 1 == 0 ']' + # └──┬─┘└────┬───┘ └───┬───┘ └──┬─┘ └──────┬─────┘ + # │ │ │ │ │ + # │ │ │ │ └─ command + # │ │ │ └─ line number + # │ │ └─ nanoseconds + # │ └─ seconds since 1970-01-01 00:00:00 UTC + # └─ depth-level of the subshell + + PS4="+$( tput cr 2> /dev/null; + tput cuf 6 2> /dev/null; + printf "%s" "$reset" )" + + export PS4 + +} + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +main() { + enable_color_support + set_prompts +} + +main + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Cleanup. + +unset -f enable_color_support +unset -f main +unset -f set_prompts diff --git a/bashrc b/bashrc new file mode 100644 index 0000000..4625915 --- /dev/null +++ b/bashrc @@ -0,0 +1,4 @@ +#!/bin/bash + +[ -n "$PS1" ] \ + && . ~/.bash_profile diff --git a/curlrc b/curlrc new file mode 100644 index 0000000..ffb63ba --- /dev/null +++ b/curlrc @@ -0,0 +1,32 @@ +# cURL configuration options. +# https://curl.haxx.se/docs/manpage.html + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Limit the time (in seconds) the connection is allowed to take. + +connect-timeout = 60 + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Follow HTTP redirects. + +location + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Display progress as a simple progress bar. + +progress-bar + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Show error messages. + +show-error + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# Send a fake UA string for the HTTP servers that sniff it. + +user-agent = "Mozilla/5.0 Gecko" diff --git a/gitattributes b/gitattributes new file mode 100644 index 0000000..052579e --- /dev/null +++ b/gitattributes @@ -0,0 +1,4 @@ +# Automatically normalize line endings for all text-based files. +# https://git-scm.com/docs/gitattributes#_end_of_line_conversion +# +* text=auto diff --git a/gitconfig b/gitconfig new file mode 100644 index 0000000..d139e91 --- /dev/null +++ b/gitconfig @@ -0,0 +1,151 @@ +[alias] + + a = commit --amend + br = branch + c = commit + ca = !git add -A && git commit # Commit all changes. + co = checkout + cp = cherry-pick + d = diff + dc = diff --cached + g = log --graph --pretty=custom # Show custom graph. + l = log --pretty=custom # Show custom log. + lc = shortlog --summary --numbered # List contributors. + p = push + r = rebase + rlc = reset --hard HEAD~1 # Remove last commit. + s = status + ulc = reset --soft HEAD~1 # Undo last commit. + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Find commits by source code. + + cc = "!f() { \ + git log --pretty=custom --decorate --date=short -S\"$1\"; \ + }; f" + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Find commits by commit message. + + cm = "!f() { \ + git log --pretty=custom --decorate --date=short --grep=\"$1\"; \ + }; f" + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Credit an author on the latest commit. + + credit = "!f() { \ + if [ -n \"$1\" ] && [ -n \"$2\" ]; then \ + git commit --amend --author \"$1 <$2>\" -C HEAD; \ + fi \ + }; f" + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # List remote branches. + + lrb = "!f() { \ + remote="${1:-origin}"; \ + git ls-remote --heads "$remote"; \ + }; f" + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Merge GitHub pull request on top of the current branch or, + # if a branch name is specified, on top of the specified branch. + + mpr = "!f() { \ + declare currentBranch=\"$(git symbolic-ref --short HEAD)\"; \ + declare branch=\"${2:-$currentBranch}\"; \ + if [ $(printf \"%s\" \"$1\" | grep '^[0-9]\\+$' > /dev/null; printf $?) -eq 0 ]; then \ + git fetch origin refs/pull/$1/head:pr/$1 && \ + git checkout -B $branch && \ + git rebase $branch pr/$1 && \ + git checkout -B $branch && \ + git merge pr/$1 && \ + git branch -D pr/$1 && \ + git commit --amend -m \"$(git log -1 --pretty=%B)\n\nClose #$1\"; \ + fi \ + }; f" + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Remove the tag with the specified tag name if + # exists and tag the latest commit with that name. + + retag = "!f() { \ + git tag -d "$1" &> /dev/null; \ + git tag $1; \ + }; f" + + +[color "branch"] + + current = green bold + local = green + remote = yellow + +[color "diff"] + + frag = magenta + meta = yellow + new = green + old = red + +[color "status"] + + added = green reverse + changed = yellow reverse + untracked = red reverse + +[core] + + abbrev = 12 + attributesfile = ~/.gitattributes + autocrlf = input + editor = vim + excludesfile = ~/.gitignore + +[diff "bin"] + + # Use `hexdump` to diff binary files. + + textconv = hexdump -v -C + +[pretty] + + custom = "%C(magenta)%h%C(red)%d %C(yellow)%ar %C(green)%s %C(yellow)(%an)" + # │ │ │ │ └─ author name + # │ │ │ └─ message + # │ │ └─ date (relative) + # │ └─ decorations (branch, heads or tags) + # └─ hash (abbreviated) + + +[push] + + # Make `git push` automatically push relevant + # annotated tags when pushing branches out. + + followTags = true + +[user] + + # Don't guess the user's identity. + # https://github.com/git/git/blob/90f7b16b3adc78d4bbabbd426fb69aa78c714f71/Documentation/config.txt#L2847-L2855 + + useConfigOnly = true + +[include] + + # Load local configs. + # https://git-scm.com/docs/git-config#_includes + # + # [!] The following needs to remain at the end of this file in + # order to allow any of the above configs to be overwritten + # by the local ones + + path = ~/.gitconfig.local diff --git a/gitconfig.local b/gitconfig.local new file mode 100644 index 0000000..238da94 --- /dev/null +++ b/gitconfig.local @@ -0,0 +1,13 @@ +[commit] + + # Sign commits using GPG. + # https://help.github.com/articles/signing-commits-using-gpg/ + + gpgsign = true + + +[user] + + name = Antoine Leblanc + email = antoine@example.com + signingkey = XXXXXXXX diff --git a/.gitignore b/gitignore similarity index 91% rename from .gitignore rename to gitignore index 1bb9bf6..689853f 100644 --- a/.gitignore +++ b/gitignore @@ -12,13 +12,14 @@ # | Miscellaneous | # ---------------------------------------------------------------------- -# npm log file -# https://docs.npmjs.com/misc/config#loglevel +# Node.js & npm. + +node_modules npm-debug.log # ---------------------------------------------------------------------- -# | OS X | +# | macOS | # ---------------------------------------------------------------------- ._* @@ -30,6 +31,7 @@ npm-debug.log .Trashes Icon + # ---------------------------------------------------------------------- # | Vim | # ----------------------------------------------------------------------