From 432e5a1e03ba7f1f1e9fcb9543a0087265140108 Mon Sep 17 00:00:00 2001 From: TheK4n Date: Sun, 17 Oct 2021 03:42:44 +0300 Subject: [PATCH 1/2] feat: exit code right --- .bashrc | 66 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/.bashrc b/.bashrc index 3250e20..765c299 100644 --- a/.bashrc +++ b/.bashrc @@ -20,13 +20,13 @@ if type shopt 2>/dev/null 1>&2; then shopt -s dirspell shopt -s histappend - PROMPT_COMMAND='history -a' fi export HISTSIZE=10000 export HISTIGNORE="&:l[lsa\.]:[bf]g:exit:q:clear:c:history:h" + parse_git_branch() { if ! [ -x "$(which git)" ]; then @@ -67,32 +67,54 @@ virtualenv_info() { fi } -close_color='\[\e[m\]' -red_color='\[\033[1;31m\]' - -prompt_color='\[\033[;32m\]' -info_color='\[\033[1;34m\]' -prompt_symbol='㉿' -end_symbol='$' +rightprompt() +{ + if [[ $1 -ne 0 ]]; then + printf "%*s" $COLUMNS "$1 ⨯" + fi +} -if [ "$EUID" -eq 0 ]; then # Change prompt colors and symbols for root user - prompt_color='\[\033[;94m\]' - info_color='\[\033[1;31m\]' - end_symbol='#' -fi +PROMPT_COMMAND=__prompt_command + +__prompt_command() { + + local EXIT="$?" + + close_color='\[\e[m\]' + red_color='\[\033[1;31m\]' + + prompt_color='\[\033[;32m\]' + info_color='\[\033[1;34m\]' + prompt_symbol='㉿' + end_symbol='$' - -if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then - prompt_symbol='📡' -fi + if [ "$EUID" -eq 0 ]; then # Change prompt colors and symbols for root user + prompt_color='\[\033[;94m\]' + info_color='\[\033[1;31m\]' + end_symbol='#' + fi -export VIRTUAL_ENV_DISABLE_PROMPT=1 -VENV_="\$(virtualenv_info)"; + if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then + prompt_symbol='📡' + fi + + + export VIRTUAL_ENV_DISABLE_PROMPT=1 + + VENV_="\$(virtualenv_info)" + BRANCH_="\$(parse_git_branch)" + TERMINAL_NAME="\[\e]2;${0^^}\a\]" + + if [ $EXIT != 0 ]; then + PS1="$TERMINAL_NAME\n$prompt_color┌─${VENV_}─($close_color$info_color\u$prompt_symbol\H$close_color$prompt_color)-[$close_color\w$prompt_color]$close_color $red_color${BRANCH_}$close_color\n\[$(tput sc; rightprompt $EXIT; tput rc)\]$prompt_color└─$close_color$info_color$end_symbol$close_color " + else + PS1="$TERMINAL_NAME\n$prompt_color┌─${VENV_}─($close_color$info_color\u$prompt_symbol\H$close_color$prompt_color)-[$close_color\w$prompt_color]$close_color $red_color${BRANCH_}$close_color\n$prompt_color└─$close_color$info_color$end_symbol$close_color " + fi + + PS2="> " +} -BRANCH_="\$(parse_git_branch)"; -# last -PS1="\n$prompt_color┌─${VENV_}─($close_color$info_color\u$prompt_symbol\H$close_color$prompt_color)-[$close_color\w$prompt_color]$close_color $red_color${BRANCH_}$close_color\n$prompt_color└─$close_color$info_color$end_symbol$close_color " From 525243681a187ce866dcc82e2844357f4cc042d3 Mon Sep 17 00:00:00 2001 From: TheK4n Date: Sun, 17 Oct 2021 04:24:49 +0300 Subject: [PATCH 2/2] ref: all --- .bashrc | 121 +------------------------- .profile | 10 --- .bash_aliases => .subbash/aliases | 0 .subbash/export | 16 ++++ .bash_functions => .subbash/functions | 0 .subbash/prompt | 90 +++++++++++++++++++ .subbash/shopt | 11 +++ .subbash/sourcer | 23 +++++ README.md | 10 +-- setup.sh | 3 +- 10 files changed, 150 insertions(+), 134 deletions(-) rename .bash_aliases => .subbash/aliases (100%) create mode 100644 .subbash/export rename .bash_functions => .subbash/functions (100%) create mode 100644 .subbash/prompt create mode 100644 .subbash/shopt create mode 100644 .subbash/sourcer diff --git a/.bashrc b/.bashrc index 765c299..23187cd 100644 --- a/.bashrc +++ b/.bashrc @@ -1,120 +1,5 @@ # .bashrc by TheK4n +# https://github.com/TheK4n/dotfiles -if [ -f $HOME/.bash_aliases ]; then - source $HOME/.bash_aliases -fi - -if [ -f $HOME/.bash_functions ]; then - source $HOME/.bash_functions -fi - -if [ -f /etc/bash_completion.d/all ]; then - source /etc/bash_completion.d/all -fi - - -if type shopt 2>/dev/null 1>&2; then - - # corrections - shopt -s cdspell - shopt -s dirspell - - shopt -s histappend -fi - -export HISTSIZE=10000 -export HISTIGNORE="&:l[lsa\.]:[bf]g:exit:q:clear:c:history:h" - - - -parse_git_branch() { - - if ! [ -x "$(which git)" ]; then - return - fi - - local branch status - - # current branch - branch="$(git branch --show-current 2> /dev/null)" - - # current status - # M = modified - # A = added - # D = deleted - # R = renamed - # C = copied - # U = updated but unmerged - - status="$(git status -s 2>/dev/null | cut -c 1 | sort -u | tr -d " \n?")" - - if [ -n "$status" ]; then - status="-[$status]" - fi - - if [[ -n "$branch" ]]; then - echo "($branch)$status" - fi -} - - -virtualenv_info() { - - # Get Virtual Env - if [[ -n "$VIRTUAL_ENV" ]]; then - # Strip out the path and just leave the env name - echo "($(basename $VIRTUAL_ENV))" - fi -} - -rightprompt() -{ - if [[ $1 -ne 0 ]]; then - printf "%*s" $COLUMNS "$1 ⨯" - fi -} - - -PROMPT_COMMAND=__prompt_command - -__prompt_command() { - - local EXIT="$?" - - close_color='\[\e[m\]' - red_color='\[\033[1;31m\]' - - prompt_color='\[\033[;32m\]' - info_color='\[\033[1;34m\]' - prompt_symbol='㉿' - end_symbol='$' - - - if [ "$EUID" -eq 0 ]; then # Change prompt colors and symbols for root user - prompt_color='\[\033[;94m\]' - info_color='\[\033[1;31m\]' - end_symbol='#' - fi - - - if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then - prompt_symbol='📡' - fi - - - export VIRTUAL_ENV_DISABLE_PROMPT=1 - - VENV_="\$(virtualenv_info)" - BRANCH_="\$(parse_git_branch)" - TERMINAL_NAME="\[\e]2;${0^^}\a\]" - - if [ $EXIT != 0 ]; then - PS1="$TERMINAL_NAME\n$prompt_color┌─${VENV_}─($close_color$info_color\u$prompt_symbol\H$close_color$prompt_color)-[$close_color\w$prompt_color]$close_color $red_color${BRANCH_}$close_color\n\[$(tput sc; rightprompt $EXIT; tput rc)\]$prompt_color└─$close_color$info_color$end_symbol$close_color " - else - PS1="$TERMINAL_NAME\n$prompt_color┌─${VENV_}─($close_color$info_color\u$prompt_symbol\H$close_color$prompt_color)-[$close_color\w$prompt_color]$close_color $red_color${BRANCH_}$close_color\n$prompt_color└─$close_color$info_color$end_symbol$close_color " - fi - - PS2="> " -} - - +if [ -f $HOME/.subbash/sourcer ]; then + source $HOME/.subbash/sourcer diff --git a/.profile b/.profile index 5b90441..c27545d 100644 --- a/.profile +++ b/.profile @@ -5,13 +5,3 @@ if [ -n "$BASH_VERSION" ]; then . "$HOME/.bashrc" fi fi - -# set PATH so it includes user's private bin if it exists -if [ -d "$HOME/bin" ] ; then - export PATH="$PATH:$HOME/bin" -fi - -# set PATH so it includes user's private bin if it exists -if [ -d "$HOME/.local/bin" ] ; then - export PATH="$PATH:$HOME/.local/bin" -fi diff --git a/.bash_aliases b/.subbash/aliases similarity index 100% rename from .bash_aliases rename to .subbash/aliases diff --git a/.subbash/export b/.subbash/export new file mode 100644 index 0000000..d9f8137 --- /dev/null +++ b/.subbash/export @@ -0,0 +1,16 @@ +export EDITOR=vim + +export HISTSIZE=10000 +export HISTFILESIZE=10000 +export HISTTIMEFORMAT="%F %T " +export HISTIGNORE="&:l[lsa\.]:[bf]g:exit:q:clear:c:history:h" + +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/bin" ] ; then + export PATH="$PATH:$HOME/bin" +fi + +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/.local/bin" ] ; then + export PATH="$PATH:$HOME/.local/bin" +fi diff --git a/.bash_functions b/.subbash/functions similarity index 100% rename from .bash_functions rename to .subbash/functions diff --git a/.subbash/prompt b/.subbash/prompt new file mode 100644 index 0000000..250cfa4 --- /dev/null +++ b/.subbash/prompt @@ -0,0 +1,90 @@ + +parse_git_branch() { + + if ! [ -x "$(which git)" ]; then + return + fi + + local branch status + + # current branch + branch="$(git branch --show-current 2> /dev/null)" + + # current status + # M = modified + # A = added + # D = deleted + # R = renamed + # C = copied + # U = updated but unmerged + + status="$(git status -s 2>/dev/null | cut -c 1 | sort -u | tr -d " \n?")" + + if [ -n "$status" ]; then + status="-[$status]" + fi + + if [[ -n "$branch" ]]; then + echo "($branch)$status" + fi +} + + +virtualenv_info() { + + # Get Virtual Env + if [[ -n "$VIRTUAL_ENV" ]]; then + # Strip out the path and just leave the env name + echo "($(basename "$VIRTUAL_ENV"))" + fi +} + +rightprompt() +{ + if [[ $1 -ne 0 ]]; then + printf "%*s" $COLUMNS "$1 ⨯" + fi +} + + +export PROMPT_COMMAND=__prompt_command + +__prompt_command() { + + local EXIT=${PIPESTATUS[-1]} + + close_color='\[\e[m\]' + red_color='\[\033[1;31m\]' + + prompt_color='\[\033[;32m\]' + info_color='\[\033[1;34m\]' + prompt_symbol='㉿' + end_symbol='$' + + + if [ "$EUID" -eq 0 ]; then # Change prompt colors and symbols for root user + prompt_color='\[\033[;94m\]' + info_color='\[\033[1;31m\]' + end_symbol='#' + fi + + + if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then + prompt_symbol='📡' + fi + + + export VIRTUAL_ENV_DISABLE_PROMPT=1 + + VENV_="\$(virtualenv_info)" + BRANCH_="\$(parse_git_branch)" + TERMINAL_NAME="\[\e]2;${0^^}\a\]" + + if [ $EXIT != 0 ]; then + PS1="$TERMINAL_NAME\n$prompt_color┌─${VENV_}─($close_color$info_color\u$prompt_symbol\H$close_color$prompt_color)-[$close_color\w$prompt_color]$close_color $red_color${BRANCH_}$close_color\n\[$(tput sc; rightprompt $EXIT; tput rc)\]$prompt_color└─$close_color$info_color$end_symbol$close_color " + else + PS1="$TERMINAL_NAME\n$prompt_color┌─${VENV_}─($close_color$info_color\u$prompt_symbol\H$close_color$prompt_color)-[$close_color\w$prompt_color]$close_color $red_color${BRANCH_}$close_color\n$prompt_color└─$close_color$info_color$end_symbol$close_color " + fi + + PS2="> " +} \ No newline at end of file diff --git a/.subbash/shopt b/.subbash/shopt new file mode 100644 index 0000000..5932a52 --- /dev/null +++ b/.subbash/shopt @@ -0,0 +1,11 @@ + +## Misc +shopt -s histappend ## Appends hist on exit +shopt -s cmdhist ## Save multi-line hist as one line +shopt -s checkwinsize ## Update col/lines after commands + +### Completion +shopt -s autocd 2>/dev/null ## Can change dir without `cd` +shopt -s cdspell ## Fixes minor spelling errors in cd paths +shopt -s no_empty_cmd_completion ## Stops empty line tab comp +shopt -s dirspell 2>/dev/null ## Tab comp can fix dir name typos \ No newline at end of file diff --git a/.subbash/sourcer b/.subbash/sourcer new file mode 100644 index 0000000..096200d --- /dev/null +++ b/.subbash/sourcer @@ -0,0 +1,23 @@ +if [ -f "$HOME"/.subbash/aliases ]; then + source "$HOME"/.subbash/aliases +fi + +if [ -f "$HOME"/.subbash/functions ]; then + source "$HOME"/.subbash/functions +fi + +if [ -f "$HOME"/.subbash/shopt ]; then + source "$HOME"/.subbash/shopt +fi + +if [ -f "$HOME"/.subbash/prompt ]; then + source "$HOME"/.subbash/prompt +fi + +if [ -f "$HOME"/.subbash/export ]; then + source "$HOME"/.subbash/export +fi + +if [ -f /etc/bash_completion.d/all ]; then + source /etc/bash_completion.d/all +fi \ No newline at end of file diff --git a/README.md b/README.md index beda5dc..ed0f480 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

BashConfig

+

dotfiles

@@ -29,10 +29,10 @@ Bash config files ## Installation ```bash -git clone https://github.com/thek4n/BashConfig -chmod u+x BashConfig/setup.sh -BashConfig/setup.sh -rm -rf BashConfig +git clone https://github.com/TheK4n/dotfiles +chmod u+x dotfiles/setup.sh +dotfiles/setup.sh +rm -rf dotfiles ``` diff --git a/setup.sh b/setup.sh index f51a959..7c45bb0 100644 --- a/setup.sh +++ b/setup.sh @@ -1,4 +1,5 @@ #!/usr/bin/bash -cp .bashrc .bash_aliases .bash_functions .profile .vimrc .zshrc ~ && +cp -r .subbash ~ +cp .bashrc ~ . ~/.bashrc