.profile: Small improvements

I think
Not really, actually
This commit is contained in:
Salt 2018-11-27 23:24:17 -06:00
parent 5dff2dca30
commit 9c4a950385

View File

@ -39,6 +39,9 @@
# shellcheck disable=1117 # shellcheck disable=1117
# Environment variables # Environment variables
# First, what shell are we?
_baseshell="$(basename "$0")"
# Use Vim if we have it # Use Vim if we have it
export EDITOR="vi" export EDITOR="vi"
command -v vim > /dev/null 2>&1 && export EDITOR="vim" command -v vim > /dev/null 2>&1 && export EDITOR="vim"
@ -65,7 +68,7 @@ PATH="$desiredpath:$PATH"
# 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 "$(basename "$SHELL")" in case "$_baseshell" in
*bash) *bash)
if ! [ -f "$HOME/.pip-completion-bash" ]; then if ! [ -f "$HOME/.pip-completion-bash" ]; then
pip completion --bash > "$HOME/.pip-completion-bash" pip completion --bash > "$HOME/.pip-completion-bash"
@ -171,10 +174,10 @@ _ps1() {
*bash) *bash)
prefix="${prefix}${fg_yellow}" prefix="${prefix}${fg_yellow}"
;; ;;
ksh) /bin/ksh)
prefix="${prefix}${fg_green}" prefix="${prefix}${fg_green}"
;; ;;
sh) /bin/sh)
prefix="${prefix}${fg_grey}" prefix="${prefix}${fg_grey}"
;; ;;
*) *)
@ -191,15 +194,24 @@ _ps1() {
if ! [ "$exitcode" = "0" ]; then if ! [ "$exitcode" = "0" ]; then
fail="${fg_bold}${fg_red}?" fail="${fg_bold}${fg_red}?"
fi fi
# printf is used here less for its C-like arguments and more becasue
# POSIX echo doesn't have an option to not print a newline.
# Hence this warning is disabled
# shellcheck disable=2059 # shellcheck disable=2059
printf "[${prefix}${cpwd}${r}]${fail}${r}${fg_green}\$${r} " printf "[${prefix}${cpwd}${r}]${fail}${r}${fg_green}\$${r} "
} }
if ! [ "$ZSH_NAME" ]; then # And export our PS1
# I've got a different ZSH theme case "$_baseshell" in
zsh)
# Don't do this on ZSH
# I have a custom theme for that
;;
sh)
export PS1=''
;;
*)
export PS1='$(_ps1)' export PS1='$(_ps1)'
fi ;;
esac
# Clean up
unset _baseshell