rework colors and indents

This commit is contained in:
James Dixon 2020-05-20 16:53:34 -04:00
parent c207896ec7
commit 4838eae9bc

View File

@ -1,28 +1,32 @@
# If not running interactively, don't do anything # If not running interactively, don't do anything
case $- in case $- in
*i*) ;; *i*) ;;
*) return;; *) return;;
esac esac
#========== HISTORY OPTIONS ==========# # HISTORY OPTIONS
# ---------------
HISTSIZE= ; HISTSIZE= ;
HISTFILESIZE= HISTFILESIZE=
HISTCONTROL="ignoreboth:erasedups" HISTCONTROL="ignoreboth:erasedups"
HISTTIMEFORMAT="%F %T " HISTTIMEFORMAT="%F %T "
#========== SHELL OPTIONS ==========# # SHELL OPTIONS
# -------------
shopt -s checkhash checkjobs checkwinsize cmdhist direxpand dirspell extglob globstar histappend shopt -s checkhash checkjobs checkwinsize
shopt -s direxpand dirspell extglob globstar
#========== PROGRAM VARIABLES ==========# shopt -s cmdhist histappend
# VARIABLES
# ---------
export EDITOR="/usr/bin/vim" export EDITOR="/usr/bin/vim"
export VISUAL="/usr/bin/vim" export VISUAL="/usr/bin/vim"
export PAGER="less" export PAGER="less"
#========== ALIASES ==========# export GH="https://github.com/lemonase"
# ALIASES
# -------
# common options # common options
LS_OPTS="-F --color=auto" LS_OPTS="-F --color=auto"
GREP_OPTS="--color=auto" GREP_OPTS="--color=auto"
@ -32,7 +36,6 @@ alias l='ls ${LS_OPTS}'
alias ls='ls ${LS_OPTS}' alias ls='ls ${LS_OPTS}'
alias ll='ls -lsh ${LS_OPTS}' alias ll='ls -lsh ${LS_OPTS}'
alias la='ls -Alsh ${LS_OPTS}' alias la='ls -Alsh ${LS_OPTS}'
alias al='ls -A ${LS_OPTS}' alias al='ls -A ${LS_OPTS}'
alias sl='ls -lsSh ${LS_OPTS}' alias sl='ls -lsSh ${LS_OPTS}'
alias sal='ls -AlsSh ${LS_OPTS}' alias sal='ls -AlsSh ${LS_OPTS}'
@ -62,8 +65,35 @@ alias tmka='tmux kill-server' # aka killall
# python venv # python venv
alias venvac='source venv/bin/activate' alias venvac='source venv/bin/activate'
#========== FUNCTIONS ==========# # COLORS
# ------
# color vars using tput or ANSI/VT100 Control sequences
if command -v "tput" > /dev/null 2>&1 ; then
black="\[$(tput setaf 0)\]"
red="\[$(tput setaf 1)\]"
green="\[$(tput setaf 2)\]"
yellow="\[$(tput setaf 3)\]"
blue="\[$(tput setaf 4)\]"
purple="\[$(tput setaf 5)\]"
cyan="\[$(tput setaf 6)\]"
white="\[$(tput setaf 7)\]"
reset="\[$(tput sgr0)\]"
bold="\[$(tput bold)\]"
else
black="\[\033[0;30\]"
red="\[\033[1;31\]"
green="\[\033[1;32\]"
yellow="\[\033[1;33\]"
blue="\[\033[1;34\]"
purple="\[\033[1;35\]"
cyan="\[\033[1;36\]"
white="\[\033[1;37\]"
reset="\[\033[0m\]"
bold="\[\033[1m\]"
fi
# FUNCTIONS
# ---------
# common commands improved # common commands improved
cll() { cd -P "$@" && ls -alshF; } cll() { cd -P "$@" && ls -alshF; }
cls() { cd -P "$@" && ls; } cls() { cd -P "$@" && ls; }
@ -71,117 +101,129 @@ mkcd() { mkdir -p -- "$1" && cd "$1"; }
cdd() { [ -n "$1" ] && for i in $(seq 1 "$1"); do cd ..; done; } cdd() { [ -n "$1" ] && for i in $(seq 1 "$1"); do cd ..; done; }
touchx() { touch "$@" && chmod +x "$@"; } touchx() { touch "$@" && chmod +x "$@"; }
# git
lazygit() { git commit -a -m "$*" && git push; }
lg() { lazygit "$*"; }
# git prompt functions
parse_git() {
# ways to get branches
# git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
# git rev-parse --abbrev-ref HEAD 2> /dev/null | sed -e 's/.*\/\(.*\)/\1/'
BRANCH="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)"
STATUS="$(git status 2> /dev/null)"
if [[ $? -ne 0 ]]; then
return
else
printf "\033[1;37m:(${BRANCH})["
fi
if echo "${STATUS}" | grep -c "nothing to commit" &> /dev/null; then printf "\033[1;34m=\033[0m"; else printf ""; fi
if echo "${STATUS}" | grep -c "renamed:" &> /dev/null; then printf "\033[1;31m>\033[0m"; else printf ""; fi
if echo "${STATUS}" | grep -c "deleted:" &> /dev/null; then printf "\033[1;31m-\033[0m"; else printf ""; fi
if echo "${STATUS}" | grep -c "new file:" &> /dev/null; then printf "\033[1;32m+\033[0m"; else printf ""; fi
if echo "${STATUS}" | grep -c "branch is ahead:" &> /dev/null; then printf "\033[1;33m!\033[0m"; else printf ""; fi
if echo "${STATUS}" | grep -c "Untracked files:" &> /dev/null; then printf "\033[1;33m?\033[0m"; else printf ""; fi
if echo "${STATUS}" | grep -c "modified:" &> /dev/null; then printf "\033[1;33m*\033[0m"; else printf ""; fi
printf "\033[1;37m]"
}
# tmux # tmux
tm() { tm() {
if [ "$#" -gt 0 ]; then if [ "$#" -gt 0 ]; then
tmux new-session -As "$1" tmux new-session -As "$1"
else else
tmux new-session tmux new-session
fi fi
} }
tma() { tma() {
if [ "$#" -gt 0 ]; then if [ "$#" -gt 0 ]; then
tmux attach-session -d -t "$1" tmux attach-session -d -t "$1"
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
tmux new-session -As "$1" tmux new-session -As "$1"
fi fi
else else
tmux attach tmux attach
fi fi
} }
# paths and files # paths and files
pathappend() { pathappend() {
# https://superuser.com/questions/39751/add-directory-to-path-if-its-not-already-there # https://superuser.com/questions/39751/add-directory-to-path-if-its-not-already-there
for ARG; do for ARG; do
if [ -d "$ARG" ] && [[ ":$PATH:" != *":$ARG:"* ]]; then if [ -d "$ARG" ] && [[ ":$PATH:" != *":$ARG:"* ]]; then
ABS_DIR="$(readlink -f "$ARG")" ABS_DIR="$(readlink -f "$ARG")"
PATH="${PATH:+"$PATH:"}$ABS_DIR" PATH="${PATH:+"$PATH:"}$ABS_DIR"
echo "$ABS_DIR" added! echo "$ABS_DIR" added!
else else
echo Invalid directory in "\"$*\"" echo Invalid directory in "\"$*\""
fi fi
done done
} }
bkup() { bkup() {
# create backup file with date appended # create backup file with date appended
if [ -f "$1" ]; then if [ -f "$1" ]; then
cp "${1}" "${1}.bkup.$(date +'%F.%R')" cp "${1}" "${1}.bkup.$(date +'%F.%R')"
fi fi
} }
#========== PROMPTS ==========# # hugo -- create and edit a new post
new-post() {
postname=""
if [ -z "$1" ]; then
echo -n "Please enter a postname: "
read -r postname
else
postname="$1"
fi
post_filename="$postname.md"
blog_dir="$HOME/src/blog"
local_url="http://localhost:1313/posts/$postname"
hugo new -s "$blog_dir" "posts/$post_filename"
hugo serve -s "$blog_dir" -D &> /dev/null &
xdg-open "$local_url" &> /dev/null &
vim "$blog_dir/content/posts/$post_filename" && kill %1
}
# git
lazygit() { git commit -a -m "$*" && git push; }
lg() { lazygit "$*"; }
# git prompt function
parse_git() {
# ways to get branches
# git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
# git rev-parse --abbrev-ref HEAD 2> /dev/null | sed -e 's/.*\/\(.*\)/\1/'
BRANCH="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)"
STATUS="$(git status 2> /dev/null)"
if [[ $? -ne 0 ]]; then return; else printf "$(tput sgr0)$(tput bold)%s" ":(${BRANCH})["; fi
if echo "${STATUS}" | grep -c "nothing to commit" &> /dev/null; then printf "$(tput setaf 4)%s" "="; else printf ""; fi
if echo "${STATUS}" | grep -c "renamed:" &> /dev/null; then printf "$(tput setaf 1)%s" ">"; else printf ""; fi
if echo "${STATUS}" | grep -c "deleted:" &> /dev/null; then printf "$(tput setaf 1)%s" "-"; else printf ""; fi
if echo "${STATUS}" | grep -c "new file:" &> /dev/null; then printf "$(tput setaf 2)%s" "+"; else printf ""; fi
if echo "${STATUS}" | grep -c "branch is ahead:" &> /dev/null; then printf "$(tput setaf 3)%s" "!"; else printf ""; fi
if echo "${STATUS}" | grep -c "Untracked files:" &> /dev/null; then printf "$(tput setaf 3)%s" "?"; else printf ""; fi
if echo "${STATUS}" | grep -c "modified:" &> /dev/null; then printf "$(tput setaf 3)%s" "*"; else printf ""; fi
printf "$(tput setaf 7)%s" "]"
}
# PROMPTS
# -------
# start prompt string
PS1="${bold}"
# ***git prompts*** # ***git prompts***
# PS1+="${blue}\w\[\$(parse_git)\] ${cyan}\\$ "
# PS1="\[\033[1;34m\]\w\[\033[0m\]\$(parse_git) \[\033[1;36m\]\$\[\033[0m\] " PS1+="${white}[\t] ${blue}\w\[\$(parse_git)\] ${green}\\$ "
# PS1="\[\033[1;35m\]\u\[\033[1;33m\]@\[\033[1;36m\]\h\[\033[0m\]:\[\033[1;37:\[\033[1;34m\]\w\[\033[0m\]\$(parse_git)\[\033[0m\]\[\033[1;33m\]$ \[\033[0m\]" # PS1+="${purple}\u${yellow}@${cyan}\h${white}:${blue}\w\[\$(parse_git)\]${yellow} \\$ "
# PS1="\[\033[1;36m\]\u \[\033[1;37m\]at \[\033[1;33m\]\h \[\033[1;37m\]in \[\033[1;34m\]\w \[\033[1;37m\]on \[\033[1;37m\]\$(parse_git)\n\[\033[1;37m\]\$ " # PS1+="\n${cyan}\u ${white}at ${yellow}\h ${white}in ${blue}\w ${white}on \[\$(parse_git)\]\n${yellow}\\$ "
# ***non git prompts*** # ***non git prompts***
# PS1="\[\033[1;34m\]\w \[\033[1;33m\]\$ \[\033[0m\]" # PS1+="${blue}\w ${yellow}\\$ "
# PS1="\[\033[1;35m\]\u\[\033[1;33m\]@\[\033[1;36m\]\h\[\033[0m\]:\[\033[1;37:\[\033[1;34m\]\w\[\033[0m\]\[\033[1;33m\]$ \[\033[0m\]" # PS1+="${purple}\u${yellow}@${cyan}\h${white}:${blue}\w ${yellow}\\$ "
# ***non-color prompts*** # ***non-color prompts***
# PS1="\w \\$ "
# PS1="[\u@\h:\w] \\$ "
# PS1="\u@\h:\w \\$ "
# PS1="\w \$ " # end prompt string
# PS1="[\u@\h:\w]$ " PS1+="${reset}"
# PS1="\u@\h:\w$ "
#========== COLORS REFERENCE ==========#
# COLORS according to (ANSI/VT100 Control sequences)
# https://misc.flogisoft.com/bash/tip_colors_and_formatting for examples
# \[\033[0;30m\] BLACK \[\033[1;30m\] DARK_GREY
# \[\033[0;31m\] RED \[\033[1;31m\] LIGHT_RED
# \[\033[0;32m\] GREEN \[\033[1;32m\] LIGHT_GREEN
# \[\033[0;33m\] BROWN \[\033[1;33m\] YELLOW
# \[\033[0;34m\] BLUE \[\033[1;34m\] LIGHT_BLUE
# \[\033[0;35m\] PURPLE \[\033[1;35m\] LIGHT_PURPLE
# \[\033[0;36m\] CYAN \[\033[1;36m\] LIGHT_CYAN
# \[\033[0;37m\] LIGHT_GREY \[\033[1;37m\] WHITE
# \[\033[0m\] RESET NORMAL
# \[\033[1m\] RESET BOLD
#========== BASH AUTOCOMPLETION ==========#
# BASH AUTOCOMPLETION
# -------------------
if ! shopt -oq posix; then if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion source /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion source /etc/bash_completion
fi fi
fi fi
# LOCAL RC
# --------
[ -f "$HOME/.config/bashrc" ] && source "$HOME/.config/bashrc"