-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.shell_common
More file actions
214 lines (192 loc) · 6.09 KB
/
Copy path.shell_common
File metadata and controls
214 lines (192 loc) · 6.09 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
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
#!/bin/sh
# Common shell configuration shared between bash and zsh
# Sourced by both ~/.bashrc and ~/.zshrc
#------------------------------------------////
# Colors:
#------------------------------------------////
black='\e[0;30m'
blue='\e[0;34m'
green='\e[0;32m'
cyan='\e[0;36m'
red='\e[0;31m'
purple='\e[0;35m'
brown='\e[0;33m'
lightgray='\e[0;37m'
darkgray='\e[1;30m'
lightblue='\e[1;34m'
lightgreen='\e[1;32m'
lightcyan='\e[1;36m'
lightred='\e[1;31m'
lightpurple='\e[1;35m'
yellow='\e[1;33m'
white='\e[1;37m'
nc='\e[0m'
IP_DEVICE='eth0'
#------------------------------------------////
## FUNCTIONS
#------------------------------------------////
welcome() {
#------------------------------------------
#------WELCOME MESSAGE---------------------
# customize this first message with a message of your choice.
# this will display the username, date, time, a calendar, the amount of users, and the up time.
#clear
# Gotta love ASCII art with figlet
if command -v figlet &>/dev/null; then
figlet "Welcome, " "$USER"
else
echo "Welcome, $USER"
fi
#toilet "Welcome, " $USER;
echo -e ""
if command -v cal &>/dev/null; then
cal
fi
echo -ne "Today is "
date #date +"Today is %A %D, and it is now %R"
echo -e ""
echo -ne "Up time:"
uptime | awk /'up/'
echo -en "Local IP Address :"
if command -v ip &>/dev/null; then
ip -4 addr show ${IP_DEVICE} 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1
elif command -v ifconfig &>/dev/null; then
ifconfig ${IP_DEVICE} 2>/dev/null | awk /'inet / {print $2}' | sed -e s/addr:/' '/
else
echo "N/A"
fi
echo ""
}
# get IP adresses
my_ip() {
if command -v ip &>/dev/null; then
MY_IP=$(ip -4 addr show ${IP_DEVICE} 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1)
elif command -v ifconfig &>/dev/null; then
MY_IP=$(ifconfig ${IP_DEVICE} 2>/dev/null | awk /'inet addr/ {print $2}')
MY_ISP=$(ifconfig ${IP_DEVICE} 2>/dev/null | awk "/P-t-P/ { print $3 } " | sed -e s/P-t-P://)
fi
}
# get current host related info
ii() {
echo -e "\nYou are logged on ${red}$HOST"
echo -e "\nAdditionnal information:$NC "
uname -a
echo -e "\n${red}Users logged on:$NC "
w -h
echo -e "\n${red}Current date :$NC "
date
echo -e "\n${red}Machine stats :$NC "
uptime
echo -e "\n${red}Memory stats :$NC "
free
echo -en "\n${red}Local IP Address :$NC"
if command -v ip &>/dev/null; then
ip -4 addr show ${IP_DEVICE} 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1
elif command -v ifconfig &>/dev/null; then
ifconfig ${IP_DEVICE} 2>/dev/null | awk /'inet / {print $2}' | sed -e s/addr:/' '/
else
echo "N/A"
fi
echo
}
# Easy extract
extract() {
if [ -f "$1" ]; then
case $1 in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2)
if command -v bunzip2 &>/dev/null; then
bunzip2 "$1"
else
echo "bunzip2 not found. Install bzip2 package."
fi
;;
*.rar)
if command -v unrar &>/dev/null; then
unrar x "$1"
elif command -v rar &>/dev/null; then
rar x "$1"
else
echo "unrar/rar not found. Install unrar package."
fi
;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip)
if command -v unzip &>/dev/null; then
unzip "$1"
else
echo "unzip not found. Install unzip package."
fi
;;
*.Z) uncompress "$1" ;;
*.7z)
if command -v 7z &>/dev/null; then
7z x "$1"
else
echo "7z not found. Install p7zip-full package."
fi
;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
upinfo() {
echo -ne "${green}${HOST}${HOSTNAME} ${red}uptime is ${cyan} \t "
uptime | awk /'up/ {print $3,$4,$5,$6,$7,$8,$9,$10}'
}
# Makes directory then moves into it
mkcdr() {
mkdir -p -v "$1"
cd "$1" || exit
}
# kill all by name https://stackoverflow.com/a/30515012
killAllByName() {
ps -ef | grep "$1" | grep -v grep | awk '{print $2}' | xargs -r kill -9
}
#------------------------------------------////
## ALIASES
#------------------------------------------////
# ls aliases
alias ll='ls -alF'
alias la='ls -a'
# Utility aliases
alias biggest='BLOCKSIZE=1048576; du -x | sort -nr | head -10'
alias wget='wget -c'
alias trash='mv -t ~/.local/share/Trash/files'
alias ps-aux='ps axo user:20,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,comm'
# Docker helper methods
alias docker-cleanup='docker container prune -f; docker image prune -f; docker rmi $(docker images --quiet --filter "dangling=true"); docker volume prune -f ; docker system prune -f;'
# Claude Code alias
alias claude-yolo='claude --dangerously-skip-permissions'
#------------------------------------------////
## ENVIRONMENT VARIABLES
#------------------------------------------////
export http_proxy= #"Page on 168"
# NVM setup
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Add local bin to PATH
export PATH="$HOME/.local/bin:$PATH"
# de-dupe PATH (works in both bash and zsh)
if command -v perl &>/dev/null; then
PATH="$(perl -e 'print join(":", grep { not $seen{$_}++ } split(/:/, $ENV{PATH}))')"
fi
# GitHub Token - SECURITY WARNING: Do not store tokens in plaintext!
# Consider using a credential manager or environment-specific config
# export GITHUB_TOKEN="your_token_here"
if [ -f "$HOME/.github_token" ]; then
export GITHUB_TOKEN=$(cat "$HOME/.github_token")
fi
# SSH agent (with conditional check for file existence)
if [ -f "$HOME/.ssh-agent.sh" ]; then
. "$HOME/.ssh-agent.sh"
fi
# Call welcome message
welcome