2017-07-30 00:04:04 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
2017-08-16 16:30:51 -05:00
|
|
|
# Copyright (c) 2017 rehashedsalt/vintagesalt
|
2019-07-10 04:31:05 -05:00
|
|
|
# Licensed under the terms of the MIT license
|
2017-08-16 16:30:51 -05:00
|
|
|
|
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
|
2020-06-01 16:21:43 -05:00
|
|
|
# report at git.9iron.club/salt/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
|
|
|
|
2018-08-21 18:45:52 -05:00
|
|
|
# Environment variables
|
2018-12-08 20:56:30 -06:00
|
|
|
_baseshell="$(basename -- "$0")"
|
2018-11-27 23:24:17 -06:00
|
|
|
|
2018-11-21 15:33:07 -06:00
|
|
|
# Patch PATH
|
2020-04-03 06:55:31 -05:00
|
|
|
for dir in \
|
2020-06-01 16:21:43 -05:00
|
|
|
"$HOME/.bin" \
|
|
|
|
"$HOME/.local/bin" \
|
|
|
|
"$HOME/.firestarter" \
|
2020-04-03 06:55:31 -05:00
|
|
|
"/usr/local/opt/coreutils/libexec/gnubin" \
|
2020-04-04 04:20:33 -05:00
|
|
|
"/usr/local/opt/gnu-sed/libexec/gnubin" \
|
2020-04-04 07:19:38 -05:00
|
|
|
"/usr/local/opt/grep/libexec/gnubin" \
|
2020-04-03 06:55:31 -05:00
|
|
|
"/usr/local/opt/util-linux/bin" \
|
|
|
|
"/usr/local/opt/util-linux/sbin"
|
|
|
|
do
|
|
|
|
if [ -d "$dir" ]; then
|
|
|
|
PATH="$dir:$PATH"
|
|
|
|
fi
|
|
|
|
done
|
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-12-19 23:15:32 -06:00
|
|
|
# Source ~/.functions, if it exists
|
2019-02-05 15:17:50 -06:00
|
|
|
[ -r "$HOME/.functions" ] \
|
|
|
|
&& [ "$_baseshell" != "sh" ] \
|
|
|
|
&& [ "$_baseshell" != "dash" ] \
|
|
|
|
&& . "$HOME/.functions"
|
2018-12-19 23:15:32 -06:00
|
|
|
|
2019-02-05 12:38:56 -06:00
|
|
|
# Define a require function
|
|
|
|
has() {
|
|
|
|
[ -z "$1" ] && return 1
|
|
|
|
command -v "$1" > /dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2020-04-16 23:53:49 -05:00
|
|
|
# Doot
|
|
|
|
if ! has doot; then
|
|
|
|
alias doot="echo Doot doot."
|
|
|
|
fi
|
|
|
|
|
2018-11-21 23:16:02 -06:00
|
|
|
# Grab pip completion, if it exists
|
2019-02-05 12:38:56 -06:00
|
|
|
if has pip; 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
|
|
|
|
|
2019-01-25 16:56:06 -06:00
|
|
|
# Set up go, if we have it
|
2019-02-05 12:38:56 -06:00
|
|
|
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
|
2019-02-05 12:38:56 -06:00
|
|
|
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
|
|
|
|
|
2019-07-10 04:31:05 -05:00
|
|
|
# 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'
|
|
|
|
|
2019-07-10 04:31:05 -05:00
|
|
|
# Now for a shitton of aliases
|
|
|
|
if ! has define; then
|
|
|
|
if has mate-dictionary; then
|
|
|
|
alias define='mate-dictionary -n --look-up'
|
|
|
|
fi
|
|
|
|
fi
|
2020-06-26 12:02:42 -05:00
|
|
|
if ! has helpme; then
|
|
|
|
# https://breanneboland.com/blog/2020/02/28/you-can-put-what-in-dns-txt-records-a-blog-post-for-con-west-2020/
|
|
|
|
alias helpme='dig +short txt "$(( RANDOM % 50 )).maybethiscould.work"'
|
|
|
|
fi
|
2019-02-05 12:38:56 -06:00
|
|
|
if has emerge; 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'
|
2019-02-05 12:38:56 -06:00
|
|
|
if has eclean; 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
|
2020-06-15 09:52:09 -05:00
|
|
|
if has firestarter and ! has fs; then
|
|
|
|
alias fs="firestarter"
|
|
|
|
fi
|
2020-06-01 17:41:31 -05:00
|
|
|
if has fork; then
|
|
|
|
alias dup="fork $TERMINAL $PWD"
|
|
|
|
fi
|
2019-09-01 21:34:02 -05:00
|
|
|
if has git; then
|
|
|
|
# Thanks Bash-it!
|
|
|
|
alias g='git'
|
|
|
|
alias ga='git add'
|
|
|
|
alias gall='git add -A'
|
|
|
|
alias gap='git add -p'
|
|
|
|
alias gb='git branch'
|
|
|
|
alias gbD='git branch -D'
|
|
|
|
alias gba='git branch -a'
|
|
|
|
alias gbd='git branch -d'
|
|
|
|
alias gbm='git branch -m'
|
|
|
|
alias gbt='git branch --track'
|
|
|
|
alias gc='git commit -v'
|
|
|
|
alias gca='git commit -v -a'
|
|
|
|
alias gcam="git commit -v -am"
|
|
|
|
alias gcb='git checkout -b'
|
|
|
|
alias gci='git commit --interactive'
|
|
|
|
alias gcl='git clone'
|
|
|
|
alias gclean='git clean -fd'
|
|
|
|
alias gcm='git commit -v -m'
|
|
|
|
alias gco='git checkout'
|
|
|
|
alias gcob='git checkout -b'
|
|
|
|
alias gcom='git checkout master'
|
|
|
|
alias gcount='git shortlog -sn'
|
|
|
|
alias gcp='git cherry-pick'
|
|
|
|
alias gcpd='git checkout master; git pull; git branch -D'
|
|
|
|
alias gcpx='git cherry-pick -x'
|
|
|
|
alias gcsam="git commit -S -am"
|
|
|
|
alias gct='git checkout --track'
|
|
|
|
alias gd='git diff'
|
|
|
|
alias gdel='git branch -D'
|
|
|
|
alias gds='git diff --staged'
|
|
|
|
alias gdv='git diff -w "$@" | vim -R -'
|
|
|
|
alias get='git'
|
|
|
|
alias gexport='git archive --format zip --output'
|
|
|
|
alias gf='git fetch --all --prune'
|
|
|
|
alias gft='git fetch --all --prune --tags'
|
|
|
|
alias gftv='git fetch --all --prune --tags --verbose'
|
|
|
|
alias gfv='git fetch --all --prune --verbose'
|
|
|
|
alias ggs="gg --stat"
|
|
|
|
alias ggui="git gui"
|
|
|
|
alias gh='cd "$(git rev-parse --show-toplevel)"'
|
|
|
|
alias gl='git pull'
|
|
|
|
alias gll='git log --graph --pretty=oneline --abbrev-commit'
|
|
|
|
alias glum='git pull upstream master'
|
|
|
|
alias gm="git merge"
|
|
|
|
alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/master'
|
|
|
|
alias gmv='git mv'
|
|
|
|
alias gp='git push'
|
|
|
|
alias gpatch="git format-patch -1"
|
|
|
|
alias gpo='git push origin'
|
|
|
|
alias gpom='git push origin master'
|
|
|
|
alias gpp='git pull && git push'
|
|
|
|
alias gpr='git pull --rebase'
|
|
|
|
alias gpristine='git reset --hard && git clean -dfx'
|
|
|
|
alias gpu='git push --set-upstream'
|
|
|
|
alias gpuo='git push --set-upstream origin'
|
|
|
|
alias gpuoc='git push --set-upstream origin $(git symbolic-ref --short HEAD)'
|
|
|
|
alias gr='git remote'
|
|
|
|
alias gra='git remote add'
|
|
|
|
alias grm='git rm'
|
|
|
|
alias grv='git remote -v'
|
|
|
|
alias gs='git status'
|
|
|
|
alias gsl="git shortlog -sn"
|
|
|
|
alias gss='git status -s'
|
|
|
|
alias gst="git stash"
|
|
|
|
alias gstb="git stash branch"
|
|
|
|
alias gstd="git stash drop"
|
|
|
|
alias gstl="git stash list"
|
|
|
|
alias gstp="git stash pop"
|
|
|
|
alias gsu='git submodule update --init --recursive'
|
|
|
|
alias gt="git tag"
|
|
|
|
alias gta="git tag -a"
|
|
|
|
alias gtd="git tag -d"
|
|
|
|
alias gtl="git tag -l"
|
|
|
|
alias gtls='git tag -l | sort -V'
|
|
|
|
alias gup='git fetch && git rebase'
|
|
|
|
alias gus='git reset HEAD'
|
|
|
|
alias gwc="git whatchanged"
|
|
|
|
# Add uncommitted and unstaged changes to the last commit
|
|
|
|
alias gcaa="git commit -a --amend -C HEAD"
|
|
|
|
# From http://blogs.atlassian.com/2014/10/advanced-git-aliases/
|
|
|
|
# Show commits since last pull
|
|
|
|
alias gnew="git log HEAD@{1}..HEAD@{0}"
|
|
|
|
# Show untracked files
|
|
|
|
alias gu='git ls-files . --exclude-standard --others'
|
|
|
|
fi
|
2020-03-26 05:13:32 -05:00
|
|
|
if has nc; then
|
|
|
|
# I'm not sorry
|
|
|
|
alias blinkenlights='nc -v towel.blinkenlights.nl 23'
|
|
|
|
fi
|
2019-10-21 00:13:10 -05:00
|
|
|
if has ptgdp; then
|
|
|
|
song() {
|
|
|
|
if [ -z "$*" ]; then
|
|
|
|
echo "song: Requires an argument"
|
|
|
|
return 1
|
|
|
|
fi
|
2019-10-23 23:35:14 -05:00
|
|
|
echo "$*" | ptgdp -p
|
2019-10-21 00:13:10 -05:00
|
|
|
}
|
2020-08-02 19:56:10 -05:00
|
|
|
fi
|
|
|
|
if has sed && has find; then
|
|
|
|
replace() {
|
|
|
|
if [ $# -ne 2 ]; then
|
|
|
|
echo "replace: Requires two arguments"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
find . -type f -exec sed -i "s/$1/$2/g" {} \;
|
|
|
|
}
|
2019-10-21 00:13:10 -05:00
|
|
|
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
|
2020-06-01 05:50:15 -05:00
|
|
|
if has tree; then
|
2020-06-01 05:58:57 -05:00
|
|
|
treeargs='-qF --dirsfirst'
|
|
|
|
alias tree="tree $treeargs"
|
|
|
|
alias t="tree $treeargs -L 2"
|
|
|
|
alias tl="tree $treeargs -pughL 2"
|
|
|
|
alias tp="tree $treeargs -pL 2"
|
|
|
|
alias ts="tree $treeargs -hL 2"
|
|
|
|
unset treeargs
|
2020-06-01 05:50:15 -05:00
|
|
|
fi
|
2020-06-14 04:54:31 -05:00
|
|
|
if has vault; then
|
|
|
|
alias vlogin="vault login -method=ldap username=$(whoami)"
|
|
|
|
alias vls="vault list"
|
|
|
|
alias vr="vault read"
|
|
|
|
fi
|
2019-06-19 16:04:48 -05:00
|
|
|
|
2019-07-10 04:31:05 -05:00
|
|
|
# Dotfile management aliases
|
2017-08-16 14:30:47 -05:00
|
|
|
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"
|
2020-07-18 00:24:31 -05:00
|
|
|
if [ -f "/usr/share/bash-completion/completions/git" ] && [ "$_baseshell" == "bash" ]; then
|
|
|
|
. "/usr/share/bash-completion/completions/git"
|
|
|
|
__git_complete dot _git
|
|
|
|
fi
|
2018-10-10 16:31:54 -05:00
|
|
|
alias dotupdate="\
|
2020-06-30 09:29:45 -05:00
|
|
|
printf 'Pulling...\n'
|
2018-10-30 14:23:15 -05:00
|
|
|
$dotcmd pull
|
2020-06-30 09:29:45 -05:00
|
|
|
printf 'Updating submodules...\n'
|
2020-06-30 09:54:29 -05:00
|
|
|
$dotcmd submodule update --init --recursive --remote
|
2020-06-30 09:29:45 -05:00
|
|
|
$dotcmd status"
|
|
|
|
alias dotupgrade="\
|
|
|
|
printf 'Pulling...\n'
|
|
|
|
$dotcmd pull
|
|
|
|
printf 'Updating submodules...\n'
|
|
|
|
$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"
|
2018-12-19 23:15:32 -06:00
|
|
|
unset dotcmd
|
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
|
2020-04-03 08:10:46 -05:00
|
|
|
if [ "$(uname)" = "Linux" ] || has brew; then
|
2018-10-07 00:02:13 -05:00
|
|
|
# Assume we have GNU coreutils
|
2020-02-17 17:13:41 -06:00
|
|
|
lsarguments='-Fh --color=auto --group-directories-first'
|
|
|
|
alias l="ls -l --file-type $lsarguments"
|
|
|
|
alias la="ls -A --file-type $lsarguments"
|
|
|
|
alias ls="ls $lsarguments"
|
|
|
|
alias ll="ls -Al --file-type $lsarguments"
|
2018-07-14 14:55:36 -05:00
|
|
|
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-12-19 23:15:32 -06:00
|
|
|
alias cp='cp -i'
|
2019-07-10 04:31:05 -05:00
|
|
|
alias d='du -hs'
|
2017-07-30 00:04:04 -05:00
|
|
|
|
2019-10-24 00:20:03 -05:00
|
|
|
# Set up a default PS1 for bash
|
|
|
|
_ps1bash() {
|
2018-08-08 17:02:11 -05:00
|
|
|
exitcode="$?"
|
2019-10-24 00:20:03 -05:00
|
|
|
r="\[\e[0m\]"
|
|
|
|
bg_red="\[\e[41m\]"
|
|
|
|
bg_yellow="\[\e[43m\]"
|
|
|
|
bg_blue="\[\e[44m\]"
|
|
|
|
fg_black="\[\e[30m\]"
|
|
|
|
fg_red="\[\e[31m\]"
|
|
|
|
fg_green="\[\e[32m\]"
|
|
|
|
fg_yellow="\[\e[33m\]"
|
|
|
|
fg_blue="\[\e[34m\]"
|
|
|
|
fg_magenta="\[\e[35m\]"
|
|
|
|
fg_grey="\[\e[37m\]"
|
|
|
|
fg_bold="\[\e[1m\]"
|
2018-08-08 16:52:09 -05:00
|
|
|
|
2018-10-07 00:15:04 -05:00
|
|
|
# Add hostname prefix in SSH sessions
|
2019-11-19 15:17:43 -06:00
|
|
|
unset prefix
|
2020-01-15 14:13:44 -06:00
|
|
|
# Alert if in an SSH session
|
2020-01-15 14:21:04 -06:00
|
|
|
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
2020-04-03 03:50:42 -05:00
|
|
|
prefix="${fg_bold}${fg_red}$(hostname -s)${r}${fg_red}:${r}${prefix}"
|
2018-11-02 21:40:38 -05:00
|
|
|
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
|
|
|
;;
|
2020-01-15 14:13:44 -06:00
|
|
|
*ksh)
|
2018-10-07 00:15:04 -05:00
|
|
|
prefix="${prefix}${fg_green}"
|
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
|
2019-09-18 03:29:48 -05:00
|
|
|
# Show read-only status in certain directories
|
|
|
|
if [ "$UID" = 0 ]; then
|
2020-08-24 10:02:14 -05:00
|
|
|
# Root gets the usual "#" prompt
|
2019-09-18 03:29:48 -05:00
|
|
|
prompt="${fg_red}#${r}"
|
|
|
|
elif ! [ -d "$PWD" ]; then
|
2020-08-24 10:02:14 -05:00
|
|
|
# Something very bad has happened to our PWD, probably got deleted
|
2019-09-18 03:29:48 -05:00
|
|
|
prompt="${bg_red}${fg_black}!${r}"
|
|
|
|
elif ! [ -r "$PWD" ]; then
|
2020-08-24 10:02:14 -05:00
|
|
|
# Guess we lost privileges
|
2019-09-18 03:29:48 -05:00
|
|
|
prompt="${fg_red}"'$'"${r}"
|
|
|
|
elif ! [ -x "$PWD" ]; then
|
2020-08-24 10:02:14 -05:00
|
|
|
# Missing execution perms
|
2019-09-18 03:29:48 -05:00
|
|
|
if [ -w "$PWD" ]; then
|
|
|
|
# Fixable
|
|
|
|
prompt="${bg_blue}${fg_black}"'$'"${r}"
|
|
|
|
else
|
|
|
|
# Unfixable
|
|
|
|
prompt="${bg_yellow}${fg_black}"'$'"${r}"
|
|
|
|
fi
|
|
|
|
elif ! [ -w "$PWD" ]; then
|
|
|
|
# Can't write is really common but also good to know
|
|
|
|
prompt="${fg_magenta}"'~'"${r}"
|
|
|
|
else
|
|
|
|
# Otherwise we should be fine
|
|
|
|
prompt="${fg_green}"'$'"${r}"
|
|
|
|
fi
|
2018-08-08 16:52:09 -05:00
|
|
|
# Alert us if the last command failed
|
2019-09-01 21:34:02 -05:00
|
|
|
unset 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
|
2019-10-24 00:20:03 -05:00
|
|
|
PS1="[${prefix}${cpwd}${r}]${fail}${r}${prompt}${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
|
|
|
|
;;
|
2019-10-24 00:20:03 -05:00
|
|
|
*bash)
|
|
|
|
export PS1=""
|
|
|
|
export PROMPT_COMMAND=_ps1bash
|
2018-11-27 23:24:17 -06:00
|
|
|
;;
|
|
|
|
*)
|
2019-09-01 21:34:02 -05:00
|
|
|
export PS1='[\e[31m\w\e[0m]\e[32m\$\e[0m '
|
2018-11-27 23:24:17 -06:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Clean up
|
2020-03-28 08:56:32 -05:00
|
|
|
unset gnubin
|
2019-02-05 12:38:56 -06:00
|
|
|
unset -v _baseshell
|
|
|
|
unset -f has
|
2018-08-08 16:52:09 -05:00
|
|
|
|
2020-04-03 03:41:15 -05:00
|
|
|
# Source in a site-specific profile
|
|
|
|
localprofile="$HOME/.local/profile"
|
|
|
|
if [ -f "$localprofile" ]; then
|
|
|
|
. "$localprofile"
|
|
|
|
fi
|
|
|
|
|