-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc_shared
247 lines (213 loc) · 7.4 KB
/
.bashrc_shared
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# This is for Bash settings you want to share across machines.
# Let bootstrap.sh symlink this file, then source it from your local ~/.bash_profile
# [[ -f ~/.bashrc_shared ]] && . ~/.bashrc_shared
if [ -f ~/.secrets ]; then
echo "Applying secrets to your environment"
source ~/.secrets
fi
if [ -f /usr/bin/nvim ] || [ -f /usr/local/bin/nvim ]; then
# Shadow Vim with Neovim.
# Use \vim to bypass the alias.
alias vim="nvim"
export EDITOR=nvim
fi
if [ -f /usr/bin/vimpager ]; then
export PAGER=/usr/bin/vimpager
export VIMPAGER=/usr/bin/vimpager
alias less=$VIMPAGER
if [ -f /usr/bin/nvim ]; then
export VIMPAGER_VIM=/usr/bin/nvim
fi
fi
if [ -f /usr/local/bin/vimpager ]; then
export PAGER=/usr/local/bin/vimpager
export VIMPAGER=/usr/local/bin/vimpager
alias less=$VIMPAGER
if [ -f /usr/local/bin/nvim ]; then
export VIMPAGER_VIM=/usr/local/bin/nvim
fi
fi
# Use git-delta (great for diffs) if it's installed.
if command -v git >/dev/null 2>&1 && command -v delta >/dev/null 2>&1; then
# Core delta setup
git config --global core.pager "delta"
git config --global interactive.diffFilter "delta --color-only"
# Delta's own config
git config --global delta.navigate true
git config --global delta.light false
git config --global delta.side-by-side true
git config --global delta.line-numbers true
git config --global delta.syntax-theme "Dracula"
# Custom colors for diff backgrounds
git config --global delta.minus-style "syntax #450a15"
git config --global delta.plus-style "syntax #0b4820"
git config --global delta.minus-emph-style "syntax #600818"
git config --global delta.plus-emph-style "syntax #0f5323"
fi
# https://wiki.archlinux.org/index.php/.NET_Core#Troubleshooting
export DOTNET_ROOT=/opt/dotnet
export PATH="~/.dotnet/tools:$PATH"
# Rancher Desktop
export PATH="~/.rd/bin:$PATH"
# xset r rate 190 40
# Use the file type backend for aws-vault because this is compatible
# with Linux (needed for Geodesic sessions).
# https://github.com/99designs/aws-vault
# https://docs.cloudposse.com/tools/aws-vault/
export AWS_VAULT_BACKEND="file"
export PATH=~/.local/bin:$PATH
export PATH=~/bin:$PATH
# Start the default OpenSSH agent automatically and make
# sure only one ssh-agent process runs at a time.
if ! pgrep -u "$USER" ssh-agent > /dev/null; then
ssh-agent -t 8h > "$XDG_RUNTIME_DIR/ssh-agent.env"
echo "Running ssh-agent, the default OpenSSH agent, for all terminals."
fi
if [[ ! "$SSH_AUTH_SOCK" ]]; then
if [[ -f "$XDG_RUNTIME_DIR/ssh-agent.env" ]]; then
source "$XDG_RUNTIME_DIR/ssh-agent.env" >/dev/null
else
echo "Warning: ssh-agent environment file not found."
fi
fi
# FZF configuration - check dependencies first
if command -v fzf >/dev/null 2>&1; then
# Base FZF options - check if bat is available for preview
if command -v bat >/dev/null 2>&1; then
preview_cmd='bat --color=always --style=numbers --line-range=:500 {}'
else
preview_cmd='cat {}'
fi
export FZF_DEFAULT_OPTS="--height 60% --layout=reverse --border sharp"
# Add preview options if bat is available
if command -v bat >/dev/null 2>&1; then
export FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --preview '$preview_cmd' --preview-window=right:60%:wrap"
export FZF_CTRL_T_OPTS="--preview '$preview_cmd' --preview-window=right:60%:wrap"
fi
# Basic CTRL-R options (doesn't require additional tools)
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window=down:3:wrap"
# ALT-C preview with eza if available, fallback to tree, then ls
if command -v eza >/dev/null 2>&1; then
export FZF_ALT_C_OPTS="--preview 'eza --tree {} | head -200'"
elif command -v tree >/dev/null 2>&1; then
export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'"
else
export FZF_ALT_C_OPTS="--preview 'ls -la {}'"
fi
# Use fd if available, otherwise fall back to find
if command -v fd >/dev/null 2>&1; then
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_ALT_C_COMMAND='fd --type d --hidden --follow --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
else
export FZF_DEFAULT_COMMAND='find . -type f -not -path "*/\.git/*"'
export FZF_ALT_C_COMMAND='find . -type d -not -path "*/\.git/*"'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
fi
fi
# Checkout git branch (including remote branches) with fzf
gitf() {
git checkout $(git branch --all | fzf | sed 's/remotes\/origin\///')
}
# Kill process
killf() {
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
if [ "x$pid" != "x" ]; then
kill -${1:-9} $pid
fi
}
# Fuzzy file open in Neovim
vf() {
if ! command -v nvim >/dev/null 2>&1; then
echo "Error: Neovim (nvim) is not installed"
return 1
fi
local file
file="$(fzf --preview 'bat --color=always --style=numbers --line-range=:500 {}')"
[ -n "$file" ] && nvim "$file"
}
# Fuzzy file open in VS Code
vsf() {
if ! command -v code >/dev/null 2>&1; then
echo "Error: VS Code (code) is not installed"
return 1
fi
local file
file="$(fzf --preview 'bat --color=always --style=numbers --line-range=:500 {}')"
[ -n "$file" ] && code "$file"
}
# Fuzzy history search and execute
histf() {
local cmd
cmd=$(history | fzf --tac | sed 's/ *[0-9]* *//')
if [ -n "$cmd" ]; then
echo "Executing: $cmd"
eval $cmd
fi
}
# Fuzzy find and cd into directory
cdf() {
local dir
dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m)
if [ -n "$dir" ]; then
cd "$dir"
fi
}
# Fuzzy find in directory contents (uses ripgrep)
rgf() {
if ! command -v rg >/dev/null 2>&1; then
echo "Error: ripgrep (rg) is not installed"
return 1
fi
local file line
read -r file line <<<"$(rg --line-number . | fzf -d ':' --preview 'bat --color=always --highlight-line {2} {1}' | awk -F: '{print $1, $2}')"
if [ -n "$file" ]; then
${EDITOR:-nvim} "$file" +"$line"
fi
}
# Fuzzy find and checkout git commit
commitf() {
local commits commit
commits=$(git log --oneline --color=always | fzf --ansi --preview 'git show --color=always {1}' | awk '{print $1}')
if [ -n "$commits" ]; then
git checkout "$commits"
fi
}
# Fuzzy find git stash and apply
stashf() {
local stash
stash=$(git stash list | fzf --preview 'git stash show --color=always {1}' | cut -d: -f1)
if [ -n "$stash" ]; then
git stash apply "$stash"
fi
}
# Fuzzy find environment variable
envf() {
local var
var=$(printenv | fzf)
if [ -n "$var" ]; then
echo "$var" | tr -d '\n' | pbcopy # Copies to clipboard
echo "Copied to clipboard: $var"
fi
}
# Extract any archive
extract() {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}