home/.profile

242 lines
5.8 KiB
Plaintext
Raw Normal View History

2017-07-30 00:04:04 -05:00
#!/bin/sh
# Copyright (c) 2017 rehashedsalt/vintagesalt
# Licensed under the terms of the MIT license
2018-12-19 23:15:32 -06:00
## POSIX NOTICE
# This script, or at least the parts expected to be run by a standard sh
# implementation, should be fully POSIX-compliant. If it is not, open a bug
# report at gitlab.com/rehashedsalt/home and I'll take care of it.
2017-07-30 00:04:04 -05:00
2018-12-19 23:15:32 -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
2018-12-19 22:52:36 -06:00
# Some variables will not be used here, but in the shell
# shellcheck disable=2034
2018-12-19 23:15:32 -06:00
# Quit being pedantic
# shellcheck disable=1117
2018-11-22 02:24:19 -06:00
# Environment variables
2018-12-08 20:56:30 -06:00
_baseshell="$(basename -- "$0")"
# 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"
IFS=":"
for path in $desiredpath; do
PATH="${PATH#*$path}"
done
unset IFS
while [ "${PATH#:}" != "$PATH" ]; do
PATH="${PATH#:}"
done
PATH="$desiredpath:$PATH"
# Grab bash_completion, if it exists
[ -f "/etc/profile.d/bash_completion.sh" ] && . "/etc/profile.d/bash_completion.sh"
2018-12-19 23:15:32 -06:00
# Source ~/.functions, if it exists
[ -r "$HOME/.functions" ] \
&& [ "$_baseshell" != "sh" ] \
&& [ "$_baseshell" != "dash" ] \
&& . "$HOME/.functions"
2018-12-19 23:15:32 -06:00
# Define a require function
has() {
[ -z "$1" ] && return 1
command -v "$1" > /dev/null 2>&1
}
# Grab pip completion, if it exists
if has pip; then
case "$_baseshell" in
*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"
;;
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"
;;
*)
;;
esac
fi
2019-01-25 16:56:06 -06:00
# Set up go, if we have it
if has go; then
2019-01-25 16:56:06 -06:00
export GOPATH="$HOME/.local/go"
2019-02-01 14:42:51 -06:00
[ "${PATH#*$GOPATH}" = "$PATH" ] && export PATH="$PATH:$GOPATH/bin"
2019-01-25 16:56:06 -06:00
fi
2018-12-19 23:15:32 -06:00
# Grab dircolors, if it exists
if has dircolors; then
2018-12-19 23:15:32 -06:00
dircolorsfile="$HOME/.config/dircolors"
if [ -r "$dircolorsfile" ]; then
eval "$(dircolors "$dircolorsfile")"
else
eval "$(dircolors -b)"
fi
fi
# Set up our text editor
2018-12-19 23:15:32 -06:00
for editor in vim vi nano; do
2019-06-19 16:04:48 -05:00
if has "$editor"; then
2018-12-19 23:15:32 -06:00
export EDITOR="$editor"
break
fi
done
alias e='$EDITOR'
# Now for a shitton of aliases
if ! has define; then
if has mate-dictionary; then
alias define='mate-dictionary -n --look-up'
fi
fi
if has emerge; then
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'
alias e-search='emerge -s'
alias e-sync='sudo emerge --sync'
if has eclean; then
alias e-cleanup='sudo eclean -d distfiles && sudo eclean -d packages'
fi
fi
if has instantmusic; then
alias song='instantmusic -p -s'
alias songp='instantmusic -s'
fi
2019-06-19 16:04:48 -05:00
if has sudo; then
case $_baseshell in
*bash|*zsh)
export SUDO_PROMPT=$'[\e[34msudo\e[0m as %U]: Password for %p: '
;;
*)
export SUDO_PROMPT='[sudo as %U]: Password for %p: '
esac
fi
# Dotfile management aliases
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
printf 'Updating submodules...\n'; \
$dotcmd submodule update --init; \
printf 'Checking out masters...\n'; \
$dotcmd submodule -q foreach --recursive 'git checkout -q master && git pull' && \
2018-10-10 16:31:54 -05:00
$dotcmd status"
2018-12-19 23:15:32 -06:00
unset dotcmd
fi
2017-07-30 00:04:04 -05:00
# Aliases for common utilities
2018-11-22 02:24:19 -06:00
if [ "$(uname)" = "Linux" ]; then
# Assume we have GNU coreutils
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
alias rm='rm -I'
else
# Else only assume POSIX/BSD
lsarguments='-F'
alias l="ls -$lsarguments"
alias la="ls -A $lsarguments"
alias ls="ls $lsarguments"
alias ll="ls -Ahl $lsarguments"
fi
2018-12-19 23:15:32 -06:00
alias cp='cp -i'
alias d='du -hs'
alias todo='$EDITOR "$HOME/Documents/todo"'
2017-07-30 00:04:04 -05: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"
fg_yellow="\e[33m"
fg_grey="\e[37m"
2018-08-08 16:52:09 -05:00
fg_bold="\e[1m"
# Add hostname prefix in SSH sessions
# Yes, shellcheck. I get it. That's what the or is for
#shellcheck disable=2039
if [ "$HOSTNAME" = "phys-saltshaker" ] || [ "$(hostname)" = "phys-saltshaker" ]; then
2018-12-15 20:46:19 -06:00
prefix="${fg_bold}${fg_grey}ss${r}${fg_grey}:${r}"
fi
2018-08-08 16:52:09 -05:00
if [ "$SSH_CLIENT" ]; then
2018-12-15 20:46:19 -06:00
prefix="${fg_bold}${fg_red}$(hostname)${r}${fg_red}:${r}${prefix}"
2018-08-08 16:52:09 -05:00
fi
# Append "vim" in Vim
if [ -n "$VIM_TERMINAL" ]; then
prefix="${fg_bold}${fg_green}*${r}"
fi
# Change PWD color depending on the shell
case $0 in
*bash)
2018-12-01 16:48:24 -06:00
prefix="${prefix}${fg_blue}"
;;
/bin/ksh)
prefix="${prefix}${fg_green}"
;;
/bin/sh)
prefix="${prefix}${fg_grey}"
;;
*)
;;
esac
2018-08-08 16:52:09 -05:00
# Show the tilde instead of $HOME
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
}
# And export our PS1
case "$_baseshell" in
zsh)
# Don't do this on ZSH
# I have a custom theme for that
;;
sh|dash)
export PS1='\$ '
;;
*)
export PS1='$(_ps1)'
;;
esac
# Clean up
unset -v _baseshell
unset -f has
2018-08-08 16:52:09 -05:00