I guess I just got tired of re-configuring my linux distros each time I installed a new one from scratch.
(copy and paste code below)
set constantshow
- Always display the cursor position at the bottom of the editor
set linenumbers
- Show line numbers on the left side of the editor
set numbercolor cyan,black
- Set the color of the line numbers to cyan text on a black background
hardstatus on
- Turn on the hardstatus line
hardstatus alwaysfirstline
- Place the hardstatus line at the top of the screen
hardstatus string '%{= wk}Screen: %S %= [%c]'
- Customize the hardstatus line format
- %{= wk} - Set text to white on black background
- Screen: %S - Display "Screen: " followed by the session name (%S)
- %= - Push everything after this to the far right
- [%c] - Display current time in HH:MM format, surrounded by square brackets
defscrollback 10000
- Set the scrollback buffer size to 10000 lines
defutf8 on
- Enable UTF-8 support
startup_message off
- Disable the startup message when screen starts
case $- in
i) ;;
*) return;;
esac
- case $- in ... esac: This checks the current shell options.
- i) ;;: If the shell is interactive (i is present in $-), do nothing (;;).
- *) return;;: If the shell is not interactive, exit the script (return).
HISTCONTROL=ignoreboth
- HISTCONTROL=ignoreboth: Sets the shell history to ignore duplicate entries and commands that start with a space.
shopt -s histappend
- shopt -s histappend: Enables appending to the history file, rather than overwriting it.
HISTSIZE=1000
HISTFILESIZE=2000
- HISTSIZE=1000: Sets the number of commands to remember in the command history.
- HISTFILESIZE=2000: Sets the maximum number of lines contained in the history file.
shopt -s checkwinsize
- shopt -s checkwinsize: After each command, checks the window size and updates LINES and COLUMNS if necessary.
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
- Checks if the debian_chroot variable is unset or empty and if /etc/debian_chroot is readable.
- If both conditions are met, it sets debian_chroot to the contents of /etc/debian_chroot.
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
- Checks if the terminal supports color (xterm-color or *-256color).
- If so, sets color_prompt=yes.
force_color_prompt=yes
- Forces the color prompt to be enabled.
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
color_prompt=yes
else
color_prompt=
fi
fi
- Checks if force_color_prompt is set.
- If tput exists and can set terminal colors, it sets color_prompt=yes.
- Otherwise, it sets color_prompt to empty.
if [ "$color_prompt" = yes ]; then
if [ "$(id -u)" -eq 0 ]; then
PS1='${debian_chroot:+($debian_chroot)}[\033[5;31m]\u\e[25m@\h[\033[00m]:[\033[01;34m]\w #[\033[00m] '
else
PS1='${debian_chroot:+($debian_chroot)}[\033[01;32m]\u@\h[\033[00m]:[\033[01;34m]\w \$[\033[00m] '
fi
else
if [ "$(id -u)" -eq 0 ]; then
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w # '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w $ '
fi
fi
unset color_prompt force_color_prompt
- Sets the prompt (PS1) based on whether color_prompt is set.
- If the user is root (id -u equals 0), the prompt ends with #, otherwise with $.
- The colors are different for root (\033[01;31m for red) and non-root users (\033[01;32m for green).
case "$TERM" in
xterm*|rxvt*)
PS1="[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a]$PS1"
;;
*)
;;
esac
- If the terminal is xterm or rxvt, sets the terminal title to user@host: dir.
if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi
- Checks if dircolors exists and is executable.
- If ~/.dircolors is readable, evaluates it for setting up color definitions.
- Sets up color aliases for ls, grep, fgrep, and egrep.
diffy() {
diff -y -B <(grep -vE '^\s*#' "$1") <(grep -vE '^\s*#' "$2")
}
- Defines the diffy function to compare two files, ignoring lines that start with a comment (#) or are empty.
catta() {
if [[ -n "$1" ]]; then
for texts in $(file "$1"* | grep text | awk '{print $1}' | sed 's/.$\//' ); do
echo -e "\n\n\e[4m\e[93m${texts}\e[0m\n"
cat "${texts}"
done
else
for texts in $(file ./* | grep text | awk '{print $1}' | sed 's/.$\//' ); do
echo -e "\n\n\e[4m\e[93m${texts}\e[0m\n"
cat "$texts"
done
fi
}
- Defines the catta function to display contents of text files.
- If a file pattern is provided, it processes files matching the pattern.
- Otherwise, it processes all text files in the current directory.
- Each file's name is highlighted and separated for readability.
alias ll='ls -l'
alias la='ls -la'
alias lh='ls -lah'
alias cd..='cd ..' alias go='apt update -y && apt upgrade -y && apt dist-upgrade && apt full-upgrade'
- Sets up aliases for common ls commands and a cd shortcut for a common typo I make as wlel as using
goto do all the updates it can.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
- If ~/.bash_aliases exists, sources it to load additional aliases.
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
- If the shell is not in POSIX mode, checks for bash_completion files and sources them to enable programmable completion features.
Checks if we can resolve names if not, adds Cloudflare and Quad9 name servers If we're root, installs Curl and Sudo
if [[ $(ping -c1 -q www.google.com &>/dev/null; echo $?) -ne 0 ]]; then
if [[ $(grep -vcE '^$|^#' /etc/resolv.conf) -eq 0 ]]; then
echo -e "\nnameserver 1.1.1.2\nnameserver 9.9.9.9" >> /etc/resolv.conf
sleep 3
if [[ $(ping -c1 -q www.google.com &>/dev/null; echo $?) -ne 0 ]]; then
echo -e " ALERT!\nAdded Cloudflare and Quad9 nameservers, but still not resolving domain names!"
else
[[ $(id -u) -eq "0" ]] && apt install -y curl sudo
fi
fi
fi
cat <<"EOF" > ~/.bashrc
case $- in
*i*) ;;
*) return;;
esac
HISTCONTROL=ignoreboth
shopt -s histappend
HISTSIZE=1000
HISTFILESIZE=2000
shopt -s checkwinsize
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
if [ "$(id -u)" -eq 0 ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[5;31m\]\u\[\e[25m\]@\h\[\033[00m\]:\[\033[01;34m\]\w #\[\033[00m\] '
else
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \$\[\033[00m\] '
fi
else
if [ "$(id -u)" -eq 0 ]; then
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w # '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w \$ '
fi
fi
unset color_prompt force_color_prompt
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
diffy() {
diff -y -B <(grep -vE '^\s*#' "$1") <(grep -vE '^\s*#' "$2")
}
catta() {
if [[ -n "$1" ]]; then
for texts in $(file "$1"* | grep text | awk '{print $1}' | sed 's/.$//'); do
echo -e "
\e[4m\e[93m${texts}\e[0m
"
cat "${texts}"
done
else
for texts in $(file ./* | grep text | awk '{print $1}' | sed 's/.$//'); do
echo -e "
\e[4m\e[93m${texts}\e[0m
"
cat "$texts"
done
fi
}
alias ll='ls -l'
alias la='ls -la'
alias lh='ls -lah'
alias cd..='cd ..'
alias update='apt update -y && apt upgrade -y && apt dist-upgrade && apt full-upgrade'
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
EOF
cat <<"EOF" > ~/.nanorc
set constantshow
set linenumbers
set numbercolor cyan,black
EOF
INTERFACE=""
IPADD=""
IPMASK=""
IPGATE=""
GETINTERFACE() {
INTERFACE=$(cat /etc/network/interfaces | grep -E '^iface.*dhcp$' | awk '{print $2}')
}
GETMASK() {
read -rp "
What should the netmask be (IP address, not CIDR)?
" IPMASK
if [[ ! $IPMASK =~ ([0-9]+\.){3}[0-9]{1,3} ]]; then
echo "Please use x.x.x.x format to enter net mask."
GETMASK
fi
}
GETGATE() {
read -rp "
What should the Gateway be?
" IPGATE
if [[ ! $IPGATE =~ ([0-9]+\.){3}[0-9]{1,3} ]]; then
echo "Please use x.x.x.x format to enter gateway address."
GETGATE
fi
}
GETIP() {
echo -e " Current IP is: $(ip a | grep inet | gpre -vE 'host lo|inet6' | awk '{print $2}')"
read -rp "
What should the IP be for this host?
" IPADD
if [[ ! $IPADD =~ ([0-9]+\.){3}[0-9]{1,3} ]]; then #I know, I know, this regex is utter drivel and needs to be improved.
echo "Yeah, no, give me a valid IPv4 address (no netmask)."
GETIP
fi
}
SETSTATIC() {
sed -i "s/iface $INTERFACE inet dhcp/iface $INTERFACE inet static/" /etc/network/interfaces
echo -e " address $IPADD\n netmask $IPMASK\n gateway $IPGATE" >> /etc/network/interfaces
}
if [[ $(id -u) -eq "0" ]]; then
if grep -q dhcp /etc/network/interfaces; then
GETINTERFACE
GETIP
GETMASK
GETGATE
SETSTATIC
fi
fi
if [[ $(ping -c1 -q www.google.com &>/dev/null; echo $?) -ne 0 ]]; then
if [[ $(grep -vcE '^$^#' /etc/resolv.conf) -eq 0 ]]; then
echo -e "\nnameserver 1.1.1.2\nnameserver 9.9.9.9" >> /etc/resolv.conf
sleep 3
if [[ $(ping -c1 -q www.google.com &>/dev/null; echo $?) -ne 0 ]]; then
echo -e " ALERT!
Added Cloudflare and Quad9 nameservers, but still not resolving domain names!"
else
[[ $(id -u) -eq "0" ]] && apt update -y && apt upgrade -y && apt install -y curl sudo
fi
fi
fi
source ~/.bashrc