<repo_name>dbrady/dotfiles<file_sep>/dotplatform-dev
#!/bin/bash

export PLATFORM_DEV=$HOME/dev
shovel() ( $PLATFORM_DEV/script/run shovel "$@"; )
alias de='docker exec -e COLUMNS="$(tput cols)" -e LINES="$(tput lines)" -ti'
alias dps='docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}\t{{.Command}}\t{{.Image}}"'

# zsh completion - investigate for bash?
# export PLATFORM_DEV=$HOME/platform/dev # change to match your local dev directory
# fpath=($PLATFORM_DEV/misc/completion/ $fpath)
# autoload -U compinit && compinit
<file_sep>/osx_or_linux.sh
#!/bin/bash

echo `uname -a | awk '{print $1}'`
case `uname -a | awk '{print $1}'` in
    Linux)
        echo 'This is running on Linux!' ;;
    Darwin)
        echo 'This is running on OSX!' ;;
    *)
        echo 'I have no clue what OS this is. :-(' ;;
esac


# Here's the same thing as an if test statement
if [ `uname -a | awk '{print $1}'` = 'Linux' ]; then echo 'This is running on Linux!'; fi
if [ `uname -a | awk '{print $1}'` = 'Darwin' ]; then echo 'This is running on OSX!'; fi
<file_sep>/just_your_methods.rb
# thing.just_your_methods - Return methods not shared with all Object instances

# Differs from object.methods(false) in that it returns methods you inherit from
# parent classes (that aren't also inherited by Object instances)

class Object
  def just_your_methods
    (self.methods - Object.new.methods).sort
  end
end

puts "Object#just_your_methods loaded."
<file_sep>/ps1_functions
#!/usr/bin/env bash

# ======================================================================
# ps1_functions
#
# Originally stol^H^H^H^Hcopied from .rvm/contrib, which I sort of
# feel entitled to do since I helped Wayne write the original version
# of this script. Well, I watched him do it, at any rate. :-)
# Excellent bash programming tutorial video here:
# http://vimeo.com/21538711
#
# Why I'm forking it: I'm now working on a company laptop where I need
# my git config to show my company name/email when I'm working on
# company projects, but my personal name/email when I'm working on
# personal stuff.
# ======================================================================

#
# Source this file in your ~/.bash_profile or interactive startup file.
# This is done like so:
#
#    [[ -s "$HOME/.rvm/contrib/ps1_functions" ]] &&
#      source "$HOME/.rvm/contrib/ps1_functions"
#
# Then in order to set your prompt you simply do the following for example
#
# Examples:
#
#   ps1_set --prompt ∫
#
#   or
#
#   ps1_set --prompt ∴
#
# This will yield a prompt like the following, for example,
#
# 00:00:50 wayneeseguin@GeniusAir:~/projects/db0/rvm/rvm  (git:master:156d0b4) [<EMAIL>]  ruby-1.8.7-p334@rvm
# ∴
#
ps1_titlebar()
{
  case $TERM in
    (xterm*|rxvt*)
      printf "%s" "\033]0;\\u@\\h: \W\\007"
      ;;
  esac
}

ps1_identity()
{
  if (( $UID == 0 )) ; then
    printf "%s" "\[\033[31m\]\\u\[\033[0m\]@\[\033[36m\]\\h\[\033[35m\]:\w\[\033[0m\] "
  else
    printf "%s" "\[\033[32m\]\\u\[\033[0m\]@\[\033[36m\]\\h\[\033[35m\]:\w\[\033[0m\] "
  fi
}

ps1_git()
{
  local branch="" sha1="" line="" attr="" color=0 pr=""

  shopt -s extglob # Important, for our nice matchers :)

  command -v git >/dev/null 2>&1 || {
    printf " \033[1;37m\033[41m[git not found]\033[m "
    return 0
  }

  branch=$(git symbolic-ref -q HEAD 2>/dev/null) || return 0 # Not in git repo.
  branch=${branch##refs/heads/}

  # Now we display the branch.
  sha1=$(git rev-parse --short --quiet HEAD)

  case "${branch:-"(no branch)"}" in
      production|prod)                            attr="1;37m\033[" ; color=41 ;; # bold white on red
      master|develop|dev|development|deploy|main) attr="1;37m\033[" ; color=41 ;; # bold white on red
      stage|staging)                              color=33 ;; # yellow
      next)                                       color=36 ;; # gray
      *)
          if [[ -n "${branch}" ]] ; then # Happiness! This is a feature/story branch :)
              color=32 # green
              # TODO: don't show PR info if get-pr-id returns -1
              pr=" \033[1;37;42mPR-$(git get-pr-id)"
          else
              color=0 # reset
          fi
          ;;
  esac

  [[ $color -gt 0 ]] &&
      printf "\[\033[${attr}${color}m\](git:${branch}$(ps1_git_status):$sha1)${pr}\[\033[0m\] $(ps1_git_email) "
}

ps1_git_email()
{
    local hash_program="" attr="" fgcolor=0 bgcolor=0 color="" git_email="" hash=""

    git_email="$(git config --get user.email)"

    # Hash emails here only because this file is publicly visible ;-)
    hash_program="md5"
    command -v $hash_program >/dev/null 2>&1 || $hash_program="md5sum"
    hash=`echo ${git_email} | ${hash_program} | cut -f 1 -d ' '`
    prerendered=0

    # TODO: 2020-10-11 - Today I did 3 commits from the wrong email even though
    # it was colorized. Two thoughts about that: For now, just watch for it
    # (YAGNI: it might have been a one-off?) and if it happens again let's add a
    # path fragment for each email to belong to, and if it doesn't belong let's
    # freak right out, like bold white on bright red at a minimum, possibly even
    # blart an alarm to $stderr if possible?
    #
    # In the Interim: these were new repos that also needed add_nocommit to be
    # run on them. I wonder if I could change git clone to emit a reminder
    # and/or the same in add_nocommit (I forgot to run add_nocommit too until
    # later, so eh.)
    #
    # IF IT HAPPENS AGAIN but isn't merged, git rebase -i
    # <commit_before_mistake> and change all of them to "edit", then do 'git
    # commit --amend author=blah <LOOK THIS UP, BUSY PAIRING>'
    case $hash in
        "1d0e58ecbd97780bb36f6db90a2b57ac") bgcolor=""   ; fgcolor="32"   ;; # shinybit - green
        "563e2af36b14b3c954f77e938469606b")
            git_email="\033[1;47;38;5;208mdbrady\033[0m\033[1;47;38;5;125m@\033[0m\033[1;47;38;5;208mcover\033[0m\033[1;47;38;5;125mmy\033[0m\033[1;47;38;5;208mmeds\033[0m"
            prerendered=1
            ;;
        "abf0f4f7072d77a68ccec42247fe1e4f") fgcolor="1;38;5;27"; bgcolor="48;5;15" ;; # kp - bold blue on white
        "745932c691e01f288d7b56625296afe8") fgcolor="1;38;5;15"; bgcolor="48;5;17" ;; # ks - bold white on blue
        "fdbc33b336274f0b0e65030f7e39d435") fgcolor="1;38;5;15"; bgcolor="48;5;33" ;; # acimacredit - bold white on light blue
        "d9ade019b6afb77f890ac5c93845f029") fgcolor="1;38;5;15"; bgcolor="48;5;33" ;; # acima - bold white on light blue

        # default
        *)                                  bgcolor=41   ; fgcolor="1;37" ;; # bold white on bright red
    esac

    if [[ 1 -eq $prerendered ]] ; then
        printf "%s" $git_email
    else
        if [[ -n "${bgcolor}" ]] ; then
            printf "\033[${fgcolor};${bgcolor}m%s\033[0m" $git_email
        else
            printf "\033[${fgcolor}m%s\033[0m" $git_email
        fi
    fi
}

ps1_git_status()
{
  local git_status="$(git status 2>/dev/null)"

  [[ "${git_status}" = *deleted* ]]                    && printf "%s" "-"
  [[ "${git_status}" = *Untracked[[:space:]]files:* ]] && printf "%s" "+"
  [[ "${git_status}" = *modified:* ]]                  && printf "%s" "*"
}

ps1_rvm()
{
  command -v rvm-prompt >/dev/null 2>&1 && printf "%s" " $(rvm-prompt) "
}

ps1_update()
{
  local prompt_char='$' separator="\n" notime=0 thisisdocker=''

  (( $UID == 0 )) && prompt_char='#'

  while [[ $# -gt 0 ]] ; do
    local token="$1" ; shift

    case "$token" in
      --trace)
        export PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()}  \${LINENO} > "
        set -o xtrace
        ;;
      --prompt)
        prompt_char="$1"
        shift
        ;;
      --noseparator)
        separator=""
        ;;
      --separator)
        separator="$1"
        shift
        ;;
      --notime)
        notime=1
        ;;
      *)
        true # Ignore everything else.
        ;;
    esac
  done

  if [ "$IS_DOCKER_LOCAL" != "1" ]; then
      # Not on docker - use my usual prompt nonsense
      if (( notime > 0 )) ; then
          PS1="$(ps1_titlebar)$(ps1_identity)$(ps1_git)$(ps1_rvm)$(vpn_display)${separator}${prompt_char} "
      else
          PS1="$(ps1_titlebar)\D{%H:%M:%S} $(ps1_identity)$(ps1_git)$(ps1_rvm)$(vpn_display)${separator}${prompt_char} "
      fi
  else
      # Yes on docker - use my alternative prompt nonsense
      thisisdocker="\033[1;37;105m ~~~ THIS IS DOCKER ~~~ THIS IS DOCKER ~~~ THIS IS DOCKER ~~~ THIS IS DOCKER ~~~ THIS IS DOCKER ~~~ THIS IS DOCKER ~~~ THIS IS DOCKER ~~~ \033[0m"

      if (( notime > 0 )) ; then
          PS1="$(ps1_titlebar)$(ps1_identity)$(ps1_git)$(ps1_rvm)${separator}${thisisdocker}${separator}${prompt_char} "
      else
          PS1="$(ps1_titlebar)\D{%H:%M:%S} $(ps1_identity)$(ps1_git)$(ps1_rvm)${separator}${thisisdocker}${separator}${prompt_char} "
      fi
  fi
}

ps2_set()
{
  PS2="  \[\033[0;40m\]\[\033[0;33m\]> \[\033[1;37m\]\[\033[1m\]"
}

ps4_set()
{
  export PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()}  \${LINENO} > "
}

# WARNING:  This clobbers your PROMPT_COMMAND so if you need to write your own, call
#           ps1_update within your PROMPT_COMMAND with the same arguments you pass
#           to ps1_set
#
# The PROMPT_COMMAND is used to help the prompt work if the separator is not a new line.
# In the event that the separator is not a new line, the prompt line may become distorted if
# you add or delete a certian number of characters, making the string wider than the
# $COLUMNS + len(your_input_line).
#
# This orginally was done with callbacks within the PS1 to add in things like the git
# commit, but this results in the PS1 being of an unknown width which results in the prompt
# being distorted if you add or remove a certain number of characters. To work around this
# it now uses the PROMPT_COMMAND callback to re-set the PS1 with a known width of chracters
# each time a new command is entered. See PROMPT_COMMAND for more details.
#
ps1_set()
{
  PROMPT_COMMAND="ps1_update $@"
}

ps1_plain()
{
    PROMPT_COMMAND=""
    PS1="$(ps1_identity)\\$ "
}

ps1_bare()
{
    PROMPT_COMMAND=""
    PS1="\\$ "
}
<file_sep>/xml_load_file.rb
# loading a file from disk that contains XML directly into memory is a minor
# PITA in Ruby, and it shouldn't be. This creates a global method, load_xml,
# that does exactly what you'd expect, as long as you expect it to use Nokogiri
# to load the xml file.
require "nokogiri"
def xml_load_file(filename)
  Nokogiri::XML(File.read(File.expand_path(filename)))
end
$stderr.puts "So, doin' a lot of XML work lately, eh? I just created xml_load_file(filename) for you. You're welcome."
<file_sep>/dotbash_functions
#!/bin/bash
# ----------------------------------------------------------------------
# tssh()
#
# Clever hack from <NAME> -- when in tmate, tssh will put the
# tmate_ssh key into the OSX clipboard
# ----------------------------------------------------------------------
tssh() {
    echo "tmate display -p '#{tmate_ssh}'"
    tmate display -p '#{tmate_ssh}'

    echo "tmate display -p '#{tmate_ssh}' | pbcopy;"
    tmate display -p '#{tmate_ssh}' | pbcopy;

    echo "copied to clipboard."
}

# ----------------------------------------------------------------------
# makeline()
#
# 'makeline =' to make terminal width line. Or give 2nd arg count. By
# default prints a line of #'s as wide as the terminal.
#
# Credit due to @climagic:
# https://twitter.com/#!/climagic/status/168025763063406593
#
# Example:
# $ makeline = 40
# ========================================
makeline() { printf "%${2:-$COLUMNS}s\n" ""|tr " " ${1:-#}; }

# ========================================
# Interface to calc. Use from prompt!
# $ calc "sqrt(37)+(2^7/3)"
# 48.74942
# ========================================
calc() { bc <<< "scale=5; $1";}

# ----------------------------------------------------------------------
# rspec_alot()
#
# stolen from <NAME> - do I need to tweak this to bundle exec or
# bin/rspec?
# ----------------------------------------------------------------------
function rspec_alot() {
  for i in `seq $1` ; do rspec $2 ; [[ ! $? = 0 ]] && break ; done
}
<file_sep>/bash_completions
#!/bin/sh

# Include ports' version of bash_completion (if it exists)
if [ -f /opt/local/etc/bash_completion ]; then
    . /opt/local/etc/bash_completion
fi


# FIXME: This does not work. Something about the colon causes the
# expander to wonk. I think maybe complete treats : as a separate
# token? Dono. Anyway, here's what happens:
#
# You type...                You get...
# 
# rake db:<TAB>              rake db:db:
# rake db:mig<TAB>           rake db:migrate
# # Custom expansion of rake tasks. WOO!
# _rake_tasks()
# {
#     local curw
#     COMPREPLY=()
#     curw=${COMP_WORDS[COMP_CWORD]}
#     # The bit of ruby in there eats the first line of output. Wish
#     # head/tail had the ability to show all but the n first/last lines
#     # of a file.
#     local tasks="$(rake -T | ruby -n -e 'puts $_ if $seen; $seen=true' | awk '{ print $2 }')"
#     COMPREPLY=($(compgen -W '$tasks' -- $curw));
#     return 0
# }
# complete -F _rake_tasks rake

# dbrady 2008-12-03: Commented out because ports bash_completion does this better than me.
# Custom expansion of ssh, using hostnames from .ssh/config
# _sshhosts()
# {
#   # cat ~/.ssh/config | grep -Ei '^Host' | awk '{ print $2}'
#     local curw
#     COMPREPLY=()
#     curw=${COMP_WORDS[COMP_CWORD]}
#     local hosts="$(cat ~/.ssh/config | grep -Ei '^Host' | awk '{ print $2}')"
#     COMPREPLY=($(compgen -W '$hosts' -- $curw));
#     return 0
# }
# complete -o default -o nospace -F _sshhosts ssh
# complete -o default -o nospace -F _sshhosts scp

# Custom expansion for mysql-D <databasename>
_mysqldbs()
{
    local cur prev
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    if [[ ${prev} == -D ]] ; then
        local dbs="$(mysql -e 'show databases')"
        COMPREPLY=( $(compgen -W "${dbs}" -- ${cur}) )
        return 0
    fi
}
complete -o default -o nospace -F _mysqldbs mysql

# Custom expansion for mategem
_gemdirs()
{
    local curw
    COMPREPLY=()
    curw=${COMP_WORDS[COMP_CWORD]}
    local gems="$(gem environment gemdir)/gems"
    COMPREPLY=($(compgen -W '$(ls $gems)' -- $curw));
    return 0
}
complete -F _gemdirs -o dirnames mategem
complete -F _gemdirs -o dirnames emgem
# cdgem is just an alias script for "cd", but this lets me get
# tab-completion into the gems folder. Why yes, I am that
# lazy^H^H^H^Hclever, thank you for asking.
complete -F _gemdirs -o dirnames cdgem

<file_sep>/dotirbrc
#!/usr/bin/env ruby

# begin
#   # looksee is awesome. Adds gorgeous Object#ls method
#   # https://github.com/oggy/looksee
#   require 'looksee'
# rescue LoadError => e
#   $stderr.puts "~/.irbrc:#{__LINE__}: Could not load looksee/shortcuts: looksee gem not present in this gemset"
# end

require File.expand_path("~/dotfiles/json_load_file")
require File.expand_path("~/dotfiles/xml_load_file")
require File.expand_path("~/dotfiles/just_your_methods")

# Hello Acima MP Rails
if defined? Rails

  ZBONCAK_ID=41499
  ZBONCAK_GUID="merc-5c5d37fb-071c-4739-b832-bfafc93db09b"
  DAVE_USER_ID=2892
  DAVE_API_USER_ID=377

  puts 'def load_merchant; Merchant.find(41499); end # Find Zboncak-Adams easily'
  puts 'def load_user; User.find(2892); end # Find my user easily'
  puts 'def load_api_user; ApiUser.find(377); end'
  puts "def load_hacks -> load all files in app/local_hacks"

  def load_hacks
    # load all files in app/local_hacks
    Dir.glob(Rails.root + "app/local_hacks/*").each do |file|
      puts "Loading #{file}..."
      load file
    end
    puts "Loaded! Call ApiScript.ls to list important/useful methods"
  end

  def load_merchant
    Merchant.find ZBONCAK_ID
  end

  def load_location
    load_merchant.locations.first
  end

  def load_user
    User.find DAVE_USER_ID
  end

  def load_api_user
    ApiUser.find DAVE_API_USER_ID
  end

  class User < ApplicationRecord
    def add_all_roles!
      puts "Giving all roles to #{full_name}..."
      user.role_names = "|#{Role.all.pluck(:short_name) * '|'}|"
      user.save
    end

    def remove_all_roles!
      puts "Removing all roles from #{full_name}..."
      user.role_names = ''
      user.save
    end
  end

  # for the 49/99 stuff
  class Location < ApplicationRecord
    def banksy?
      puts "location.settings.can_offer_unbanked_application"
      settings.can_offer_unbanked_application
    end

    def banksy!(enable=true)
      puts "location.settings.update!(can_offer_unbanked_application: #{enable.inspect})"
      settings.update!(can_offer_unbanked_application: enable)
    end
  end


  class Lease < ApplicationRecord
    def banksy?
      puts "lease.settings.unbanked_application"
      settings.unbanked_application
    end

    def banksy!(enable=true)
      puts "lease.settings.update!(unbanked_application: #{enable.inspect})"
      settings.update!(unbanked_application: true)
    end
  end
end
<file_sep>/dotbash_profile
#!/bin/sh
export EDITOR=$(echo `which emacs` -nw -q -l ~/.emacstiny)
export GEMEDITOR=$(echo `which emacs` -nw)
export CVSEDITOR=$(echo `which emacs` -nw -q -l ~/.emacstiny)
export SVN_EDITOR=$(echo `which emacs` -nw -q -l ~/.emacstiny)

# Flags suggested by homebrew
export LDFLAGS="-L/opt/homebrew/opt/curl/lib"
export CPPFLAGS="-I/opt/homebrew/opt/curl/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/curl/lib/pkgconfig"

case `uname -a | awk '{print $1}'` in
    Linux)
        # export JAVA_HOME='/usr/lib/jvm/default-java'
        export JAVA_HOME='/usr/lib/jvm/java-8-openjdk-amd64/'
        ;;
    Darwin)
        export JAVA_HOME='/System/Library/Frameworks/JavaVM.framework/Home'
        ;;
    *)
        echo '~/.bash_profile has no clue what OS this is; not setting JAVA_HOME.'
        ;;
esac

# === OSX Specific ======================================================
# Search the ls manpage for "CLICOLOR" and "color designators for an
# explanation of this goodness.

# CLICOLOR: Search "man ls" for "CLICOLOR" and "color designators".
# a: black                                        1.  directory
# b: red                                          2.  symbolic link
# c: green                                        3.  socket
# d: brown                                        4.  pipe
# e: blue                                         5.  executable
# f: magenta                                      6.  block special
# g: cyan                                         7.  character special
# h: light grey                                   8.  executable with setuid bit set
# A: bold black, usually shows up as dark grey    9.  executable with setgid bit set
# B: bold red                                     10. directory writable to others, with sticky bit
# C: bold green                                   11. directory writable to others, without sticky bit
# D: bold brown, usually shows up as yellow
# E: bold blue
# F: bold magenta
# G: bold cyan
# H: bold light grey; looks like bright white
# x: default foreground or background
#
# The standard Mac OSX colors are: exfxcxdxbxegedabagacad
#
# TODO: export these to functions or scripts called light_bg or dark_bg, etc.
export CLICOLOR=1
# Standard colors look good on a white background
# export LSCOLORS=exfxcxdxbxegedabagacad
# export LS_COLORS=exfxcxdxbxegedabagacad

# Swap blue/cyan for better visibility on dark bg
#export LSCOLORS=gxfxcxdxbxegedabagacad
# === OSX Specific ======================================================

# Use less by default b/c search works better. But keep most inifile
# here for tweaking.
#export PAGER="most"
export MOST_INIFILE='/etc/most.rc'

GREP_OPTIONS='--color=auto'
GREP_COLOR='1;32'

# ----------------------------------------------------------------------
# Terminal colours (after installing GNU coreutils)
NM="\[\033[0;38m\]" #means no background and white lines
HI="\[\033[0;37m\]" #change this for letter colors
HII="\[\033[0;31m\]" #change this for letter colors
SI="\[\033[0;33m\]" #this is for the current directory
IN="\[\033[0m\]"

export HISTFILESIZE=10000

# Whin SHIFTING dirs onto head of PATH, last shift is the first/winner.
# postgres Acima (postgresql@13 because I wanted a psql for reference)
if [[ $PATH != *"/opt/homebrew/bin"* ]]; then
    export PATH=/opt/homebrew/Cellar/postgresql\@13/13.11/bin:$PATH
fi

if [[ $PATH != *"$HOME/bin"* ]]; then
    export PATH=$HOME/bin:$PATH
fi

if [[ $PATH != *"private_bin"* ]]; then
    export PATH=~/private_bin:$PATH
fi


# Acima-specific stuffs - if more than this path needs to be here, please make a
# .acima file and source_files() it
if [[ $PATH != *"acima/bin"* ]]; then
    export PATH=~/acima/bin:$PATH
fi

if [[ $PATH != *"acima/devel/merchant_portal/app/local_hacks"* ]]; then
    export PATH=~/acima/devel/merchant_portal/app/local_hacks:$PATH
fi

source_files()
{
  local file

  for file in "$@" ; do

    file=${file/\~\//$HOME\/} # Expand ~/

    if [[ -s "${file}" ]] ; then
      source "${file}"
    # else
    #     # I found this useful for debugging, now it's just noisy
    #   if [[ ! -e "${file}" ]] ; then
    #     printf "NOTICE: ${file} does not exist, not loading.\n"
    #   else
    #     true # simply an empty file, no warning necessary.
    #   fi
    fi
  done

  return 0
}

source_files ~/.aliases \
  ~/.bash_completions \
  ~/.git-completion.bash \
  ~/.nav \
  ~/.private \
  ~/.ps1_functions \
  ~/.bash_functions \
  ~/.current-project \
  ~/.hue.conf \
  ~/.platform-dev \
  ~/.vpn

# Turn on path completion for my go command.
# This must come after git-completion.bash.
complete -o default -o nospace -F _git_checkout go

# PS1 EMOJIS
if command -v ps1_set >/dev/null 2>&1 ; then
    if [ `hostname` == "poo.local" ]; then
        ps1_set --prompt "💩 "
        export PS2=💩💩
    elif [ `hostname` == "poot" ]; then
#        ps1_set --prompt "💨­"
        ps1_set --prompt "💨 "
        export PS2="💨💨 "
        # ps1_set --prompt "$"
    elif [ `hostname` == "CMMVMOSX045" ]; then
        ps1_set --prompt "💊­"
        export PS2=💊💊­
    elif [ `hostname` == "Mac1205Pro.local" ]; then
        ps1_set --prompt "💳"
        export PS2=💳💳
    elif [ `hostname` == "31b95b7de045" ]; then
        ps1_set --prompt "🚢"
        export PS2=🚢🚢
    else
        ps1_set --prompt "🎸"
        export PS2=🎶🎵
    fi
else
    export PS1="!!! It's \D{%H} O'Clock! Check your dotfiles folder for ps1_functions.\n$ "
fi


# force 256-color terminal in docker
if [ "$IS_DOCKER_LOCAL" == "1" ]; then
    export TERM=xterm-256color
fi

export MANPATH=/opt/local/share/man:$MANPATH

# For some reason unbeknownst to me, emacs started from the CLI opens an XWindows version of emacs but with keyboard input still locked to the terminal.
# 2015-02-04 Is this dead code? Has no effect in OSX. Turn back on if linux still needs it.
# alias 'emacs'='emacs -nw'

export OPSCODE_USER=ratgeyser

# 2023-07-31 - Switching to rbenv because the keyserver poisoning is real :'-(
# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

# Acima
if [ `hostname` = "Mac1205Pro.local" ]; then
    # MP tests need this every time, so
    export TZ='America/Denver'

    # This adds 80 seconds to the MP spec suite. It is good to pass in when we
    # need the whole suite to interop correctly, but when trying to TDD it is
    # agonizing.
    # export SPEC_SEED=true

    # Acima AWS
    export AWS_PROFILE=acima-nonprod
    export KUBECONFIG=~/.kube/nonprod/preflight

    # Atlas>Artemis>Hermes gave the option to install postgresql@13 as an app,
    # and self-containment is teh win. But now I need the CLI tools in my path,
    # so...
    export PATH="$PATH:/Applications/Postgres.app/Contents/Versions/13/bin"
else
    case `uname -s` in
        Linux)
            source /etc/profile.d/rvm.sh
            ;;
        Darwin)
            echo "~/.bash_profile: I see you're on OSX but NOT your usual work machine. That's weird, right? NOT setting rvm defaults."
            ;;
        *)
            echo "~/.bash_profile has no clue what OS this is. So that's kinda neat I guess."
            ;;
    esac
fi

if [ `uname -s` = "Darwin" ]; then
    # I'll never let go of bash until they physically bar me from installing it.
    # zsh is NOT an acceptable bash unless you're not using any of bash's features.
    # That said, I get why AAPL is doing this. bash going GPL v3 poses a genuine
    # threat to the privacy of their OS.
    export BASH_SILENCE_DEPRECATION_WARNING=1
fi


# Setup ssh agent
# ssh-add -L &> /dev/null
ssh-add -L >/dev/null 2>&1
if [ $? -eq 1 ]; then
    ssh-add
fi

# OSX-specific randomness
if [ `uname -s` == "Darwin" ]; then
    test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"

    [ -f ~/.fzf.bash ] && source ~/.fzf.bash

    # capybara-webkit needs quicktime 5.5, which is the last version of QT to support webkit bindings
    # get it with brew install qt@5.5
    export PATH="/usr/local/opt/qt@5.5/bin:$PATH"

    # for mtr (OSX)
    export PATH=$PATH:/usr/local/sbin
fi

# Linux-specific randomness
if [ `uname -s` == "Linux" ]; then
    export FLEX_HOME=/home/dbrady/devel/flex_sdk_4_6/
    export PATH=$PATH:$FLEX_HOME/bin
fi

# my manual implementation of ponysay because lol
# sayfortune
# if [ -e ~/bin/applejack.txt ] ; then
#     cat ~/bin/applejack.txt
# fi

# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# $IS_DOCKER_LOCAL is a flag we set in data_services to distinguish between "prodlike, because Docker" and "prodlike, because production"
if [ ! "$IS_DOCKER_LOCAL" == "1" ]; then
    # Let's do birbs for a while. (Acima OSX only, since I don't have my Pictures
    # folder under git since I don't wanna get my repo copywronged.)  Have to call
    # it "term-birb" because "birb" will "bundle exec irb" lol.
    term-birb

    # brew shellenv will dump all the homebrew variables. eval() on it will
    # export them into the current bash session.
    eval "$(/opt/homebrew/bin/brew shellenv)"
fi

# rbenv
# eval "$(rbenv init - bash)"
# rbenv global 3.2.2
export PATH="/Users/davidbrady/.rbenv/shims/:$PATH"
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
<file_sep>/json_load_file.rb
# loading a file from disk that contains JSON directly into memory is a huge
# PITA in Ruby, and it shouldn't be. This creates a method directly on the
# module, JSON.load_file(filename), that does exactly what you'd expect.
require 'json'
module JSON
  def self.load_file(filename, options={})
    parse File.read(filename)
  end

  def self.purtify(json)
    pretty_generate parse json
  end
end
$stderr.puts "So, doin' a lot of JSON work lately, eh? I just created JSON.load_file(filename [, options]) for you. You're welcome. ([options] are so can symbolize_names: true)"
$stderr.puts "Also! I just added JSON.purtify(json). It does JSON.pretty_generate(JSON.parse(json)) so you don't have to!"
<file_sep>/dotvpn
#!/bin/bash
#

# 2023-03-28: This checks ifconfig for a specific utun or mtu connection, which
# is a mostly-but-not-always-reliable side effect. On Apple Silicon, ifconfig
# does not change. So I did some digging around and discovered that Cisco
# provides a tool for OSX to determine VPN status directly:
# `/opt/cisco/anyconnect/bin/vpn state` will report `state: Disconnected` or
# `state: Connected`. (It does this 3 times; I do not know why. So there's still
# some magic here to cargo cult around.)
#
# I don't use any of the other tools here, favoring the GUI, but I do like
# seeing if the VPN is up or not on my command-line, so I'm going to comment out
# everything in here except for the vpn state detection.

# export VPN_USER=david.brady
#
# # adds VPN password to macOS Keychain
# function set-vpn-pw() {
#   security add-generic-password -s "AnyConnect" -a "$VPN_USER" -p
# }
#
# # removes and adds new VPN password to macOS Keychain
# function update-vpn-pw() {
#   security -q delete-generic-password -s "AnyConnect" -a "$VPN_USER"
#   set-vpn-pw
# }
#
# # 2022-08-30: The old vpn hiccupped every six minutes all
# # afternoon. This was vpndev.acimacredit.com. Talking with IT, they
# # had me change just one or two tiny things[1] and switch to a new vpn
# # they were testing.
# #
# # [1] Upgrading my AnyConnect client, which required me to upgrade my
# # whole dang OS to Monterey because it didn't run on Catalina. Neet.
# #
# # 2022-11-14: The new vpn has stopped working as of last week. :'-(
# # Going back to vpndev and hoping it's not all hangy-wangy.
# #
# # testing vpn
# # acima-minuteman-wired-wpwdkjgtjq.dynamic-m.com
# #
# # tried and true and crashy AF vpn
# # vpndev.acimacredit.com
# function vpnon() {
#     printf "0\n$VPN_USER\n$(security find-generic-password -s "AnyConnect" -a "$VPN_USER" -w)\npush" | /opt/cisco/# anyconnect/bin/vpn -s connect vpndev.acimacredit.com
#     # printf "0\n$VPN_USER\n$(security find-generic-password -s "AnyConnect" -a "$VPN_USER" -w)\npush" | /opt/cisco/anyconnect/bin/vpn -s connect acima-minuteman-wired-wpwdkjgtjq.dynamic-m.com
# }
#
# alias vpnoff="/opt/cisco/anyconnect/bin/vpn disconnect"
#
# function vpn() {
#   # if [[ $(ifconfig | grep "mtu 1406" ) ]]
#   if [[ $(ifconfig | grep -E '^utun2: ') ]]
#   then
#    echo "You're connected to the VPN"
#   else
#    echo "You're not connected to the VPN"
#   fi
# }

function vpn_display() {
    # skip all this crap if we're on Docker. Don't spend all those extra
    # milliseconds invoking vpn and ifconfig.
    if [ "$IS_DOCKER_LOCAL" != "1" ]; then
        if [[ $(/opt/cisco/anyconnect/bin/vpn state | grep 'state: Connected') ]]; then
            # 32 = green [V]
            printf " \e[32m[V]\e[0m"
        else
            # Check for my onsite dedicated IP. If docker
            if [[ $(ifconfig | grep 10.1.180.) ]]; then
                # 96;40 = light cyan [O] = "you are [O]nsite"
                printf " \e[96m[O]\e[0m"
            else
                # 2;31 = dim red [V]
                printf " \e[2;31m[V]\e[0m"
            fi
        fi
    fi
}

# --------------------------------------------------------------------------------
# And then this goes in PS1 somewhere:
# \$(vpn_display)
<file_sep>/setup.sh
#!/bin/sh
pushd ~
if [ $IS_DOCKER_LOCAL == "1" ]; then
    ln -s ~/dotfiles/dotbash_profile .bashrc
    ln -s ~/dotfiles/dotnav.docker .nav
else
    ln -s ~/dotfiles/dotbashrc .bashrc
    ln -s ~/dotfiles/dotbash_profile .bash_profile
    ln -s ~/dotfiles/dotnav .nav
fi

ln -s ~/dotfiles/bash_completions .bash_completions
ln -s ~/dotfiles/dotaliases .aliases
ln -s ~/dotfiles/dotvimrc .vimrc
ln -s ~/dotfiles/dotirbrc .irbrc
ln -s ~/dotfiles/git-completion.bash .git-completion.bash
ln -s ~/dotfiles/dotgitignore .gitignore

echo "# dotprivate - This is your .private file. It generated by setup.sh\nand does not live in git." > ~/dotfiles/dotprivate
echo "# dotprivate - This is your .private file. It is autogenerated by\nsetup.sh and does not live in git." > ~/dotfiles/dotprivate
ln -s ~/dotfiles/dotprivate .private


ln -s dotfiles/ps1_functions .ps1_functions
ln -s dotfiles/dotvpn .vpn
popd
