]>
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 | |
ae3ee401 IB |
34 | [[ -f /usr/share/stgit/completion/stgit-completion.bash ]] && . /usr/share/stgit/completion/stgit-completion.bash |
35 | ||
397c4fed IB |
36 | {% if role.get(profile) == "fretlink" %} |
37 | ##### Some Fretlink aliases | |
38 | alias getDump='s3cmd -c <(pass show Travail/Fretlink/S3) get ' | |
39 | ||
40 | function vpn() { | |
41 | TMPFILE=$(mktemp /tmp/openvpn.XXXXXX) | |
42 | pass show Travail/Fretlink/OpenVPN >> $TMPFILE | |
43 | sudo openvpn $TMPFILE | |
44 | rm -f $TMPFILE | |
45 | } | |
46 | ||
47 | function dev_prompt() { | |
48 | if [ -n "$FRETLINK_ENV" ]; then | |
49 | echo "{$FRETLINK_ENV} " | |
50 | fi | |
51 | } | |
de1c634c IB |
52 | |
53 | function tmux_dev() { | |
54 | type="${1:-bash}" | |
55 | if [ -n "$TMUX" ]; then | |
56 | m=switch-client | |
57 | else | |
58 | m=attach-session | |
59 | fi | |
60 | ||
a65169cc IB |
61 | case "$type" in |
62 | "bash") start_dir="$HOME";; | |
1f22cde1 | 63 | "remote") start_dir="$HOME";; |
a65169cc IB |
64 | "puppet") start_dir="/etc/puppetlabs/code" |
65 | esac | |
66 | ||
de1c634c IB |
67 | if tmux has-session -t "$type" 2>/dev/null; then |
68 | tmux $m -t "$type" | |
69 | else | |
1f22cde1 IB |
70 | if [ "$type" = "remote" ]; then |
71 | tmux new-session -d -c $start_dir -s "$type" mosh immae.eu \; \ | |
72 | $m -t "$type" | |
73 | elif [ -n "$start_dir" ]; then | |
a65169cc IB |
74 | tmux new-session -d -c $start_dir -s "$type" \; \ |
75 | $m -t "$type" \; \ | |
76 | new-window -c $start_dir | |
de1c634c IB |
77 | else |
78 | tmux new-session -d -c "$HOME/workdir/$type" -s "$type" \; \ | |
79 | $m -t "$type" \; \ | |
80 | send-keys "../start" C-m \; \ | |
81 | rename-window "running" \; \ | |
82 | new-window -c "$HOME/workdir/$type" | |
83 | fi | |
84 | fi | |
85 | } | |
86 | ||
87 | _tmux_dev() { | |
88 | COMPREPLY=() | |
89 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
90 | prefix="$HOME/workdir/" | |
91 | local IFS=$'\n' | |
1f22cde1 | 92 | local items=($(IFS=' ' compgen -W "bash remote puppet" -- $cur) $(compgen -d $prefix$cur)) |
de1c634c IB |
93 | for item in ${items[@]}; do |
94 | [[ $item == $prefix.* ]] && continue | |
95 | COMPREPLY+=("${item#$prefix}") | |
96 | done | |
97 | } | |
98 | complete -o filenames -F _tmux_dev tmux_dev | |
bfe7d9cb IB |
99 | |
100 | if [ -n "$TMUX" ]; then | |
101 | TMUX_SESSION_NAME=$(tmux display-message -p "#S") | |
102 | export HISTFILE="$XDG_STATE_HOME/bash/tmux_${TMUX_SESSION_NAME}_history" | |
103 | fi | |
397c4fed IB |
104 | ##### /Fretlink |
105 | {% endif %} | |
106 | ||
107 | # Non-printable chars need to be wrapped by \[ ... \] otherwise bash | |
108 | # will wrongly count the size of the prompt and glitch when going | |
109 | # through history | |
110 | function git_prompt_color() { | |
111 | git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null | |
112 | gitstatus=$? | |
113 | if [ "$gitstatus" -gt 0 ]; then | |
114 | av=$'\033[01;31m' | |
115 | else | |
116 | av=$'\033[01;34m' | |
117 | fi | |
118 | echo "$av" | |
119 | } | |
120 | ||
121 | function git_prompt() { | |
122 | gitinfo=$(git branch 2>/dev/null | grep "^*" | cut -c3-); | |
123 | git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null | |
124 | gitstatus=$? | |
125 | gitlsfiles=$(git ls-files . 2>/dev/null | wc -l); | |
126 | if [ "$gitinfo" -a "$gitlsfiles" -gt 0 ]; then | |
127 | echo -e "($gitinfo) " | |
128 | fi | |
129 | } | |
853c1445 | 130 | {% set ps1_git = '\[$(git_prompt_color)\]$(git_prompt)' %} |
397c4fed IB |
131 | |
132 | function error_code() { | |
133 | ret=$? | |
134 | if [[ $ret != 0 ]]; then | |
135 | echo "$ret " | |
136 | fi | |
137 | } | |
138 | ||
139 | function running_jobs() { | |
140 | ret=$(jobs | wc -l) | |
141 | if [[ $ret != 0 ]]; then | |
142 | echo "[$ret] " | |
143 | fi | |
144 | } | |
853c1445 | 145 | {% set ps1_status = '\[\\033[01;31m\]$(error_code)\[\\033[00;00m\]$(running_jobs)' -%} |
397c4fed | 146 | |
853c1445 IB |
147 | {# Ensure new line before the prompt #} |
148 | {% set ps1_newline = '$(printf "%$((`tput cols`-1))s\\r")' -%} | |
149 | ||
150 | {% set ps1_other = '' %} | |
151 | {% if role.get(profile) == "fretlink" -%} | |
152 | {% set ps1_other = '\[\\033[01;32m\]$(dev_prompt)' %} | |
153 | {%- endif %} | |
154 | ||
155 | PS1='{{ ps1_newline }}{{ ps1_status }}{{ ps1_other }}{{ ps1_git }}\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] ' | |
397c4fed | 156 | |
853c1445 | 157 | PROMPT_COMMAND="[[ -f $XDG_STATE_HOME/bash/bashrc_temp ]] && . $XDG_STATE_HOME/bash/bashrc_temp" |
a19180df | 158 | |
397c4fed IB |
159 | {% if "nodejs" in features.get(profile, []) %} |
160 | source /usr/share/nvm/init-nvm.sh | |
161 | {% endif %} |