forked from Will-Hellinger/college-dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
218 lines (173 loc) · 5.1 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
update_dotfiles() {
local repo_dir="$HOME/.dotfiles"
local repo_url="https://github.com/0mega24/se-dotfiles.git"
local DOTFILES_BASHRC="$repo_dir/.bashrc"
local HOME_BASHRC="$HOME/.bashrc"
local DOTFILES_VIMRC="$repo_dir/.vimrc"
local HOME_VIMRC="$HOME/.vimrc"
if [ ! -d "$repo_dir" ]; then
git clone "$repo_url" "$repo_dir"
else
(cd "$repo_dir" && git pull origin main)
fi
# backup bashrc if it exists
if [ -f "$HOME_BASHRC" ] && [ ! -L "$HOME_BASHRC" ]; then
mv "$HOME_BASHRC" "${HOME_BASHRC}.bak"
fi
if [ ! -L "$HOME_BASHRC" ]; then
if [ -f "$DOTFILES_BASHRC" ]; then
ln -s "$DOTFILES_BASHRC" "$HOME_BASHRC"
else
echo "dotfiles .bashrc not found. Symlink not created."
fi
fi
# backup vimrc if it exists
if [ -f "$HOME_VIMRC" ] && [ ! -L "$HOME_VIMRC" ]; then
mv "$HOME_VIMRC" "$HOME_VIMRC.bak"
fi
if [ ! -L "$HOME_VIMRC" ]; then
if [ -f "$DOTFILES_VIMRC" ]; then
ln -s "$DOTFILES_VIMRC" "$HOME_VIMRC"
else
echo "dotfiles .vimrc not found. Symlink not created."
fi
fi
export PATH="$HOME/.tools:$PATH"
}
install_vim_plug() {
if [ ! -d $HOME/.vim/autoload/plug.vim ]; then
echo "vim plugin folder not located | Installing now..."
mkdir "$HOME/.vim"
mkdir "$HOME/.vim/autoload"
curl -L https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim -o "$HOME/.vim/autoload/plug.vim"
fi
export PATH="$HOME/.tools:$PATH"
}
update_vim_plug() {
rm -rf "$HOME/.vim/autoload/plug.vim"
install_vim_plug
}
get_tools() {
local tmux_url="https://github.com/nelsonenzo/tmux-appimage/releases/download/3.3a/tmux.appimage"
local neovim_url="https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage"
local fastfetch_url="https://github.com/fastfetch-cli/fastfetch/releases/download/2.6.0/fastfetch-2.6.0-Linux.zip"
local btop_url="https://github.com/aristocratos/btop/releases/download/v1.3.0/btop-x86_64-linux-musl.tbz"
local tools_dir="$HOME/.tools"
mkdir -p "$tools_dir"
if [ ! -f "$tools_dir/tmux" ]; then
echo "Downloading tmux..."
wget -O "$tools_dir/tmux" "$tmux_url" || curl -L "$tmux_url" -o "$tools_dir/tmux"
chmod +x "$tools_dir/tmux"
echo "Done setting up tmux"
fi
if [ ! -f "$tools_dir/neovim" ]; then
echo "Downloading neovim..."
wget -O "$tools_dir/neovim" "$neovim_url" || curl -L "$neovim_url" -o "$tools_dir/neovim"
chmod +x "$tools_dir/neovim"
echo "Done setting up neovim"
fi
if [ ! -f "$tools_dir/fastfetch" ]; then
echo "Downloading fastfetch..."
wget -O fastfetch.zip "$fastfetch_url" || curl -L "$fastfetch_url" -o fastfetch.zip
unzip fastfetch.zip
rm fastfetch.zip
mv "./fastfetch-2.6.0-Linux/usr/bin/fastfetch" "$tools_dir/fastfetch"
rm -rf "fastfetch-2.6.0-Linux"
echo "Done setting up fastfetch"
fi
if [ ! -f "$tools_dir/btop" ]; then
echo "Downloading btop..."
wget -O btop.tbz "$btop_url" || curl -L "$btop_url" -o btop.tbz
tar -xjf btop.tbz
rm btop.tbz
mv "./btop/bin/btop" "$tools_dir/btop"
rm -rf "btop"
echo "done setting up btop"
fi
export PATH="$HOME/.tools:$PATH"
}
update_tools() {
rm -rf "$HOME/.tools"
get_tools
}
update() {
update_dotfiles
update_tools
update_vim_plug
cl
}
tmux() {
"$HOME/.tools/tmux" "$@"
}
set_tmux_settings() {
tmux set -g mouse on
}
neovim() {
"$HOME/.tools/neovim" "$@"
}
extract() {
if [ -z "$1" ]; then
echo "Usage: extract <path/filename>"
return 1
fi
if [ -f "$1" ]; then
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$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
}
userlist() {
local option=${1:-all}
local online_users=$(who | cut -d' ' -f1 | sort | uniq)
local all_users=$(awk -F':' '{print $1}' /etc/passwd)
case "$option" in
online)
echo -e "Online Users:"
for user in $online_users; do
echo -e "\e[32m$user\e[0m"
done
;;
offline)
echo -e "Offline Users:"
for user in $all_users; do
if ! [[ $online_users =~ $user ]]; then
echo -e "\e[31m$user\e[0m"
fi
done
;;
esac
}
server_info() {
local online_users=$(who | cut -d' ' -f1 | sort | uniq)
local online_user_count=$(echo "$online_users" | wc -l)
local current_user=$(whoami)
echo -e "Welcome to RIT Servers!"
echo -e "Current time is: $(date)"
if [ "$online_user_count" -eq 1 ] && [[ $online_users == *"$current_user"* ]]; then
echo -e "There is 1 user\e[32m online\e[0m - You!"
else
echo -e "There are $online_user_count user(s)\e[32m online\e[0m!"
fi
}
cl() {
clear
fastfetch
server_info
}
update_dotfiles
get_tools
install_vim_plug
cl