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