.profile: Cleanup and reorganize

This commit is contained in:
Salt 2018-12-19 23:15:32 -06:00
parent 849c023dca
commit ca72a7876e

View File

@ -20,64 +20,46 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
# POSIX NOTICE ## POSIX NOTICE
# This script should be fully POSIX-compliant # This script, or at least the parts expected to be run by a standard sh
# If it is not, open a bug report at gitlab.com/rehashedsalt/home and I'll take # implementation, should be fully POSIX-compliant. If it is not, open a bug
# care of it # report at gitlab.com/rehashedsalt/home and I'll take care of it.
# SHELLCHECK ## SHELLCHECK
# Not finding these sources is none of my concern; they're out of scope # Not finding these sources is none of my concern; they're out of scope
# shellcheck disable=1091 # shellcheck disable=1091
# shellcheck disable=1090 # shellcheck disable=1090
# I'm well aware of when functions are defined vs used # I'm well aware of when functions are defined vs used
# Those choices are deliberate # Those choices are deliberate
# shellcheck disable=2139 # shellcheck disable=2139
# shellcheck disable=2016 # shellcheck disable=2016
# Quit being pedantic
# shellcheck disable=1117
# Some variables will not be used here, but in the shell # Some variables will not be used here, but in the shell
# shellcheck disable=2034 # shellcheck disable=2034
# Quit being pedantic
# shellcheck disable=1117
# Environment variables # Environment variables
# First, what shell are we? # First, what shell are we?
_baseshell="$(basename -- "$0")" _baseshell="$(basename -- "$0")"
# Use Vim if we have it
export EDITOR="vi"
command -v vim > /dev/null 2>&1 && export EDITOR="vim"
alias e='$EDITOR'
# Patch PATH # Patch PATH
desiredpath="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/games:/usr/games:$HOME/.bin:$HOME/.local/bin" desiredpath="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/games:/usr/games:$HOME/.bin:$HOME/.local/bin"
# Here, we eliminate the parts of the environment-supplied PATH that we already
# plan on using
IFS=":" IFS=":"
for path in $desiredpath; do for path in $desiredpath; do
PATH="${PATH#*$path}" PATH="${PATH#*$path}"
done done
unset IFS unset IFS
# We remove any prepending colons to make it appear neater
while [ "${PATH#:}" != "$PATH" ]; do while [ "${PATH#:}" != "$PATH" ]; do
PATH="${PATH#:}" PATH="${PATH#:}"
done done
# Then finally set up our path
PATH="$desiredpath:$PATH" PATH="$desiredpath:$PATH"
# Grab dircolors, if it exists
if command -v dircolors > /dev/null 2>&1; then
dircolorsfile="$HOME/.config/dircolors"
if [ -r "$dircolorsfile" ]; then
eval "$(dircolors "$dircolorsfile")"
else
eval "$(dircolors -b)"
fi
fi
# Grab bash_completion, if it exists # Grab bash_completion, if it exists
[ -f "/etc/profile.d/bash_completion.sh" ] && . "/etc/profile.d/bash_completion.sh" [ -f "/etc/profile.d/bash_completion.sh" ] && . "/etc/profile.d/bash_completion.sh"
# Source ~/.functions, if it exists
[ -r "$HOME/.functions" ] && [ "$_baseshell" != "sh" ] && . "$HOME/.functions"
# Grab pip completion, if it exists # Grab pip completion, if it exists
if command -v pip > /dev/null 2>&1; then if command -v pip > /dev/null 2>&1; then
case "$_baseshell" in case "$_baseshell" in
@ -100,6 +82,25 @@ if command -v pip > /dev/null 2>&1; then
esac esac
fi fi
# Grab dircolors, if it exists
if command -v dircolors > /dev/null 2>&1; then
dircolorsfile="$HOME/.config/dircolors"
if [ -r "$dircolorsfile" ]; then
eval "$(dircolors "$dircolorsfile")"
else
eval "$(dircolors -b)"
fi
fi
# Set up editor aliases
for editor in vim vi nano; do
if command -v "$editor" > /dev/null 2>&1; then
export EDITOR="$editor"
break
fi
done
alias e='$EDITOR'
# If emerge exists, add emerge aliases # If emerge exists, add emerge aliases
if command -v emerge > /dev/null 2>&1 ; then if command -v emerge > /dev/null 2>&1 ; then
alias e-depclean='sudo emerge -a --depclean' alias e-depclean='sudo emerge -a --depclean'
@ -119,7 +120,7 @@ if command -v instantmusic > /dev/null 2>&1; then
alias songp='instantmusic -s' alias songp='instantmusic -s'
fi fi
# Alias for the dotfile setup # Alias for my bare repo dotfile setup
if [ -d "$HOME/.dotfiles" ]; then if [ -d "$HOME/.dotfiles" ]; then
dotcmd='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME' dotcmd='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
alias dot="$dotcmd" alias dot="$dotcmd"
@ -131,6 +132,7 @@ if [ -d "$HOME/.dotfiles" ]; then
printf 'Checking out masters...\n'; \ printf 'Checking out masters...\n'; \
$dotcmd submodule -q foreach --recursive 'git checkout -q master && git pull' && \ $dotcmd submodule -q foreach --recursive 'git checkout -q master && git pull' && \
$dotcmd status" $dotcmd status"
unset dotcmd
fi fi
# Aliases for common utilities # Aliases for common utilities
@ -153,15 +155,11 @@ else
alias ll="ls -Ahl $lsarguments" alias ll="ls -Ahl $lsarguments"
fi fi
alias cp='cp -i'
# Miscellaneous aliases # Miscellaneous aliases
alias cp='cp -i'
alias todo='$EDITOR "$HOME/Documents/todo"' alias todo='$EDITOR "$HOME/Documents/todo"'
alias waitwhat='echo $?' alias waitwhat='echo $?'
# Source ~/.functions, if it exists
[ -r "$HOME/.functions" ] && [ "$_baseshell" != "sh" ] && . "$HOME/.functions"
# Set up a default PS1 # Set up a default PS1
# This *should* work for all terminals. I know it works on ksh # This *should* work for all terminals. I know it works on ksh
_ps1() { _ps1() {