2017-07-30 00:04:04 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
2017-08-16 16:30:51 -05:00
|
|
|
# Copyright (c) 2017 rehashedsalt/vintagesalt
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
2017-07-30 00:04:04 -05:00
|
|
|
# POSIX NOTICE
|
2017-08-16 14:30:47 -05:00
|
|
|
# This script should be fully POSIX-compliant
|
2018-09-19 17:49:08 -05:00
|
|
|
# If it is not, open a bug report at gitlab.com/rehashedsalt/home and I'll take
|
2017-08-16 14:30:47 -05:00
|
|
|
# care of it
|
2017-07-30 00:04:04 -05:00
|
|
|
|
2018-11-27 22:02:39 -06:00
|
|
|
# SHELLCHECK
|
2018-11-22 02:24:19 -06:00
|
|
|
# Not finding these sources is none of my concern; they're out of scope
|
|
|
|
# shellcheck disable=1091
|
|
|
|
# shellcheck disable=1090
|
|
|
|
|
|
|
|
# I'm well aware of when functions are defined vs used
|
|
|
|
# Those choices are deliberate
|
|
|
|
# shellcheck disable=2139
|
|
|
|
# shellcheck disable=2016
|
|
|
|
|
|
|
|
# Quit being pedantic
|
|
|
|
# shellcheck disable=1117
|
|
|
|
|
2018-08-21 18:45:52 -05:00
|
|
|
# Environment variables
|
2018-11-27 23:24:17 -06:00
|
|
|
# First, what shell are we?
|
2018-12-08 20:56:30 -06:00
|
|
|
_baseshell="$(basename -- "$0")"
|
2018-11-27 23:24:17 -06:00
|
|
|
|
2018-08-21 18:45:52 -05:00
|
|
|
# Use Vim if we have it
|
2018-11-21 23:16:02 -06:00
|
|
|
export EDITOR="vi"
|
2018-11-22 02:24:19 -06:00
|
|
|
command -v vim > /dev/null 2>&1 && export EDITOR="vim"
|
2018-11-23 18:43:23 -06:00
|
|
|
alias e='$EDITOR'
|
2018-08-21 18:45:52 -05:00
|
|
|
|
2018-11-21 15:33:07 -06:00
|
|
|
# Patch PATH
|
2018-11-21 23:34:43 -06:00
|
|
|
desiredpath="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/games:/usr/games:$HOME/.bin:$HOME/.local/bin"
|
2018-11-21 15:33:07 -06:00
|
|
|
# Here, we eliminate the parts of the environment-supplied PATH that we already
|
|
|
|
# plan on using
|
|
|
|
IFS=":"
|
|
|
|
for path in $desiredpath; do
|
|
|
|
PATH="${PATH#*$path}"
|
|
|
|
done
|
|
|
|
unset IFS
|
|
|
|
# We remove any prepending colons to make it appear neater
|
2018-11-21 15:38:34 -06:00
|
|
|
while [ "${PATH#:}" != "$PATH" ]; do
|
|
|
|
PATH="${PATH#:}"
|
2018-11-21 15:33:07 -06:00
|
|
|
done
|
|
|
|
# Then finally set up our path
|
|
|
|
PATH="$desiredpath:$PATH"
|
|
|
|
|
2018-12-01 11:31:29 -06:00
|
|
|
# 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
|
|
|
|
|
2018-11-21 15:33:07 -06:00
|
|
|
# Grab bash_completion, if it exists
|
|
|
|
[ -f "/etc/profile.d/bash_completion.sh" ] && . "/etc/profile.d/bash_completion.sh"
|
2018-08-21 18:45:52 -05:00
|
|
|
|
2018-11-21 23:16:02 -06:00
|
|
|
# Grab pip completion, if it exists
|
2018-11-22 02:24:19 -06:00
|
|
|
if command -v pip > /dev/null 2>&1; then
|
2018-11-27 23:24:17 -06:00
|
|
|
case "$_baseshell" in
|
2018-11-21 23:16:02 -06:00
|
|
|
*bash)
|
|
|
|
if ! [ -f "$HOME/.pip-completion-bash" ]; then
|
|
|
|
pip completion --bash > "$HOME/.pip-completion-bash"
|
|
|
|
echo ".profile: Created pip completion for bash"
|
|
|
|
fi
|
2018-11-22 02:24:19 -06:00
|
|
|
. "$HOME/.pip-completion-bash"
|
2018-11-21 23:16:02 -06:00
|
|
|
;;
|
|
|
|
zsh)
|
|
|
|
if ! [ -f "$HOME/.pip-completion-zsh" ]; then
|
|
|
|
pip completion --zsh > "$HOME/.pip-completion-zsh"
|
|
|
|
echo ".profile: Created pip completion for zsh"
|
|
|
|
fi
|
2018-11-22 02:24:19 -06:00
|
|
|
. "$HOME/.pip-completion-zsh"
|
2018-11-21 23:16:02 -06:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2017-08-16 14:30:47 -05:00
|
|
|
# If emerge exists, add emerge aliases
|
2018-11-22 02:24:19 -06:00
|
|
|
if command -v emerge > /dev/null 2>&1 ; then
|
2017-08-16 14:30:47 -05:00
|
|
|
alias e-depclean='sudo emerge -a --depclean'
|
2018-08-10 21:45:44 -05:00
|
|
|
alias e-inst='sudo emerge -a --jobs --tree --quiet-build y'
|
2018-08-19 20:18:11 -05:00
|
|
|
alias e-upgrade='sudo emerge -DNUua --jobs --tree --quiet-build y --with-bdeps=y --keep-going --backtrack=1000 @world'
|
2018-08-16 14:59:51 -05:00
|
|
|
alias e-newuse='sudo emerge -Uva --jobs --tree --quiet-build y @world'
|
2017-08-16 14:30:47 -05:00
|
|
|
alias e-search='emerge -s'
|
|
|
|
alias e-sync='sudo emerge --sync'
|
2018-11-22 02:24:19 -06:00
|
|
|
if command -v eclean > /dev/null 2>&1; then
|
2018-08-21 18:38:18 -05:00
|
|
|
alias e-cleanup='sudo eclean -d distfiles && sudo eclean -d packages'
|
|
|
|
fi
|
2017-08-16 14:30:47 -05:00
|
|
|
fi
|
2017-07-30 00:04:04 -05:00
|
|
|
|
2018-11-21 23:24:34 -06:00
|
|
|
# If we have instantmusic, add aliases for that
|
2018-11-22 02:24:19 -06:00
|
|
|
if command -v instantmusic > /dev/null 2>&1; then
|
2018-11-21 23:32:37 -06:00
|
|
|
alias song='instantmusic -p -s'
|
2018-11-21 23:40:39 -06:00
|
|
|
alias songp='instantmusic -s'
|
2018-11-21 23:24:34 -06:00
|
|
|
fi
|
|
|
|
|
2017-08-16 14:30:47 -05:00
|
|
|
# Alias for the dotfile setup
|
|
|
|
if [ -d "$HOME/.dotfiles" ]; then
|
2018-10-10 16:24:35 -05:00
|
|
|
dotcmd='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
|
|
|
|
alias dot="$dotcmd"
|
2018-10-10 16:31:54 -05:00
|
|
|
alias dotupdate="\
|
2018-10-30 14:23:15 -05:00
|
|
|
printf 'Pulling...\n'; \
|
|
|
|
$dotcmd pull
|
2018-10-10 16:36:43 -05:00
|
|
|
printf 'Updating submodules...\n'; \
|
2018-10-30 14:08:42 -05:00
|
|
|
$dotcmd submodule update --init; \
|
|
|
|
printf 'Checking out masters...\n'; \
|
2018-10-10 16:36:43 -05:00
|
|
|
$dotcmd submodule -q foreach --recursive 'git checkout -q master && git pull' && \
|
2018-10-10 16:31:54 -05:00
|
|
|
$dotcmd status"
|
2017-08-16 14:30:47 -05:00
|
|
|
fi
|
2017-07-30 00:04:04 -05:00
|
|
|
|
2017-08-16 14:30:47 -05:00
|
|
|
# Aliases for common utilities
|
2018-11-22 02:24:19 -06:00
|
|
|
if [ "$(uname)" = "Linux" ]; then
|
2018-10-07 00:02:13 -05:00
|
|
|
# Assume we have GNU coreutils
|
2018-07-14 14:55:36 -05:00
|
|
|
lsarguments='--color=auto --group-directories-first'
|
|
|
|
alias l="ls -CF --file-type $lsarguments"
|
|
|
|
alias la="ls -AF --file-type $lsarguments"
|
|
|
|
alias ls="ls -F $lsarguments"
|
|
|
|
alias ll="ls -AhlF --file-type $lsarguments"
|
|
|
|
unset lsarguments
|
2018-08-21 18:45:52 -05:00
|
|
|
|
|
|
|
alias rm='rm -I'
|
2018-07-14 14:55:36 -05:00
|
|
|
else
|
2018-10-07 00:02:13 -05:00
|
|
|
# Else only assume POSIX/BSD
|
2018-07-14 14:55:36 -05:00
|
|
|
lsarguments='-F'
|
|
|
|
alias l="ls -$lsarguments"
|
|
|
|
alias la="ls -A $lsarguments"
|
|
|
|
alias ls="ls $lsarguments"
|
|
|
|
alias ll="ls -Ahl $lsarguments"
|
|
|
|
fi
|
|
|
|
|
2018-08-21 18:45:52 -05:00
|
|
|
alias cp='cp -i'
|
|
|
|
|
|
|
|
# Miscellaneous aliases
|
|
|
|
alias todo='$EDITOR "$HOME/Documents/todo"'
|
2017-08-16 14:30:47 -05:00
|
|
|
alias waitwhat='echo $?'
|
2017-07-30 00:04:04 -05:00
|
|
|
|
2018-11-06 17:39:56 -06:00
|
|
|
# Source ~/.functions, if it exists
|
2018-12-01 11:31:29 -06:00
|
|
|
[ -r "$HOME/.functions" ] && [ "$_baseshell" != "sh" ] && . "$HOME/.functions"
|
2018-11-06 17:39:56 -06:00
|
|
|
|
2018-08-08 16:52:09 -05:00
|
|
|
# Set up a default PS1
|
|
|
|
# This *should* work for all terminals. I know it works on ksh
|
2018-11-22 02:24:19 -06:00
|
|
|
_ps1() {
|
2018-08-08 17:02:11 -05:00
|
|
|
exitcode="$?"
|
2018-08-08 16:52:09 -05:00
|
|
|
r="\e[0m"
|
2018-12-01 16:48:24 -06:00
|
|
|
fg_blue="\e[34m"
|
2018-08-08 16:52:09 -05:00
|
|
|
fg_red="\e[31m"
|
|
|
|
fg_green="\e[32m"
|
2018-10-03 22:50:23 -05:00
|
|
|
fg_yellow="\e[33m"
|
|
|
|
fg_grey="\e[37m"
|
2018-08-08 16:52:09 -05:00
|
|
|
fg_bold="\e[1m"
|
|
|
|
|
2018-10-07 00:15:04 -05:00
|
|
|
# Add hostname prefix in SSH sessions
|
2018-12-15 20:41:57 -06:00
|
|
|
# Yes, shellcheck. I get it. That's what the or is for
|
|
|
|
#shellcheck disable=2039
|
|
|
|
if [ "$HOSTNAME" = "phys-saltshaker" ] || [ "$(hostname)" = "phys-saltshaker" ]; then
|
|
|
|
prefix="${fg_bold}${fg_yellow}ss${r}"
|
|
|
|
fi
|
2018-08-08 16:52:09 -05:00
|
|
|
if [ "$SSH_CLIENT" ]; then
|
2018-12-15 20:41:57 -06:00
|
|
|
prefix="${fg_bold}${fg_red}$(hostname)${r}${fg_red}:${prefix}"
|
2018-08-08 16:52:09 -05:00
|
|
|
fi
|
2018-11-02 21:40:38 -05:00
|
|
|
# Append a "restricted" prefix in rbash
|
2018-11-22 02:24:19 -06:00
|
|
|
if [ "$0" = "rbash" ]; then
|
2018-11-02 21:40:38 -05:00
|
|
|
prefix="${fg_bold}${fg_grey}rbash${r}:"
|
|
|
|
fi
|
2018-10-07 00:15:04 -05:00
|
|
|
# Change PWD color depending on the shell
|
2018-10-03 22:50:23 -05:00
|
|
|
case $0 in
|
2018-11-02 21:40:38 -05:00
|
|
|
*bash)
|
2018-12-01 16:48:24 -06:00
|
|
|
prefix="${prefix}${fg_blue}"
|
2018-10-03 22:50:23 -05:00
|
|
|
;;
|
2018-11-27 23:24:17 -06:00
|
|
|
/bin/ksh)
|
2018-10-07 00:15:04 -05:00
|
|
|
prefix="${prefix}${fg_green}"
|
2018-10-03 22:50:23 -05:00
|
|
|
;;
|
2018-11-27 23:24:17 -06:00
|
|
|
/bin/sh)
|
2018-10-07 00:15:04 -05:00
|
|
|
prefix="${prefix}${fg_grey}"
|
2018-10-03 22:50:23 -05:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
2018-08-08 16:52:09 -05:00
|
|
|
# Show the tilde instead of $HOME
|
2018-11-27 22:02:39 -06:00
|
|
|
if [ "${PWD#$HOME}" != "$PWD" ]; then
|
|
|
|
cpwd="~${PWD#$HOME}"
|
|
|
|
else
|
|
|
|
cpwd="$PWD"
|
|
|
|
fi
|
2018-08-08 16:52:09 -05:00
|
|
|
# Alert us if the last command failed
|
|
|
|
fail=""
|
2018-08-08 17:02:11 -05:00
|
|
|
if ! [ "$exitcode" = "0" ]; then
|
2018-08-08 16:52:09 -05:00
|
|
|
fail="${fg_bold}${fg_red}?"
|
|
|
|
fi
|
2018-11-22 02:24:19 -06:00
|
|
|
# shellcheck disable=2059
|
2018-11-06 18:36:04 -06:00
|
|
|
printf "[${prefix}${cpwd}${r}]${fail}${r}${fg_green}\$${r} "
|
2018-08-08 16:52:09 -05:00
|
|
|
}
|
|
|
|
|
2018-11-27 23:24:17 -06:00
|
|
|
# And export our PS1
|
|
|
|
case "$_baseshell" in
|
|
|
|
zsh)
|
|
|
|
# Don't do this on ZSH
|
|
|
|
# I have a custom theme for that
|
|
|
|
;;
|
|
|
|
sh)
|
2018-12-01 11:31:29 -06:00
|
|
|
export PS1='\$ '
|
2018-11-27 23:24:17 -06:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
export PS1='$(_ps1)'
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Clean up
|
|
|
|
unset _baseshell
|
2018-08-08 16:52:09 -05:00
|
|
|
|