|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# default opinioned bash configuration to be sourced from user's bashrc |
| 4 | + |
| 5 | +# enable enternal shared history |
| 6 | +export HISTCONTROL=ignoreboth:erasedups |
| 7 | +export HISTSIZE=-1 |
| 8 | +export HISTFILESIZE=-1 |
| 9 | +export SAVEHIST=-1 |
| 10 | +export HISTFILE=$USER_TERMINAL_CONFIG/.bash_eternal_history |
| 11 | +export PROMPT_COMMAND="history -a; $PROMPT_COMMAND" |
| 12 | + |
| 13 | +# bash theme - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/dst.zsh-theme |
| 14 | +# from https://github.com/devcontainers/features/blob/main/src/common-utils/scripts/bash_theme_snippet.sh |
| 15 | +__bash_prompt() { |
| 16 | + local userpart='`export XIT=$? \ |
| 17 | + && echo -n "\u " \ |
| 18 | + && [ "$XIT" -ne "0" ] && echo -n "\[\033[1;31m\]➜" || echo -n "\[\033[0m\]➜"`' |
| 19 | + local gitbranch='`\ |
| 20 | + export BRANCH="$(git --no-optional-locks symbolic-ref --short HEAD 2>/dev/null || git --no-optional-locks rev-parse --short HEAD 2>/dev/null)"; \ |
| 21 | + if [ "${BRANCH:-}" != "" ]; then \ |
| 22 | + echo -n "\[\033[0;36m\](\[\033[1;32m\]${BRANCH:-}" \ |
| 23 | + && if git --no-optional-locks ls-files --error-unmatch -m --directory --no-empty-directory -o --exclude-standard ":/*" > /dev/null 2>&1; then \ |
| 24 | + echo -n " \[\033[1;33m\]✗"; \ |
| 25 | + fi \ |
| 26 | + && echo -n "\[\033[0;36m\]) "; \ |
| 27 | + fi`' |
| 28 | + local removecolor='\[\033[0m\]' |
| 29 | + local lightblue='\[\033[1;34m\]' |
| 30 | + local cyan='\[\033[0;36m\]' |
| 31 | + PS1="${lightblue}${userpart} ${cyan}\w ${gitbranch}${removecolor}\n\$ " |
| 32 | + unset -f __bash_prompt |
| 33 | +} |
| 34 | +__bash_prompt |
| 35 | +export PROMPT_DIRTRIM=4 |
| 36 | + |
| 37 | +# Set the default git editor if not already set |
| 38 | +# from https://github.com/devcontainers/features/blob/f8e7e275b7ba2808e14a035afd753b83be68e2d9/src/common-utils/scripts/rc_snippet.sh |
| 39 | +if [ -z "$(git config --get core.editor)" ] && [ -z "${GIT_EDITOR}" ]; then |
| 40 | + if [ "${TERM_PROGRAM}" = "vscode" ]; then |
| 41 | + if [[ -n $(command -v code-insiders) && -z $(command -v code) ]]; then |
| 42 | + export GIT_EDITOR="code-insiders --wait" |
| 43 | + else |
| 44 | + export GIT_EDITOR="code --wait" |
| 45 | + fi |
| 46 | + fi |
| 47 | +fi |
| 48 | + |
| 49 | +# colorize ls output |
| 50 | +export LS_OPTIONS='--color=auto' |
| 51 | +eval "$(dircolors)" |
| 52 | +alias ls='ls $LS_OPTIONS' |
| 53 | +alias ll='ls $LS_OPTIONS -l' |
| 54 | + |
| 55 | +# enable bash completion for git |
| 56 | +source /usr/share/bash-completion/completions/git |
0 commit comments