]>
Commit | Line | Data |
---|---|---|
397c4fed IB |
1 | # |
2 | # ~/.bashrc | |
3 | # | |
4 | ||
a19180df | 5 | [[ -f "$XDG_STATE_HOME/bash/bashrc_temp" ]] && . $XDG_STATE_HOME/bash/bashrc_temp |
c235f9be | 6 | |
397c4fed IB |
7 | if [ -n "$HOME/.local/bin" ]; then |
8 | PATH="$HOME/.local/bin:$PATH" | |
9 | fi | |
10 | ||
11 | # If not running interactively, don't do anything | |
12 | [[ $- != *i* ]] && return | |
13 | ||
14 | export GPG_TTY=$(tty) | |
15 | export HISTFILE="$XDG_STATE_HOME/bash/history" | |
dd308b2f IB |
16 | export HISTTIMEFORMAT='%F %T ' |
17 | export HISTCONTROL="ignorespace:ignoredups" | |
397c4fed IB |
18 | |
19 | alias vi=vim | |
20 | alias ls='ls --color=auto -F -T 0' | |
21 | alias tmux='tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf' | |
22 | ||
23 | alias grep='grep --color=auto' | |
24 | alias fgrep='fgrep --color=auto' | |
25 | alias egrep='egrep --color=auto' | |
26 | ||
27 | alias sudo="sudo " | |
28 | alias mv="mv -i" | |
29 | alias cp="cp -i" | |
30 | alias rm="rm -i" | |
31 | alias psp="pstree -aUp $USER" | |
853c1445 | 32 | alias info='info -v active-link-style=yellow,bold -v link-style=yellow' |
397c4fed | 33 | |
9f528ac4 IB |
34 | if [[ -d "$XDG_DATA_HOME/bash_completion" ]]; then |
35 | for i in $XDG_DATA_HOME/bash_completion/*; do | |
36 | [[ -f "$i" && -r "$i" ]] && . "$i" | |
37 | done | |
38 | fi | |
39 | ||
397c4fed IB |
40 | {% if role.get(profile) == "fretlink" %} |
41 | ##### Some Fretlink aliases | |
9f528ac4 IB |
42 | alias vpn=fl_vpn |
43 | alias tmux_dev=fl_tmux_dev | |
44 | complete -o filenames -F _fl_tmux_dev tmux_dev | |
397c4fed IB |
45 | |
46 | function dev_prompt() { | |
47 | if [ -n "$FRETLINK_ENV" ]; then | |
48 | echo "{$FRETLINK_ENV} " | |
49 | fi | |
50 | } | |
de1c634c | 51 | |
bfe7d9cb IB |
52 | if [ -n "$TMUX" ]; then |
53 | TMUX_SESSION_NAME=$(tmux display-message -p "#S") | |
54 | export HISTFILE="$XDG_STATE_HOME/bash/tmux_${TMUX_SESSION_NAME}_history" | |
55 | fi | |
b7b8fe64 IB |
56 | |
57 | function load_dev_env() { | |
58 | if [ -z "$1" ]; then | |
59 | source ../environment | |
60 | else | |
61 | FL_ENV="$1" source ../environment | |
62 | fi | |
63 | } | |
64 | ||
397c4fed IB |
65 | ##### /Fretlink |
66 | {% endif %} | |
67 | ||
68 | # Non-printable chars need to be wrapped by \[ ... \] otherwise bash | |
69 | # will wrongly count the size of the prompt and glitch when going | |
70 | # through history | |
71 | function git_prompt_color() { | |
72 | git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null | |
73 | gitstatus=$? | |
74 | if [ "$gitstatus" -gt 0 ]; then | |
75 | av=$'\033[01;31m' | |
76 | else | |
77 | av=$'\033[01;34m' | |
78 | fi | |
79 | echo "$av" | |
80 | } | |
81 | ||
82 | function git_prompt() { | |
83 | gitinfo=$(git branch 2>/dev/null | grep "^*" | cut -c3-); | |
84 | git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null | |
85 | gitstatus=$? | |
86 | gitlsfiles=$(git ls-files . 2>/dev/null | wc -l); | |
87 | if [ "$gitinfo" -a "$gitlsfiles" -gt 0 ]; then | |
88 | echo -e "($gitinfo) " | |
89 | fi | |
90 | } | |
853c1445 | 91 | {% set ps1_git = '\[$(git_prompt_color)\]$(git_prompt)' %} |
397c4fed | 92 | |
397c4fed IB |
93 | function running_jobs() { |
94 | ret=$(jobs | wc -l) | |
95 | if [[ $ret != 0 ]]; then | |
96 | echo "[$ret] " | |
97 | fi | |
98 | } | |
853c1445 | 99 | |
2fdf2f6d | 100 | PROMPT_COMMAND=__prompt_command |
853c1445 | 101 | |
2fdf2f6d IB |
102 | __prompt_command () { |
103 | local ret="$?" | |
104 | PS1="" | |
105 | d="\[\033[00;00m\]" | |
106 | red="\[\033[01;31m\]" | |
107 | bgreen="\[\033[01;32m\]" | |
108 | green="\[\033[00;32m\]" | |
109 | blue="\[\033[94m\]" | |
397c4fed | 110 | |
2fdf2f6d IB |
111 | # Ensure new line before the prompt |
112 | PS1='$(printf "%$((`tput cols`-1))s\r")' | |
113 | if [[ $ret != 0 ]]; then | |
114 | PS1+="$red$ret $d" | |
115 | fi | |
116 | PS1+='$(running_jobs)' | |
117 | {% if role.get(profile) == "fretlink" %} | |
118 | PS1+="$bgreen"'$(dev_prompt)' | |
119 | {% endif %} | |
120 | PS1+='\[$(git_prompt_color)\]$(git_prompt)' | |
121 | PS1+="$green\u@\h$blue \w \$$d " | |
122 | } | |
a19180df | 123 | |
397c4fed IB |
124 | {% if "nodejs" in features.get(profile, []) %} |
125 | source /usr/share/nvm/init-nvm.sh | |
126 | {% endif %} |