summaryrefslogblamecommitdiff
path: root/roles/shell/bash/templates/bashrc.j2
blob: c7f85224b579b28d436bc72eda2924e655b35df3 (plain) (tree)
1
2
3
4
5
6



           
                                                                                 
 








                                                 

                                           













                                                    
                                                                       
 





                                                  

                                        


                                              





                                 
 



                                                                          








                                     

























                                                                       
                                                          













                           
                                                                                      
 








                                                                                                                      
 
                                                                                                
 


                                              
#
# ~/.bashrc
#

[[ -f "$XDG_STATE_HOME/bash/bashrc_temp" ]] && . $XDG_STATE_HOME/bash/bashrc_temp

if [ -n "$HOME/.local/bin" ]; then
  PATH="$HOME/.local/bin:$PATH"
fi

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

export GPG_TTY=$(tty)
export HISTFILE="$XDG_STATE_HOME/bash/history"
export HISTTIMEFORMAT='%F %T '
export HISTCONTROL="ignorespace:ignoredups"

alias vi=vim
alias ls='ls --color=auto -F -T 0'
alias tmux='tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

alias sudo="sudo "
alias mv="mv -i"
alias cp="cp -i"
alias rm="rm -i"
alias psp="pstree -aUp $USER"
alias info='info -v active-link-style=yellow,bold -v link-style=yellow'

if [[ -d "$XDG_DATA_HOME/bash_completion" ]]; then
  for i in $XDG_DATA_HOME/bash_completion/*; do
    [[ -f "$i" && -r "$i" ]] && . "$i"
  done
fi

{% if role.get(profile) == "fretlink" %}
##### Some Fretlink aliases
alias vpn=fl_vpn
alias tmux_dev=fl_tmux_dev
complete -o filenames -F _fl_tmux_dev tmux_dev

function dev_prompt() {
  if [ -n "$FRETLINK_ENV" ]; then
    echo "{$FRETLINK_ENV} "
  fi
}

if [ -n "$TMUX" ]; then
  TMUX_SESSION_NAME=$(tmux display-message -p "#S")
  export HISTFILE="$XDG_STATE_HOME/bash/tmux_${TMUX_SESSION_NAME}_history"
fi

function load_dev_env() {
  if [ -z "$1" ]; then
    source ../environment
  else
    FL_ENV="$1" source ../environment
  fi
}

##### /Fretlink
{% endif %}

# Non-printable chars need to be wrapped by \[ ... \] otherwise bash
# will wrongly count the size of the prompt and glitch when going
# through history
function git_prompt_color() {
  git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
  gitstatus=$?
  if [ "$gitstatus" -gt 0 ]; then
    av=$'\033[01;31m'
  else
    av=$'\033[01;34m'
  fi
  echo "$av"
}

function git_prompt() {
  gitinfo=$(git branch 2>/dev/null | grep "^*" | cut -c3-);
  git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
  gitstatus=$?
  gitlsfiles=$(git ls-files . 2>/dev/null | wc -l);
  if [ "$gitinfo" -a "$gitlsfiles" -gt 0 ]; then
    echo -e "($gitinfo) "
  fi
}
{% set ps1_git = '\[$(git_prompt_color)\]$(git_prompt)' %}

function error_code() {
  ret=$?
  if [[ $ret != 0  ]]; then
    echo "$ret "
  fi
}

function running_jobs() {
  ret=$(jobs | wc -l)
  if [[ $ret != 0  ]]; then
    echo "[$ret] "
  fi
}
{% set ps1_status = '\[\\033[01;31m\]$(error_code)\[\\033[00;00m\]$(running_jobs)' -%}

{# Ensure new line before the prompt #}
{% set ps1_newline = '$(printf "%$((`tput cols`-1))s\\r")' -%}

{% set ps1_other = '' %}
{% if role.get(profile) == "fretlink" -%}
  {% set ps1_other = '\[\\033[01;32m\]$(dev_prompt)' %}
{%- endif %}

PS1='{{ ps1_newline }}{{ ps1_status }}{{ ps1_other }}{{ ps1_git }}\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] '

PROMPT_COMMAND="[[ -f $XDG_STATE_HOME/bash/bashrc_temp ]] && . $XDG_STATE_HOME/bash/bashrc_temp"

{% if "nodejs" in features.get(profile, []) %}
source /usr/share/nvm/init-nvm.sh
{% endif %}