Repository navigation
Expand file tree
/
Copy pathdot_bashrc
More file actions
159 lines (135 loc) · 3.95 KB
/
Copy pathdot_bashrc
File metadata and controls
159 lines (135 loc) · 3.95 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# All the default Omarchy aliases and functions
# (don't mess with these directly, just overwrite them here!)
source ~/.local/share/omarchy/default/bash/rc
# =============================================================================
# EXPORTS & ENVIRONMENT
# =============================================================================
eval "$(starship init bash)"
eval "$(zoxide init bash)"
export VISUAL=nvim
export EDITOR="$VISUAL"
export TERMINAL="ghostty"
export SHELL="/bin/bash"
# User-local binaries
export PATH="$HOME/.local/bin:$PATH"
# Rust / Cargo
export PATH="$HOME/.cargo/bin:$PATH"
# Nix profile binaries
if [ -d "$HOME/.nix-profile/bin" ]; then
export PATH="$HOME/.nix-profile/bin:$PATH"
fi
# Optional: custom scripts
# export PATH="$HOME/scripts:$PATH"
# Deno environment
. "/home/johan/.deno/env"
# Nix profile
if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
fi
# =============================================================================
# ALIASES
# =============================================================================
alias t=tango
alias chezadd=chezmoi_readd
alias hidebt=hide_bt
alias nv=nvim
# =============================================================================
# FUNCTIONS
# =============================================================================
tm() {
if [ -n "$TMUX" ]; then
current=$(tmux display-message -p '#S' 2>/dev/null)
[ -n "$current" ] && tmux kill-session -t "$current"
exec tmux new -s "$current"
else
tmux attach || tmux new -s main
fi
}
# Shortcuts
nup() { upgrade nvim-nix; }
tup() { upgrade tmux && tmux kill-server; }
upgrade() {
if [ -z "$1" ]; then
echo "Usage: upgrade <package>"
return 1
fi
if nix profile upgrade "$1"; then
notify-send "Nix Upgrade" "Successfully upgraded $1"
else
notify-send "Nix Upgrade" "Failed to upgrade $1"
fi
}
# Start and hide Bluetooth
hide_bt() {
bluetoothctl power on
bluetoothctl pairable off
bluetoothctl discoverable off
}
# Chezmoi configuration management
chezmoi_readd() {
local base_targets=(
"$HOME/.bash_logout"
"$HOME/.bash_profile"
"$HOME/.bashrc"
"$HOME/.nanorc"
"$HOME/workspace"
)
# Add base targets
for t in "${base_targets[@]}"; do
[ -e "$t" ] && echo "HOME: Adding $t" && chezmoi add "$t"
done
# Add config directories (excluding specific ones)
find "$HOME/.config" \
-mindepth 1 -maxdepth 1 \
! -name 'chezmoi' \
! -name 'chromium' \
! -name 'gh' \
! -name 'vesktop' \
! -name 'github-copilot' \
! -name 'Signal' \
! -name 'omarchy' \
! -name '.git' \
! -name '*~' \
! -name '*.lock' |
while read -r entry; do
echo "CONFIG: Adding $entry" && chezmoi add "$entry"
done
# Optional Git operations
read -p "Add/Commit/Push chezmoi repository? [y/N] " answer
case "$answer" in
[Yy])
git -C "$HOME/.local/share/chezmoi" add .
git -C "$HOME/.local/share/chezmoi" commit -m "update"
git -C "$HOME/.local/share/chezmoi" push
;;
*)
echo "Skipping add, commit and push to GitHub"
;;
esac
}
# =============================================================================
# INTERACTIVE SHELL SETUP
# =============================================================================
if command -v tmux &>/dev/null; then
[ -z "$TMUX" ] && exec tmux
fi
# SSH agent setup
if [[ $- == *i* ]]; then
if ! ssh-add -l >/dev/null 2>&1; then
eval "$(ssh-agent -s)" >/dev/null 2>&1
for key in "$HOME/.ssh"/*; do
[[ -f "$key" ]] || continue
# Skip public keys and certificates
case "$key" in
*.pub | *-cert.pub) continue ;;
esac
# Add private keys
if grep -Iq "PRIVATE KEY" "$key" 2>/dev/null ||
grep -Iq "BEGIN SSH2 ENCRYPTED PRIVATE KEY" "$key" 2>/dev/null; then
if ! ssh-add "$key" >/dev/null 2>&1; then
echo "ssh-add failed or required passphrase for: $key"
fi
fi
done
fi
fi