Repository navigation
Expand file tree
/
Copy pathprivate_dot_bashrc
More file actions
95 lines (83 loc) · 2.39 KB
/
Copy pathprivate_dot_bashrc
File metadata and controls
95 lines (83 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
# shellcheck shell=bash
# shellcheck disable=SC1090,SC1091,SC2034
if ((BASH_VERSINFO[0] > 3)); then
shopt -s autocd
shopt -s cdspell
shopt -s dirspell
shopt -s globstar
fi
# Functions to help us manage paths. Second argument is the name of the
# path variable to be modified (default: PATH).
# Adapted from: https://www.linuxfromscratch.org/blfs/view/svn/postlfs/profile.html
path_remove() {
local PATHVARIABLE=${2:-PATH}
local val=":${!PATHVARIABLE}:"
val="${val//:${1}:/:}"
val="${val#:}"
val="${val%:}"
export "$PATHVARIABLE"="${val}"
}
path_prepend() {
path_remove "$1" "$2"
local PATHVARIABLE=${2:-PATH}
export "$PATHVARIABLE"="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
}
path_append() {
path_remove "$1" "$2"
local PATHVARIABLE=${2:-PATH}
export "$PATHVARIABLE"="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
}
# Check for /usr/local/sbin in PATH
if [[ -d "/usr/local/sbin" ]]; then
path_prepend "/usr/local/sbin"
fi
# Check for /usr/local/bin in PATH
if [[ -d "/usr/local/bin" ]]; then
path_prepend "/usr/local/bin"
fi
if [[ -e "/opt/homebrew/bin/brew" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv bash)"
fi
# Import files from $HOME/.bashrc.d
if [[ -d "$HOME/.bashrc.d" ]]; then
for config in "$HOME"/.bashrc.d/**/*.bash; do
if [[ -r "$config" ]]; then
source "$config"
fi
done
unset -v config
fi
# Check the window size after each command and, if necessary,
# Update the values of LINES and COLUMNS.
shopt -s checkwinsize
# macOS settings
if [[ -v HOMEBREW_PREFIX ]]; then
# Set Homebrew Cask default Applications directory
export HOMEBREW_CASK_OPTS="--appdir=~/Applications"
export HOMEBREW_NO_ASK=1
export HOMEBREW_NO_UPGRADE_AUTO_UPDATES_CASKS=1
# Enable bash-completion with Homebrew
export BASH_COMPLETION_COMPAT_DIR="$HOMEBREW_PREFIX/etc/bash_completion.d"
if [[ -f "$HOMEBREW_PREFIX/etc/profile.d/bash_completion.sh" ]]; then
source "$HOMEBREW_PREFIX/etc/profile.d/bash_completion.sh"
fi
fi
# Prepend $HOME/.local/bin to PATH
if [[ -d "$HOME/.local/bin" ]]; then
path_prepend "$HOME/.local/bin"
fi
# Enable Starship
if command -v starship >/dev/null 2>&1; then
starship_precmd_user_func="_pre_prompt"
eval "$(starship init bash)"
else
export PROMPT_COMMAND=_pre_prompt
export PROMPT_DIRTRIM=1
_ps1_reset=$(tput sgr0)
export PS1="\n\u@\h: \w\n\\$ \[$_ps1_reset\]"
unset _ps1_reset
fi
if command -v direnv >/dev/null 2>&1; then
eval "$(direnv hook bash)"
fi