Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
skeptycal committed Sep 6, 2019
1 parent 0772825 commit 7ad4d9e
Show file tree
Hide file tree
Showing 19 changed files with 195 additions and 121 deletions.
22 changes: 14 additions & 8 deletions .bash_profile
@@ -1,33 +1,39 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-

# Silence Catalina Warning
export BASH_SILENCE_DEPRECATION_WARNING=1

#* #############################################################################
#* ### Set Options
#* #############################################################################

umask 022 # use root defaults since they match web server defaults
set -a #? export all;

#* #############################################################################
#* ### Troubleshooting
#* #############################################################################
#? set to 1 for verbose testing
declare -xi SET_DEBUG=0

#? set to 1 for verbose testing ; remove -r to allow each script to set it
declare -ir SET_DEBUG=1
export SET_DEBUG
#? log errors to text file; only functional if $SET_DEBUG=1
if (($SET_DEBUG == 1)); then
if [[ $SET_DEBUG == 1 ]]; then
#? turn on debug logging
declare -xi DEBUG_LOG=0
export DEBUG_LOG=0
#? log file for debug logs
declare -x debug_log_file="${HOME}/.bash_profile_error.log"
export debug_log_file="${HOME}/.bash_profile_error.log"
#? max filesize for debug_log_file
declare -xi debug_log_max_size=32768
export debug_log_max_size=32768
fi
declare -x SOURCE_PATH="$HOME/.dotfiles"

#* #############################################################################
#* ### Load Profile settings
#* #############################################################################

export SOURCE_PATH="$HOME/.dotfiles"
[ -n "$PS1" ] && . "${SOURCE_PATH}/.bash_profile_details"
return

#* #############################################################################
#* ### Notes and References
Expand Down
12 changes: 4 additions & 8 deletions .bash_profile_details
Expand Up @@ -2,38 +2,34 @@
# -*- coding: utf-8 -*-
# cannot be run directly; called from .bash_profile or .bashrc

set -a
#* #############################################################################
#* ### Load profile details
#* #############################################################################

export SOURCE_PATH="$HOME/.dotfiles"

# reference: https://unix.stackexchange.com/questions/425757/avoid-sourcing-scripts-multiple-times

[[ ! $SSM_LOADED == 1 ]] && . "$(which ssm)"

function _profile_run_debug() {
db_echo "${WARN}BASH Debug Mode Enabled (SET_DEBUG=${SET_DEBUG})${RESET_FG}"
db_echo "Script source:${MAIN} ${BASH_SOURCE}${RESET_FG}"
db_script_source "Functions test"
db_echo "\$SOURCE_PATH: ${MAIN} $SOURCE_PATH"
db_echo "Logging to $debug_log_file"
db_echo "${GO}Use <versions> to see common program versions.${RESET_FG}"
}

function main() {
source "${SOURCE_PATH}/.path"
source "${SOURCE_PATH}/.exports"
source "${SOURCE_PATH}/.aliases"
source "${SOURCE_PATH}/.exports"
source "${SOURCE_PATH}/.theme"
source "${SOURCE_PATH}/.functions"
source $(which brew_fix.sh)
source "${SOURCE_PATH}/.extra"
source "${SOURCE_PATH}/.git_alias"
# prior method
# for file in ${SOURCE_PATH}/.{path,exports,aliases,theme,functions,extra,git_alias}; do
# source "$file" # &>/dev/null # used to test for errors
# done
# unset file
[[ ! $SSM_LOADED == 1 ]] && . "$(which ssm)"
[[ $SET_DEBUG == 1 ]] && _profile_run_debug
}

Expand Down
90 changes: 46 additions & 44 deletions .bash_prompt
Expand Up @@ -65,50 +65,50 @@ fi
# Heavily inspired by @necolas’s prompt: https://github.com/necolas/dotfiles
# iTerm → Profiles → Text → use 13pt Monaco with 1.1 vertical spacing.

# Detect which `ls` flavor is in use
# if ls --color > /dev/null 2>&1; then # GNU `ls`
# colorflag="--color=always"
# 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

# 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;

# 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 255); #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;
Detect which `ls` flavor is in use
if ls --color > /dev/null 2>&1; then # GNU `ls`
colorflag=" --color=always"
# 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

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;

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 255); #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;

# # Set the terminal title and prompt.
# PS1="\[\033]0;\W\007\]"; # working directory base name
Expand All @@ -125,3 +125,5 @@ fi

# PS2="\[${white}\]--→ \[${reset}\]"; # `$` (and reset color)
# export PS2;

prompt_git
4 changes: 3 additions & 1 deletion .bashrc
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
# echo "sourcing script .bashrc - forwarding to .bash_profile"

echo "sourcing script .bashrc - forwarding to .bash_profile"

[ -n "$PS1" ] && source ~/.bash_profile
return
4 changes: 2 additions & 2 deletions .exports
Expand Up @@ -15,7 +15,7 @@ export HOMEBREW_PREFIX=$(brew --prefix)
export LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
# LDFLAGS="-L/usr/local/opt/zlib/lib"
# CPPFLAGS="-I/usr/local/opt/zlib/include"
export HISTSIZE='32768'
export HISTSIZE=32768
export HISTFILESIZE="${HISTSIZE}"
export HISTCONTROL='ignoreboth'

Expand All @@ -34,7 +34,7 @@ export PROJECT_HOME="${HOME}/Documents/coding/"

# Node
export NODE_REPL_HISTORY="${HOME}/.node_history"
export NODE_REPL_HISTORY_SIZE='32768'
export NODE_REPL_HISTORY_SIZE=32768
export NODE_REPL_MODE='sloppy'

# Perl
Expand Down
5 changes: 4 additions & 1 deletion .extra
@@ -1,10 +1,13 @@
#!/usr/bin/env false bash
# *############################################################################
[[ $SET_DEBUG == 1 ]] && ce "Script source:$MAIN $BASH_SOURCE$RESET"
[[ $SET_DEBUG == 1 ]] && db_script_source ".extra test"


# https://rick.cogley.info/post/use-homebrew-zsh-instead-of-the-osx-default/
# unalias run-help
# autoload run-help
# HELPDIR=/usr/local/share/zsh/help

# source "${HOME}/.dotfiles/.iterm2_shell_integration.zsh"

source $(which brew_fix.sh)
25 changes: 14 additions & 11 deletions .functions
Expand Up @@ -11,7 +11,7 @@ COPYRIGHT="Copyright (c) 2019 Michael Treanor"
LICENSE="MIT <https://opensource.org/licenses/MIT>"
GITHUB="https://www.github.com/skeptycal"
#? ############################################################################
set -a
# set -a
export SET_DEBUG=0 # set to 1 for verbose testing
[[ ! $SSM_LOADED == 1 ]] && . "$(which ssm)"

Expand Down Expand Up @@ -574,6 +574,14 @@ function getcertnames() {
fi
}

# get name for open if linux or windows
if [ ! "$(uname -s)" = 'Darwin' ]; then
if grep -q Microsoft /proc/version; then
alias open='explorer.exe'
else
alias open='xdg-open'
fi
fi
function o() {
if [ $# -eq 0 ]; then
open .
Expand All @@ -595,19 +603,12 @@ function tree_html() {
}

function _run_debug_functions() {
attn "Functions test"
ce "Script source:$MAIN $BASH_SOURCE$RESET_FG"
db_script_source "Functions test"
warn $NAME
}

function _main_functions() {
if [ ! "$(uname -s)" = 'Darwin' ]; then
if grep -q Microsoft /proc/version; then
alias open='explorer.exe'
else
alias open='xdg-open'
fi
fi

# use git diff if available
if [[ "$(hash git &>/dev/null)" -eq 0 ]]; then
function diff() {
git diff --no-index --color-words "$@"
Expand All @@ -621,6 +622,8 @@ function _main_functions() {
[[ $SET_DEBUG == '1' ]] && _run_debug_functions
}

source

_main_functions "$@"

# generate a function list
Expand Down
Empty file added .functions_testing_new
Empty file.
Empty file added .old_functions
Empty file.
2 changes: 2 additions & 0 deletions .path
Expand Up @@ -10,6 +10,7 @@ PYTHONPATH="\
$HOME/bin/utilities/apps/python:\
/usr/bin/python:\
/usr/local/bin/python:\
./
"

PYTHONPATH="${PYTHONPATH// /}"
Expand Down Expand Up @@ -52,6 +53,7 @@ export MANPATH

PATH="\
$HOME/bin:\
./src:\
/usr/local/opt/coreutils/libexec/gnubin:\
/usr/local/opt/ccache/libexec:\
/usr/local/opt/sqlite/bin:\
Expand Down
1 change: 1 addition & 0 deletions .profile
Expand Up @@ -3,3 +3,4 @@
echo "sourcing script .profile - forwarding to .bash_profile"

[ -n "$PS1" ] && source ~/.bash_profile
return

0 comments on commit 7ad4d9e

Please sign in to comment.