Skip to content

Commit da5b65d

Browse files
Adrien FolieAdrien Folie
authored andcommitted
feat: add bash config
1 parent c1c891f commit da5b65d

File tree

4 files changed

+167
-0
lines changed

4 files changed

+167
-0
lines changed

bash/bash_profile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Load .bashrc for login shells
2+
[[ -f ~/.bashrc ]] && source ~/.bashrc
3+

bash/bashrc

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# If not running interactively, don't do anything
2+
[[ $- != *i* ]] && return
3+
4+
# Environment variables
5+
export EDITOR=vim
6+
export SHELL=$(which bash)
7+
export TERM=xterm-256color
8+
export LC_ALL=en_US.UTF-8
9+
export PAGER=most
10+
11+
# Prompt configuration
12+
# Colors
13+
RESET="\[\033[0m\]"
14+
RED="\[\033[0;31m\]"
15+
YELLOW="\[\033[0;33m\]"
16+
BLUE="\[\033[0;34m\]"
17+
WHITE="\[\033[0;37m\]"
18+
GREEN="\[\033[0;32m\]"
19+
PURPLE="\[\033[0;35m\]"
20+
21+
# Git prompt symbols
22+
GIT_PROMPT_PREFIX="["
23+
GIT_PROMPT_SUFFIX="]"
24+
GIT_PROMPT_SEPARATOR="|"
25+
GIT_PROMPT_STAGED="$RED"
26+
GIT_PROMPT_CONFLICTS="$RED"
27+
GIT_PROMPT_CHANGED="$BLUE"
28+
GIT_PROMPT_UNTRACKED=""
29+
GIT_PROMPT_STASHED=""
30+
GIT_PROMPT_CLEAN="$GREEN"
31+
32+
# Git status function
33+
git_status() {
34+
local branch staged conflicts changed untracked stashed clean
35+
36+
# Get current branch
37+
branch=$(git symbolic-ref HEAD 2>/dev/null)
38+
if [[ -n "$branch" ]]; then
39+
branch=${branch##*/}
40+
41+
# Count staged files
42+
staged=$(git diff --staged --numstat | wc -l)
43+
# Count conflicts
44+
conflicts=$(git diff --name-only --diff-filter=U | wc -l)
45+
# Count changed files
46+
changed=$(git diff --numstat | wc -l)
47+
# Count untracked files
48+
untracked=$(git ls-files --others --exclude-standard | wc -l)
49+
# Check if stash exists
50+
if [[ -n $(git stash list) ]]; then
51+
stashed=1
52+
else
53+
stashed=0
54+
fi
55+
# Check if clean
56+
if [[ $staged -eq 0 && $conflicts -eq 0 && $changed -eq 0 && $untracked -eq 0 ]]; then
57+
clean=1
58+
else
59+
clean=0
60+
fi
61+
62+
# Build status string
63+
local status="$GIT_PROMPT_PREFIX$PURPLE$branch$RESET$GIT_PROMPT_SEPARATOR"
64+
65+
[[ $staged -gt 0 ]] && status+="$GIT_PROMPT_STAGED"
66+
[[ $conflicts -gt 0 ]] && status+="$GIT_PROMPT_CONFLICTS"
67+
[[ $changed -gt 0 ]] && status+="$GIT_PROMPT_CHANGED"
68+
[[ $untracked -gt 0 ]] && status+="$GIT_PROMPT_UNTRACKED"
69+
[[ $stashed -gt 0 ]] && status+="$GIT_PROMPT_STASHED"
70+
[[ $clean -eq 1 ]] && status+="$GIT_PROMPT_CLEAN"
71+
72+
echo -n "$status$RESET$GIT_PROMPT_SUFFIX"
73+
fi
74+
}
75+
76+
# Set prompt command
77+
PROMPT_COMMAND=__prompt_command
78+
79+
__prompt_command() {
80+
local EXIT="$?"
81+
local PATH_SHORT="${PWD/#$HOME/\~}"
82+
local TIME="\$(date +%R)"
83+
84+
PS1="$YELLOW$PATH_SHORT$RESET"
85+
86+
# Add git status if in a git repository
87+
if git rev-parse --git-dir > /dev/null 2>&1; then
88+
PS1+=" \$(git_status)"
89+
fi
90+
91+
PS1+="\n$WHITE$TIME$RESET \$ "
92+
}
93+
94+
# rbenv setup
95+
if command -v rbenv >/dev/null 2>&1; then
96+
export PATH="$HOME/.rbenv/bin:$PATH"
97+
eval "$(rbenv init -)"
98+
fi
99+
100+
# nvm setup
101+
export NVM_DIR="$HOME/.nvm"
102+
export NVM_DEFAULT_VERSION=20
103+
104+
if [ -d "$NVM_DIR" ]; then
105+
[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"
106+
[ -s "$NVM_DIR/bash_completion" ] && source "$NVM_DIR/bash_completion"
107+
command -v nvm >/dev/null 2>&1 && nvm use "$NVM_DEFAULT_VERSION" >/dev/null 2>&1
108+
fi
109+
110+
# golang configuration
111+
if command -v go >/dev/null 2>&1; then
112+
export GOPATH="$HOME/dev/go"
113+
fi
114+
115+
# brew configuration
116+
if command -v brew >/dev/null 2>&1; then
117+
alias python=/opt/homebrew/bin/python3
118+
fi
119+
120+
# PATH modifications
121+
if [ -d "$HOME/.cargo/bin" ]; then
122+
export PATH="$HOME/.cargo/bin:$PATH"
123+
fi
124+
125+
# Vi mode
126+
set -o vi
127+
128+
# Aliases
129+
alias ll='ls -lF'
130+
alias la='ls -lA'
131+
alias git='hub'
132+
133+
# Load all configurations from conf.d
134+
if [ -d "$HOME/.config/bash/conf.d" ]; then
135+
for file in "$HOME/.config/bash/conf.d"/*.sh; do
136+
[ -r "$file" ] && source "$file"
137+
done
138+
fi
139+
140+
# Load local customizations if they exist
141+
[ -f "$HOME/.bashrc.local" ] && source "$HOME/.bashrc.local"
142+

bash/conf.d/tools.sh

Whitespace-only changes.

bash/install.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
CONFIG_DIR="$HOME/.config/bash"
7+
8+
# Create necessary directories
9+
mkdir -p "$CONFIG_DIR/conf.d"
10+
11+
# Create symlinks
12+
ln -sf "$SCRIPT_DIR/bashrc" "$HOME/.bashrc"
13+
ln -sf "$SCRIPT_DIR/bash_profile" "$HOME/.bash_profile"
14+
ln -sf "$SCRIPT_DIR/conf.d" "$CONFIG_DIR/"
15+
16+
# Install dependencies if they don't exist
17+
command -v hub >/dev/null 2>&1 || echo "Warning: 'hub' is not installed. Install it for git alias functionality."
18+
command -v rbenv >/dev/null 2>&1 || echo "Warning: 'rbenv' is not installed. Install it for Ruby version management."
19+
20+
echo "Bash configuration installed successfully!"
21+
echo "Please restart your shell or run 'source ~/.bashrc' to apply changes."
22+

0 commit comments

Comments
 (0)