home/.profile

131 lines
3.8 KiB
Plaintext
Raw Normal View History

2017-07-30 00:04:04 -05:00
#!/bin/sh
# 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
# This script 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
# Environment variables
# Use Vim if we have it
if `which vim > /dev/null 2>&1`; then
2018-10-06 23:58:13 -05:00
export EDITOR="vim"
else
2018-10-06 23:58:13 -05:00
export EDITOR="vi"
fi
export PATH=$PATH:$HOME/.local/bin
# If emerge exists, add emerge aliases
if `which emerge > /dev/null 2>&1` ; 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 `which eclean > /dev/null 2>&1`; then
alias e-cleanup='sudo eclean -d distfiles && sudo eclean -d packages'
fi
fi
2017-07-30 00:04:04 -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"
alias dotupdate="$dotcmd submodule update --recursive --remote && $dotcmd pull && $dotcmd commit -am \"Submodules: Update\""
fi
2017-07-30 00:04:04 -05:00
# Aliases for common utilities
2018-07-14 15:15:59 -05: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
alias cp='cp -i'
# Miscellaneous aliases
alias todo='$EDITOR "$HOME/Documents/todo"'
alias waitwhat='echo $?'
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
_ps1() {
2018-08-08 17:02:11 -05:00
exitcode="$?"
2018-08-08 16:52:09 -05:00
r="\e[0m"
fg_blue="\e[34m"
fg_cyan="\e[36m"
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
2018-08-08 16:52:09 -05:00
if [ "$SSH_CLIENT" ]; then
# Also add the machine's hostname
prefix="${fg_bold}${fg_red}`hostname`${r}${fg_red}:"
2018-08-08 16:52:09 -05:00
fi
# Change PWD color depending on the shell
case $0 in
bash)
prefix="${prefix}${fg_yellow}"
;;
ksh)
prefix="${prefix}${fg_green}"
;;
sh)
prefix="${prefix}${fg_grey}"
;;
*)
;;
esac
2018-08-08 16:52:09 -05:00
# Show the tilde instead of $HOME
2018-08-28 22:07:15 -05:00
cpwd="${PWD/#$HOME/\~}"
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
printf "(${prefix}${cpwd}${r})${fail}${r}${fg_green}\$${r} "
2018-08-08 16:52:09 -05:00
}
if ! [ "$ZSH_NAME" ]; then
# I've got a different ZSH theme
export PS1='`_ps1`'
fi