Files
configs/.mgr_config/.bashrc

89 lines
2.1 KiB
Bash

git-home() {
git --git-dir="$HOME/.git_home/" --work-tree="$HOME" "$@"
}
noerr() {
"$@" 2>/dev/null
}
alias gh='git-home'
alias highlight='grep -U999999 --color=always'
export PATH=$PATH:$HOME/.mgr_config/bin
FG_BLK="\001$(tput setaf 0)\002"
FG_RED="\001$(tput setaf 1)\002"
FG_GRN="\001$(tput setaf 2)\002"
FG_YEL="\001$(tput setaf 3)\002"
FG_BLU="\001$(tput setaf 4)\002"
FG_MGN="\001$(tput setaf 5)\002"
FG_CYN="\001$(tput setaf 6)\002"
FG_WHT="\001$(tput setaf 7)\002"
FG_DEF="\001$(tput setaf 9)\002"
BG_BLK="\001$(tput setab 0)\002"
BG_RED="\001$(tput setab 1)\002"
BG_GRN="\001$(tput setab 2)\002"
BG_YEL="\001$(tput setab 3)\002"
BG_BLU="\001$(tput setab 4)\002"
BG_MGN="\001$(tput setab 5)\002"
BG_CYN="\001$(tput setab 6)\002"
BG_WHT="\001$(tput setab 7)\002"
BG_DEF="\001$(tput setab 9)\002"
BOLD="\001$(tput bold)\002"
RST="\001$(tput sgr0)\002"
git_root() {
git rev-parse --show-toplevel 2> /dev/null
}
prompt_function() {
prompt=""
HOST_COLOR_ID=$(( "16#$(hostname | md5sum | cut -f1 -d' ')" % 7 + 1)) # [1, 7]
HOST_COLOR="${RST}\001$(tput setaf $HOST_COLOR_ID)\002"
GIT_COLOR="${RST}${FG_CYN}"
DIR_COLOR="${RST}${FG_YEL}"
WARN_COLOR="${RST}${BOLD}${FG_RED}"
if [[ "$(whoami)" == root ]]; then
prompt+="${WARN_COLOR}"
else
prompt+="${HOST_COLOR}"
fi
prompt+="$(whoami)@$(hostname)${RST}:"
if root=$(git_root); then
# If in a git repository, only print the path relative to the repo root
path=$(realpath --relative-to=$root $PWD)
ref=$(git symbolic-ref --short -q HEAD)
if [[ $ref == "" ]]; then
ref="${WARN_COLOR}detached${GIT_COLOR}"
fi
dirty=$(git diff-index --quiet HEAD)
if [[ $path == . ]]; then
path=""
fi
prompt+="${GIT_COLOR}[$(basename $root)@${ref}:${DIR_COLOR}${path}${fg}${GIT_COLOR}]${RST}"
else
# If not in a git repo, print the full path
prompt+="${DIR_COLOR}[$(dirs)]${RST}"
fi
printf "$prompt\$ "
}
PS1="\$(prompt_function)"
if [[ -z "$INSIDE_EMACS" ]]; then
EMACS="emacsclient -a="" -c"
alias emacs="$EMACS"
else
EMACS="emacsclient"
alias emacs="$EMACS -n"
fi
export EDITOR="$EMACS"
export VISUAL="$EMACS"