commit 20cd7760817b710637706c93e63b34e69bb9c433
parent 4235b4263ca83edb3f8c7a1a54441c71a38b1b7b
Author: Daniel Moch <daniel@danielmoch.com>
Date: Thu, 4 Jan 2018 07:06:51 -0500
Refactor profile and shell rc scripts
Diffstat:
M | .bash_profile | | | 3 | ++- |
M | .bashrc | | | 22 | +++++++++++----------- |
M | .profile | | | 68 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- |
M | .shrc | | | 82 | +++++++++++++++++-------------------------------------------------------------- |
4 files changed, 95 insertions(+), 80 deletions(-)
diff --git a/.bash_profile b/.bash_profile
@@ -2,4 +2,5 @@
# ~/.bash_profile
#
-[[ -f ~/.bashrc ]] && . ~/.bashrc
+[ -r "$HOME/.profile" ] && source "$HOME/.profile"
+[[ $- == *i* ]] && source "$HOME/.bashrc"
diff --git a/.bashrc b/.bashrc
@@ -1,8 +1,8 @@
-# If not running interactively, don't do anything
-[[ $- != *i* ]] && return
-
-[ -r $HOME/.shrc ] && source $HOME/.shrc
-[ -r $HOME/.bashrc.local ] && source $HOME/.bashrc.local
+#
+# ~/.bashrc
+#
+[ -r "$HOME/.shrc" ] && source "$HOME/.shrc"
+[ -r "$HOME/.bashrc.local" ] && source "$HOME/.bashrc.local"
shopt -s dotglob globstar
@@ -11,7 +11,7 @@ export HISTCONTOL=erasedups
# Git command line configuration
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
-source $HOME/.config/bash/git-prompt.sh
+source "$HOME/.config/bash/git-prompt.sh"
# Customize the prompt
export PS1='\[\033[34m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[m\]\W\[\033[31m\]$(__git_ps1 " (%s)")\[\033[m\]\$ '
@@ -21,12 +21,12 @@ if command -v brew > /dev/null 2>&1
then
export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_NO_INSECURE_REDIRECT=1
- export HOMEBREW_CASK_OPTS=--require-sha\ --appdir=$HOME/Applications
+ export HOMEBREW_CASK_OPTS=--require-sha\ --appdir="$HOME/Applications"
export HOMEBREW_NO_AUTO_UPDATE=1
- export PATH=$(brew --prefix)/bin:$PATH
- if [ -f $(brew --prefix)/etc/bash_completion ]
+ export PATH="$(brew --prefix)/bin:$PATH"
+ if [ -f "$(brew --prefix)/etc/bash_completion" ]
then
- source $(brew --prefix)/etc/bash_completion
+ source "$(brew --prefix)/etc/bash_completion"
fi
fi
@@ -36,7 +36,7 @@ fi
#
# NOTE: Might want to check that this isn't already sourced elsewhere
# (e.g. /etc/profile).
-[ -r "$BASH_COMPLETION" ] && source $BASH_COMPLETION
+[ -r "$BASH_COMPLETION" ] && source "$BASH_COMPLETION"
unset BASH_COMPLETION
if [[ "$OSTYPE" == "darwin"* ]]
diff --git a/.profile b/.profile
@@ -1,8 +1,70 @@
#
# ~/.profile
#
-if [ -r "$HOME/.shrc" ]
+[ -r "$HOME/.profile.local" ] && . "$HOME/.profile.local"
+
+set -o emacs
+
+if [ -z "$BASH" ]
then
- . $HOME/.shrc
- export ENV=$HOME/.shrc
+ ENV=$HOME/.shrc; export ENV
fi
+
+if which vim > /dev/null 2>&1
+then
+ EDITOR=vim
+else
+ EDITOR=vi
+fi
+
+VISUAL=$EDITOR
+PAGER=less
+LESS="-FMRqX#10"
+export EDITOR VISUAL PAGER LESS
+
+if which lesskey > /dev/null 2>&1 && [ -r "$HOME/.lesskey" ]
+then
+ [ -r "$HOME/.less" ] || lesskey
+fi
+
+if which lesspipe > /dev/null 2>&1
+then
+ LESSOPEN="|`which lesspipe` %s"
+else
+ LESSOPEN="|$HOME/.lessfilter %s"
+fi
+export LESSOPEN
+unset LESSCLOSE
+
+# Keep the go folder hidden
+if which go > /dev/null 2>&1
+then
+ GOPATH=$HOME/.go
+ export GOPATH
+fi
+
+# Append our default paths
+__addpath ()
+{
+ if [ -d "$1" ]
+ then
+ case ":$PATH:" in
+ *:"$1":*)
+ ;;
+ *)
+ if [ -z "$2" ]
+ then
+ PATH="$PATH:$1"
+ else
+ PATH="$1:$PATH"
+ fi
+ esac
+ fi
+}
+
+__addpath "$HOME/.go/bin"
+__addpath "$HOME/.cargo/bin"
+__addpath "$HOME/.local/bin" "before"
+
+unset __addpath
+export PATH
diff --git a/.shrc b/.shrc
@@ -1,46 +1,18 @@
-
+#
# ~/.shrc
#
# vim: ft=sh
[ -r $HOME/.shrc.local ] && . $HOME/.shrc.local
-set -o emacs
-
-if which vim > /dev/null 2>&1
-then
- EDITOR=vim
-else
- EDITOR=vi
-fi
-
-VISUAL=$EDITOR
-user=`printf '\033[34m%s\033[m' "$LOGNAME"`
-host=`printf '\033[32m\\h\033[m'`
-PS1="$user@$host:\W\$ "
-PAGER=less
-LESS="-FMRqX#10"
-export EDITOR VISUAL PS1 PAGER LESS
-
-if which lesskey > /dev/null 2>&1 && [ -r "$HOME/.lesskey" ]
-then
- [ -r "$HOME/.less" ] || lesskey
-fi
-
-if which lesspipe > /dev/null 2>&1
+if [ -z "$BASH" ]
then
- LESSOPEN="|`which lesspipe` %s"
+ user=`printf '\033[34m%s\033[m' "$LOGNAME"`
+ host=`printf '\033[32m\\h\033[m'`
+ PS1="$user@$host:\W\$ "
else
- LESSOPEN="|$HOME/.lessfilter %s"
-fi
-export LESSOPEN
-unset LESSCLOSE
-
-# Keep the go folder hidden
-if which go > /dev/null 2>&1
-then
- GOPATH=$HOME/.go
- export GOPATH
+ PS1="$LOGNAME@\h:\W\$ "
fi
+export PS1
# Turn on ls colors
if which dircolors > /dev/null 2>&1
@@ -67,6 +39,16 @@ do
fi
done
+# Handy Tmux aliases
+if which tmux > /dev/null 2>&1
+then
+ alias tas=tmux\ attach-session\ -t
+ alias tns=tmux\ new-session\ -s
+ alias tls=tmux\ list-sessions
+fi
+
+alias export="export -p"
+
# Configure GPG and start the agent if it isn't already running
if which gpg-connect-agent > /dev/null 2>&1
then
@@ -84,33 +66,3 @@ then
fi
fi
fi
-
-# Append our default paths
-__appendpath ()
-{
- if [ -d "$1" ]
- then
- case ":$PATH:" in
- *:"$1":*)
- ;;
- *)
- PATH="$PATH:$1"
- esac
- fi
-}
-
-__appendpath "$HOME/.go/bin"
-__appendpath "$HOME/.cargo/bin"
-__appendpath "$HOME/.local/bin"
-
-export PATH
-
-# Handy Tmux aliases
-if which tmux > /dev/null 2>&1
-then
- alias tas=tmux\ attach-session\ -t
- alias tns=tmux\ new-session\ -s
- alias tls=tmux\ list-sessions
-fi
-
-alias export="export -p"