-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
253 lines (202 loc) · 5.71 KB
/
.bashrc
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
248
249
250
251
252
253
# Path
# PATH=/run/current-system/sw/bin:$PATH
# Env vars
export EDITOR=nvim
export SUDO_EDITOR=nvim
# export NODE_SKIP_PLATFORM_CHECK=1
export ANDROID_HOME=~/Android/Sdk
# Node apps
export PATH=$HOME/.npm-packages/bin:$PATH
# Deno apps
export PATH=$HOME/.deno/bin:$PATH
# Cargo apps
export PATH=$HOME/.cargo/bin:$PATH
# Misc tools
export PATH=$HOME/Tools:$PATH
# Man page settings
export BROWSER=google-chrome-stable
alias man-web='man --html'
# Nix
alias nix-stray-roots='nix-store --gc --print-roots | egrep -v "^(/nix/var|/run/\w+-system|\{memory)"'
# SSH setup
alias set-key='eval `ssh-agent -s` && ssh-add ~/.ssh/id_rsa'
# List path
alias list-path='tr ":" "\n" <<< "$PATH"'
# PostgreSQL database config
export PGUSER=admin
export PGDATABASE=central
# Java config
# export JAVA_HOME=$(readlink -e $(type -p javac) | sed -e 's/\/bin\/javac//g')
# Golang config
# export PATH=$PATH:$HOME/app/go/bin
# SSH config
alias setup-ssh='eval `ssh-agent -s` && ssh-add ~/.ssh/id_rsa'
# Refresh desktop after installs
alias refresh-desktop='xfce4-panel -r && xfwm4 --replace &'
# Video downloader
yt_vdq () {
local playlist=''
local items=''
if [[ -n $4 ]]; then
playlist='%(playlist_autonumber)s-'
items="--playlist-items $4"
else
playlist=''
items=''
fi
local pString="yt-dlp --add-metadata --embed-metadata --embed-chapters --all-subs --embed-subs --embed-thumbnail -o ${playlist}%(title)s-%(id)s.%(ext)s -f"
if [[ -n $4 ]]; then
${pString} $3$2 $1 ${items}
elif [[ -n $3 ]]; then
${pString} $3$2 $1
else
${pString} $2 $1
fi
}
# Playlist downloader with subtitle embedding and separate subtitle file download
yt_vdp () {
local subtitle_lang="en.*,ja"
yt-dlp --embed-subs --sub-langs ${subtitle_lang} --write-subs -f $3 -o "%(playlist)s/%(playlist_index)s - %(title)s-%(id)s.%(ext)s" $1 -I "$2"
}
# DroidCam
detect_alsa_device () {
pacmd load-module module-alsa-source device=hw:Loopback,1,0
}
# SSH setup
unlock_ssh () {
# eval `ssh-agent`
ssh-add ~/.ssh/id_rsa
}
unlock_ssh2 () {
# eval `ssh-agent`
ssh-add ~/.ssh/id_rsa2
}
unlock_ssh3 () {
# eval `ssh-agent`
ssh-add ~/.ssh/id_rsa3
}
unlock_ssh4 () {
# eval `ssh-agent`
ssh-add ~/.ssh/id_rsa4
}
lock_ssh () {
# eval `ssh-agent`
ssh-add -d ~/.ssh/id_rsa
}
lock_ssh2 () {
# eval `ssh-agent`
ssh-add -d ~/.ssh/id_rsa2
}
lock_ssh3 () {
# eval `ssh-agent`
ssh-add -d ~/.ssh/id_rsa3
}
lock_ssh4 () {
# eval `ssh-agent`
ssh-add -d ~/.ssh/id_rsa4
}
unlock_ed25519 () {
# eval `ssh-agent`
ssh-add ~/.ssh/id_ed25519
}
lock_ed25519 () {
# eval `ssh-agent`
ssh-add -d ~/.ssh/id_ed25519
}
#--- Network mgmt helper funcs---#
# Function to start tcpdump for a given PID
capture_traffic() {
if [ -z "$1" ]; then
echo "Usage: capture_traffic <PID>"
return 1
fi
PID=$1
OUTPUT_FILE="capture_${PID}.pcap"
echo "Starting tcpdump for PID $PID..."
sudo tcpdump -i any -w "$OUTPUT_FILE" "pid $PID"
echo "Traffic capture started. Output saved to $OUTPUT_FILE."
}
# fzf setup
export FZF_DEFAULT_COMMAND='fd --type f'
# Nix shell setup
if [ -n "$IN_NIX_SHELL" ]; then
PS1="(nix-shell)$PS1"
fi
# Retry on fail command
retry_command() {
cmd="$@"
while true; do
$cmd
exit_code=$?
if [ $exit_code -eq 0 ]; then
break # Command succeeded, exit the loop
else
echo "Command '$cmd' failed with exit code $exit_code. Retrying in 1 minute..."
sleep 10 # Wait for 10 seconds before retrying
fi
done
}
retry_sudo() {
cmd="$@"
# Start a background process to continuously refresh sudo access
refresh_sudo() {
while true; do
sudo -v
sleep 25
done
}
# Run the command in the foreground
(
# Start the background process to refresh sudo access
refresh_sudo &
while true; do
sudo -n $cmd < /dev/null
exit_code=$?
# Kill the background process if the command succeeded
if [ $exit_code -eq 0 ]; then
pkill -P $$
break # Command succeeded, exit the loop
else
echo "Command '$cmd' failed with exit code $exit_code. Retrying in 1 minute..."
sleep 10 # Wait for 10 seconds before retrying
fi
done
)
}
# Backups
backup_cyberpunk () {
rsync -avP "/run/media/ryan/ubuntu/SteamLibrary/steamapps/compatdata/1091500/pfx/drive_c/users/steamuser/Saved Games/CD Projekt Red/Cyberpunk 2077" /run/media/ryan/ubuntu/SaveBackups/
}
# Managers
. "$HOME/.asdf/asdf.sh"
. "$HOME/.asdf/completions/asdf.bash"
set -h # Fixes "bash: hash: hashing disabled" warning triggered by below code
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" > /dev/null # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# pnpm
export PNPM_HOME="/home/ryan/.local/share/pnpm"
case ":$PATH:" in
*":$PNPM_HOME:"*) ;;
*) export PATH="$PNPM_HOME:$PATH" ;;
esac
# pnpm end
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
# __conda_setup="$('/home/ryan/.conda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
# if [ $? -eq 0 ]; then
# eval "$__conda_setup"
# else
# if [ -f "/home/ryan/.conda/etc/profile.d/conda.sh" ]; then
# . "/home/ryan/.conda/etc/profile.d/conda.sh"
# else
# export PATH="/home/ryan/.conda/bin:$PATH"
# fi
# fi
# unset __conda_setup
# <<< conda initialize <<<
# tabtab source for packages
# uninstall by removing these lines
[ -f ~/.config/tabtab/bash/__tabtab.bash ] && . ~/.config/tabtab/bash/__tabtab.bash || true
eval "$(direnv hook bash)"
complete -C /home/ryan/Tools/terraform terraform