From a29e678959ba4dcfba26c2f3320568fb9f7ec404 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 12 Feb 2018 16:31:40 +0000 Subject: [PATCH] Update from other laptop --- bash_aliases | 92 +++-- bash_profile | 5 - bashrc | 82 ++-- git-completion.bash | 956 +++++++++++++++++++++++++++++++++++--------- gitconfig | 7 - install.conf.yaml | 4 +- ripgreprc | 2 + tmux.conf | 1 + zshrc | 2 - 9 files changed, 884 insertions(+), 267 deletions(-) delete mode 100644 bash_profile create mode 100644 ripgreprc delete mode 100644 zshrc diff --git a/bash_aliases b/bash_aliases index 1944d86..24ff3b5 100644 --- a/bash_aliases +++ b/bash_aliases @@ -1,13 +1,11 @@ #!/bin/bash # General Aliases -alias texclean='rm -f *.toc *.aux *.log *.cp *.fn *.tp *.vr *.pg *.ky' alias h='history' alias allh='history | more' alias hgrep='history | grep' -alias j="jobs -l" - alias c='clear' + # don't alias . #alias .='cwd @@ -18,14 +16,11 @@ alias cd..='cd ..' #alias cdwd='cd $(bin/pwd)' alias cwd='echo $PWD' -alias pu="pushd" -alias po="popd" - # File system alias ln='ln -iv' alias du='du -h' -# somels aliases, 'l' should my default list command +# some ls aliases, 'l' should my default list command alias ll='ls -alFh' alias la='ls -A' alias l='ls -CFB --hide="*.pyc" --hide="*~"' @@ -43,50 +38,25 @@ alias cdopen=xdg-open # Git alias g='git' -alias notebook='ipython notebook' -alias pnotebook='ipython notebook --pylab=inline' - # tmux 256 colours alias tmux='tmux -2' -# -# Csh compatability: -# -alias unsetenv=unset -function setenv () { - export $1="$2" -} - # Irssi is weird on larger screens under tmux # http://www.wisdomandwonder.com/link/7784/making-irssi-refresh-work-with-tmux alias irssi='TERM=screen-256color irssi' -# Functions -files () { find ${1} -type f -print ; } -ff () { find . -name ${1} -print ; } -llp () { ls --color=always -lag "$@" | more ; } -word () { fgrep -i "$*" /usr/share/dict/british-english ; } -wordcount () { cat "${1}" | tr -s ' .,;:?\!()[]"' '\012' | \ - awk 'END {print NR}' ; } - -colour() { - heads=${@:1:$((${#@} - 1))} - tail=${@:${#@}} - pygmentize -f terminal -g $tail | less -R $heads -} - # # Git # git_pull_all () { - find -L . -name .git -type d -prune -print0 | xargs -0 -n 1 -I{} bash -c 'echo {}; git -C {}/.. pull; echo' + find -name .git -execdir git pull \; } git_checkout_all () { - find -L . -name .git -type d -prune -print0 | xargs -0 -n 1 -I{} bash -c 'echo {}; git -C {}/.. checkout $1; git -C {}/.. branch; echo' + find -name .git -execdir git checkout "$1" \; } git_remote_state () @@ -141,17 +111,47 @@ palert () slack_ping "${type}: ${msg}" } +echo_passed () { + echo -ne "\e[32m" +cat << 'EOF' + . . + / `. .' \ + .---. < > < > .---. + | \ \ - ~ ~ - / / | + ~-..-~ ~-..-~ + \~~~\.' `./~~~/ + \__/ \__/ + / .- . \ + _._ _.- .-~ ~-. / } \/~~~/ + _.-'q }~ / } { ; \__/ + {'__, / ( / { / `. ,~~| . . + `''''='~~-.__( /_ | /- _ `..-' \\ // + / \ =/ ~~--~~{ ./| ~-. `-..__\\_//_.-' + { \ +\ \ =\ ( ~ - . _ _ _..---~ + | | { } \ \_\ + '---.o___,' .o___,' +EOF + echo -ne "\e[0m" +} + +# Vim aliases +# pvim is for running vim in a bash pipeline +alias pvim='vim +":setlocal buftype=nofile" -' +alias pvim_yaml='vim +":setlocal buftype=nofile filetype=yaml" -' +alias pvim_json='vim +":setlocal buftype=nofile filetype=json" -' + goci() { shell_pid=$$ running=false pid_file=$(mktemp --suffix _goci.pid) - trap "rm -f $pid_file" EXIT + trap "rm -f $pid_file && setterm -cursor on" EXIT SIGINT excludes="${excludes}$(find . \( -path ./vendor -o -path ./.git \) -prune -o -type f -executable -print0 | tr "|" "\|" | tr "\0" "|")" excludes="${excludes}\..*\.sw[px]$|.git|.*~$|vendor/.*" + setterm -cursor off clear inotifywait --quiet --monitor --recursive --exclude "${excludes}" --event modify,create,delete,move --format %f . | stdbuf -oL uniq | while read line do @@ -162,10 +162,22 @@ goci() echo "'''$line''' changed - building..." running=true ( - set -xe - go build -v + set -e + go_packages=$(go list ./... | grep -v /vendor/) + echo "Go Packages: $go_packages" + go build $GO_CI_BUILD_ARGS echo testing... - go test -v $(go list ./... | grep -v /vendor/) + go test -v $go_packages + if command -v golint >/dev/null 2>&1; then + echo linting... + golint -set_exit_status $go_packages + fi + if [ -n "$(type -t echo_passed)" ] && [ "$(type -t echo_passed)" = function ]; then + clear + echo_passed + else + echo "Success!" + fi ) & echo $! > ${pid_file} sleep 1 @@ -174,4 +186,6 @@ goci() done } -# Below are functions added with the add-alias command +if [ -f ~/.secret_bash_aliases ]; then + . ~/.secret_bash_aliases +fi diff --git a/bash_profile b/bash_profile deleted file mode 100644 index 9977fd1..0000000 --- a/bash_profile +++ /dev/null @@ -1,5 +0,0 @@ - -[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile - -# rvm is slow -# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* diff --git a/bashrc b/bashrc index c8c2176..192b49e 100644 --- a/bashrc +++ b/bashrc @@ -56,7 +56,7 @@ fi # set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in - xterm-color) color_prompt=yes;; + xterm-color|*-256color) color_prompt=yes;; esac # uncomment for a colored prompt, if the terminal has the capability; turned @@ -150,16 +150,6 @@ if [ -d "$HOME/.local/bin" ] ; then PATH="$HOME/.local/bin:$PATH" fi -# virtualenvwrapper -# if [ -f /usr/local/bin/virtualenvwrapper.sh ]; then -# export WORKON_HOME=$HOME/.virtualenvs -# export PROJECT_HOME=$HOME/Documents/python -# source /usr/local/bin/virtualenvwrapper.sh -# fi - -# Don't write .pyc files -# export PYTHONDONTWRITEBYTECODE=1 - # npm if [ -d ~/.npm-packages ]; then export NPM_PACKAGES="$HOME/.npm-packages" @@ -172,16 +162,38 @@ if [ -d ~/.npm-packages ]; then MANPATH="$NPM_PACKAGES/share/man:$(manpath)" fi +# Check if we have SCM branch functions defined +if ! [ -n "$(type -t __git_ps1)" ] && [ "$(type -t __git_ps1)" = function ]; then + __git_ps1() { :; } +fi + +# Check if we have kubectx_ps1 functions defined +if ! ([ -n "$(type -t __kubectx_ps1)" ] && [ "$(type -t __kubectx_ps1)" = function ]); then + __kubectx_ps1() { + local printf_format=' [%s]'; + local k8sstring + + if ! command -v kubectl >/dev/null 2>&1; then + exit + fi + local cur_ctx=$(kubectl config view -o=jsonpath='{.current-context}') + + k8sstring="$cur_ctx" + + ns="$(kubectl config view -o=jsonpath="{.contexts[?(@.name==\"${cur_ctx}\")].context.namespace}")" + if [[ -n "${ns}" ]]; then + k8sstring="${k8sstring}/${ns}" + fi + + printf -- "$printf_format" "$k8sstring" + } +fi + # tmux if [ -f ~/.tmuxinator.bash ]; then . ~/.tmuxinator.bash fi -# Check if we have SCM branch functions defined -if ! [ -n "$(type -t __git_ps1)" ] && [ "$(type -t __git_ps1)" = function ]; then - __git_p1() { :; } -fi - # CPAN stuff if [ -d ~/perl5 ]; then PATH="$HOME/perl5/bin${PATH+:}${PATH}"; export PATH; @@ -191,7 +203,7 @@ if [ -d ~/perl5 ]; then PERL_MM_OPT="INSTALL_BASE=$HOME/perl5"; export PERL_MM_OPT; fi -# Go +# Golang if command -v go >/dev/null 2>&1; then export GOPATH="$HOME/.gopath" mkdir -p $GOPATH @@ -222,27 +234,51 @@ if [ -s "$NVM_DIR/nvm.sh" ]; then : # . "$NVM_DIR/nvm.sh" # This loads nvm fi -# SSH agent -if [ -z "$SSH_AUTH_SOCK" ] ; then - eval `ssh-agent -s` - ssh-add -fi - # Rust if [ -d "$HOME/.cargo/bin" ] ; then PATH="$HOME/.cargo/bin:${PATH}" + export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH + export LD_LIBRARY_PATH=$(rustc +nightly --print sysroot)/lib:$LD_LIBRARY_PATH +fi +if [ -d "$HOME/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/" ] ; then + export RUST_SRC_PATH="$HOME/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/" +elif [ -d "$HOME/Documents/rust/rust" ] ; then + export RUST_SRC_PATH="$HOME/Documents/rust/rust/src" fi if command -v rustup >/dev/null 2>&1; then source <(rustup completions bash) fi +if command -v rg >/dev/null 2>&1; then + export RIPGREP_CONFIG_PATH=$HOME/.ripgreprc +fi + # Emscripten if [ -d "$HOME/Documents/emscripten" ] ; then PATH="$HOME/Documents/emscripten/emsdk_portable:$HOME/Documents/emscripten/emsdk_portable/clang/fastcomp/build_incoming_64/bin:$HOME/Documents/emscripten/emsdk_portable/node/4.1.1_64bit/bin:$HOME/Documents/emscripten/emsdk_portable/emscripten/incoming:${PATH}" fi +# Java + +if [ -d "$HOME/.local/gradle-4.2.1" ] ; then + export GRADLE_HOME=$HOME/.local/gradle-4.2.1 + export PATH="$GRADLE_HOME/bin:$PATH" +fi + +# Python + +if [ -d "$HOME/.python3-env" ] ; then + VIRTUAL_ENV_DISABLE_PROMPT=true . $HOME/.python3-env/bin/activate +fi + # Digital Ocean if command -v doctl >/dev/null 2>&1; then source <(doctl completion bash) fi +# SSH agent +if [ -z "$SSH_AUTH_SOCK" ] ; then + eval `ssh-agent -s` + ssh-add +fi + diff --git a/git-completion.bash b/git-completion.bash index 482ca84..3683c77 100644 --- a/git-completion.bash +++ b/git-completion.bash @@ -10,6 +10,7 @@ # *) local and remote tag names # *) .git/remotes file names # *) git 'subcommands' +# *) git email aliases for git-send-email # *) tree paths within 'ref:path/to/file' expressions # *) file paths within current working directory and index # *) common --long-options @@ -27,27 +28,55 @@ # completion style. For example '!f() { : git commit ; ... }; f' will # tell the completion to use commit completion. This also works with aliases # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '". +# +# You can set the following environment variables to influence the behavior of +# the completion routines: +# +# GIT_COMPLETION_CHECKOUT_NO_GUESS +# +# When set to "1", do not include "DWIM" suggestions in git-checkout +# completion (e.g., completing "foo" when "origin/foo" exists). case "$COMP_WORDBREAKS" in *:*) : great ;; *) COMP_WORDBREAKS="$COMP_WORDBREAKS:" esac +# Discovers the path to the git repository taking any '--git-dir=' and +# '-C ' options into account and stores it in the $__git_repo_path +# variable. +__git_find_repo_path () +{ + if [ -n "$__git_repo_path" ]; then + # we already know where it is + return + fi + + if [ -n "${__git_C_args-}" ]; then + __git_repo_path="$(git "${__git_C_args[@]}" \ + ${__git_dir:+--git-dir="$__git_dir"} \ + rev-parse --absolute-git-dir 2>/dev/null)" + elif [ -n "${__git_dir-}" ]; then + test -d "$__git_dir" && + __git_repo_path="$__git_dir" + elif [ -n "${GIT_DIR-}" ]; then + test -d "${GIT_DIR-}" && + __git_repo_path="$GIT_DIR" + elif [ -d .git ]; then + __git_repo_path=.git + else + __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)" + fi +} + +# Deprecated: use __git_find_repo_path() and $__git_repo_path instead # __gitdir accepts 0 or 1 arguments (i.e., location) # returns location of .git repo __gitdir () { if [ -z "${1-}" ]; then - if [ -n "${__git_dir-}" ]; then - echo "$__git_dir" - elif [ -n "${GIT_DIR-}" ]; then - test -d "${GIT_DIR-}" || return 1 - echo "$GIT_DIR" - elif [ -d .git ]; then - echo .git - else - git rev-parse --git-dir 2>/dev/null - fi + __git_find_repo_path || return 1 + echo "$__git_repo_path" elif [ -d "$1/.git" ]; then echo "$1/.git" else @@ -55,6 +84,14 @@ __gitdir () fi } +# Runs git with all the options given as argument, respecting any +# '--git-dir=' and '-C ' options present on the command line +__git () +{ + git ${__git_C_args:+"${__git_C_args[@]}"} \ + ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null +} + # The following function is based on code from: # # bash_completion - programmable completion functions for bash 3.2+ @@ -74,8 +111,7 @@ __gitdir () # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# along with this program; if not, see . # # The latest version of this software can be obtained here: # @@ -184,6 +220,20 @@ _get_comp_words_by_ref () } fi +# Fills the COMPREPLY array with prefiltered words without any additional +# processing. +# Callers must take care of providing only words that match the current word +# to be completed and adding any prefix and/or suffix (trailing space!), if +# necessary. +# 1: List of newline-separated matching completion words, complete with +# prefix and suffix. +__gitcomp_direct () +{ + local IFS=$'\n' + + COMPREPLY=($1) +} + __gitcompappend () { local x i=${#COMPREPLY[@]} @@ -282,11 +332,11 @@ __gitcomp_file () __git_ls_files_helper () { if [ "$2" == "--committable" ]; then - git -C "$1" diff-index --name-only --relative HEAD + __git -C "$1" diff-index --name-only --relative HEAD else # NOTE: $2 is not quoted in order to support multiple options - git -C "$1" ls-files --exclude-standard $2 - fi 2>/dev/null + __git -C "$1" ls-files --exclude-standard $2 + fi } @@ -298,99 +348,195 @@ __git_ls_files_helper () # slash. __git_index_files () { - local dir="$(__gitdir)" root="${2-.}" file + local root="${2-.}" file - if [ -d "$dir" ]; then - __git_ls_files_helper "$root" "$1" | - while read -r file; do - case "$file" in - ?*/*) echo "${file%%/*}" ;; - *) echo "$file" ;; - esac - done | sort | uniq - fi + __git_ls_files_helper "$root" "$1" | + while read -r file; do + case "$file" in + ?*/*) echo "${file%%/*}" ;; + *) echo "$file" ;; + esac + done | sort | uniq } +# Lists branches from the local repository. +# 1: A prefix to be added to each listed branch (optional). +# 2: List only branches matching this word (optional; list all branches if +# unset or empty). +# 3: A suffix to be appended to each listed branch (optional). __git_heads () { - local dir="$(__gitdir)" - if [ -d "$dir" ]; then - git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ - refs/heads - return - fi + local pfx="${1-}" cur_="${2-}" sfx="${3-}" + + __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ + "refs/heads/$cur_*" "refs/heads/$cur_*/**" } +# Lists tags from the local repository. +# Accepts the same positional parameters as __git_heads() above. __git_tags () { - local dir="$(__gitdir)" - if [ -d "$dir" ]; then - git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ - refs/tags - return - fi + local pfx="${1-}" cur_="${2-}" sfx="${3-}" + + __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ + "refs/tags/$cur_*" "refs/tags/$cur_*/**" } -# __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments -# presence of 2nd argument means use the guess heuristic employed -# by checkout for tracking branches +# Lists refs from the local (by default) or from a remote repository. +# It accepts 0, 1 or 2 arguments: +# 1: The remote to list refs from (optional; ignored, if set but empty). +# Can be the name of a configured remote, a path, or a URL. +# 2: In addition to local refs, list unique branches from refs/remotes/ for +# 'git checkout's tracking DWIMery (optional; ignored, if set but empty). +# 3: A prefix to be added to each listed ref (optional). +# 4: List only refs matching this word (optional; list all refs if unset or +# empty). +# 5: A suffix to be appended to each listed ref (optional; ignored, if set +# but empty). +# +# Use __git_complete_refs() instead. __git_refs () { - local i hash dir="$(__gitdir "${1-}")" track="${2-}" + local i hash dir track="${2-}" + local list_refs_from=path remote="${1-}" local format refs - if [ -d "$dir" ]; then - case "$cur" in + local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}" + local match="${4-}" + local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers + + __git_find_repo_path + dir="$__git_repo_path" + + if [ -z "$remote" ]; then + if [ -z "$dir" ]; then + return + fi + else + if __git_is_configured_remote "$remote"; then + # configured remote takes precedence over a + # local directory with the same name + list_refs_from=remote + elif [ -d "$remote/.git" ]; then + dir="$remote/.git" + elif [ -d "$remote" ]; then + dir="$remote" + else + list_refs_from=url + fi + fi + + if [ "$list_refs_from" = path ]; then + if [[ "$cur_" == ^* ]]; then + pfx="$pfx^" + fer_pfx="$fer_pfx^" + cur_=${cur_#^} + match=${match#^} + fi + case "$cur_" in refs|refs/*) format="refname" - refs="${cur%/*}" + refs=("$match*" "$match*/**") track="" ;; *) for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do - if [ -e "$dir/$i" ]; then echo $i; fi + case "$i" in + $match*) + if [ -e "$dir/$i" ]; then + echo "$pfx$i$sfx" + fi + ;; + esac done - format="refname:short" - refs="refs/tags refs/heads refs/remotes" + format="refname:strip=2" + refs=("refs/tags/$match*" "refs/tags/$match*/**" + "refs/heads/$match*" "refs/heads/$match*/**" + "refs/remotes/$match*" "refs/remotes/$match*/**") ;; esac - git --git-dir="$dir" for-each-ref --format="%($format)" \ - $refs + __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \ + "${refs[@]}" if [ -n "$track" ]; then # employ the heuristic used by git checkout # Try to find a remote branch that matches the completion word # but only output if the branch name is unique - local ref entry - git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \ - "refs/remotes/" | \ - while read -r entry; do - eval "$entry" - ref="${ref#*/}" - if [[ "$ref" == "$cur"* ]]; then - echo "$ref" - fi - done | sort | uniq -u + __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \ + --sort="refname:strip=3" \ + "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \ + uniq -u fi return fi - case "$cur" in + case "$cur_" in refs|refs/*) - git ls-remote "$dir" "$cur*" 2>/dev/null | \ + __git ls-remote "$remote" "$match*" | \ while read -r hash i; do case "$i" in *^{}) ;; - *) echo "$i" ;; + *) echo "$pfx$i$sfx" ;; esac done ;; *) - echo "HEAD" - git for-each-ref --format="%(refname:short)" -- \ - "refs/remotes/$dir/" 2>/dev/null | sed -e "s#^$dir/##" + if [ "$list_refs_from" = remote ]; then + case "HEAD" in + $match*) echo "${pfx}HEAD$sfx" ;; + esac + __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \ + "refs/remotes/$remote/$match*" \ + "refs/remotes/$remote/$match*/**" + else + local query_symref + case "HEAD" in + $match*) query_symref="HEAD" ;; + esac + __git ls-remote "$remote" $query_symref \ + "refs/tags/$match*" "refs/heads/$match*" \ + "refs/remotes/$match*" | + while read -r hash i; do + case "$i" in + *^{}) ;; + refs/*) echo "$pfx${i#refs/*/}$sfx" ;; + *) echo "$pfx$i$sfx" ;; # symbolic refs + esac + done + fi ;; esac } +# Completes refs, short and long, local and remote, symbolic and pseudo. +# +# Usage: __git_complete_refs [