refactored boxborder stylization
This commit is contained in:
parent
37f2332c11
commit
fc1b52538e
1 changed files with 89 additions and 206 deletions
245
functions
245
functions
|
|
@ -98,193 +98,100 @@ else
|
||||||
BOXWIDTH=80
|
BOXWIDTH=80
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
set_borders() {
|
||||||
|
top_border=$1
|
||||||
|
bottom_border=$2
|
||||||
|
left_border=$3
|
||||||
|
right_border=$4
|
||||||
|
left_top_border=$5
|
||||||
|
right_top_border=$6
|
||||||
|
left_bottom_border=$7
|
||||||
|
right_bottom_border=$8
|
||||||
|
box_break_line=$9
|
||||||
|
}
|
||||||
|
|
||||||
# Box Drawing characters
|
# Box Drawing characters
|
||||||
case $OSTYPE in
|
case $OSTYPE in
|
||||||
linux-gnu*|cygwin|msys)
|
linux-gnu*|cygwin|msys)
|
||||||
light_h=$(echo -e "\u2500")
|
light_h='\u2500'
|
||||||
norm_h=$(echo -e "\u2501")
|
norm_h='\u2501'
|
||||||
double_h=$(echo -e "\u2550")
|
double_h='\u2550'
|
||||||
light_v=$(echo -e "\u2502")
|
light_v='\u2502'
|
||||||
norm_v=$(echo -e "\u2503")
|
norm_v='\u2503'
|
||||||
double_v=$(echo -e "\u2551")
|
double_v='\u2551'
|
||||||
;;&
|
;;&
|
||||||
darwin* )
|
darwin* )
|
||||||
light_h=$(echo -e "─")
|
light_h='─'
|
||||||
norm_h=$(echo -e "━")
|
norm_h='━'
|
||||||
double_h=$(echo -e "═")
|
double_h='═'
|
||||||
light_v=$(echo -e "│")
|
light_v='│'
|
||||||
norm_v=$(echo -e "┃")
|
norm_v='┃'
|
||||||
double_v=$(echo -e "║")
|
double_v='║'
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Box border type single-line
|
# Box border type single-line
|
||||||
box-norm() {
|
box-norm() {
|
||||||
# ---------------------------------------#
|
|
||||||
case $OSTYPE in
|
case $OSTYPE in
|
||||||
linux-gnu*|cygwin|msys)
|
linux-gnu*|cygwin|msys)
|
||||||
top_border=${norm_h}
|
set_borders "${norm_h}" "${norm_h}" "${norm_v}" "${norm_v}" "\u250f" "\u2513" "\u2517" "\u251b" "\u25AB"
|
||||||
bottom_border=${norm_h}
|
|
||||||
left_border=${norm_v}
|
|
||||||
right_border=${norm_v}
|
|
||||||
left_top_border=$(echo -e "\u250f")
|
|
||||||
right_top_border=$(echo -e "\u2513")
|
|
||||||
left_bottom_border=$(echo -e "\u2517")
|
|
||||||
right_bottom_border=$(echo -e "\u251b")
|
|
||||||
box_break_line=$(echo -e "\u25AB")
|
|
||||||
;;&
|
;;&
|
||||||
darwin* )
|
darwin* )
|
||||||
top_border=${norm_h}
|
set_borders "${norm_h}" "${norm_h}" "${norm_v}" "${norm_v}" "┏" "┓" "┗" "┛" "▫"
|
||||||
bottom_border=${norm_h}
|
|
||||||
left_border=${norm_v}
|
|
||||||
right_border=${norm_v}
|
|
||||||
left_top_border=$(echo -e "┏")
|
|
||||||
right_top_border=$(echo -e "┓")
|
|
||||||
left_bottom_border=$(echo -e "┗")
|
|
||||||
right_bottom_border=$(echo -e "┛")
|
|
||||||
box_break_line=$(echo -e "▫")
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# ---------------------------------------#
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Box border type double-line
|
# Box border type double-line
|
||||||
box-double() {
|
box-double() {
|
||||||
# ---------------------------------------#
|
|
||||||
case $OSTYPE in
|
case $OSTYPE in
|
||||||
linux-gnu*|cygwin|msys)
|
linux-gnu*|cygwin|msys)
|
||||||
top_border=${double_h}
|
set_borders "${double_h}" "${double_h}" "${double_v}" "${double_v}" "\u2554" "\u2557" "\u255A" "\u255D" "\u25AB"
|
||||||
bottom_border=${double_h}
|
|
||||||
left_border=${double_v}
|
|
||||||
right_border=${double_v}
|
|
||||||
left_top_border=$(echo -e "\u2554")
|
|
||||||
right_top_border=$(echo -e "\u2557")
|
|
||||||
left_bottom_border=$(echo -e "\u255A")
|
|
||||||
right_bottom_border=$(echo -e "\u255D")
|
|
||||||
box_break_line=$(echo -e "\u25AB")
|
|
||||||
;;&
|
;;&
|
||||||
darwin* )
|
darwin* )
|
||||||
top_border=${double_h}
|
set_borders "${double_h}" "${double_h}" "${double_v}" "${double_v}" "╔" "╗" "╚" "╝" "▫"
|
||||||
bottom_border=${double_h}
|
|
||||||
left_border=${double_v}
|
|
||||||
right_border=${double_v}
|
|
||||||
left_top_border=$(echo -e "╔")
|
|
||||||
right_top_border=$(echo -e "╗")
|
|
||||||
left_bottom_border=$(echo -e "╚")
|
|
||||||
right_bottom_border=$(echo -e "╝")
|
|
||||||
box_break_line=$(echo -e "▫")
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# ---------------------------------------#
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Box border type thick-line
|
# Box border type thick-line
|
||||||
box-heavy(){
|
box-heavy(){
|
||||||
# ---------------------------------------#
|
|
||||||
case $OSTYPE in
|
case $OSTYPE in
|
||||||
linux-gnu*|cygwin|msys)
|
linux-gnu*|cygwin|msys)
|
||||||
top_border=$(echo -e "\u2580")
|
set_borders "\u2580" "\u2584" "\u258C" "\u2590" "\u259B" "\u259C" "\u2599" "\u259F" "\u25AB"
|
||||||
bottom_border=$(echo -e "\u2584")
|
|
||||||
left_border=$(echo -e "\u258C")
|
|
||||||
right_border=$(echo -e "\u2590")
|
|
||||||
left_top_border=$(echo -e "\u259B")
|
|
||||||
right_top_border=$(echo -e "\u259C")
|
|
||||||
left_bottom_border=$(echo -e "\u2599")
|
|
||||||
right_bottom_border=$(echo -e "\u259F")
|
|
||||||
box_break_line=$(echo -e "\u25AC")
|
|
||||||
;;&
|
;;&
|
||||||
darwin* )
|
darwin* )
|
||||||
top_border=$(echo -e "▀")
|
set_borders "▀" "▄" "▌" "▐" "▛" "▜" "▙" "▟" "▫"
|
||||||
bottom_border=$(echo -e "▄")
|
|
||||||
left_border=$(echo -e "▌")
|
|
||||||
right_border=$(echo -e "▐")
|
|
||||||
left_top_border=$(echo -e "▛")
|
|
||||||
right_top_border=$(echo -e "▜")
|
|
||||||
left_bottom_border=$(echo -e "▙")
|
|
||||||
right_bottom_border=$(echo -e "▟")
|
|
||||||
box_break_line=$(echo -e "▫")
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# ---------------------------------------#
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Box border type thin-line
|
# Box border type thin-line
|
||||||
box-light(){
|
box-light(){
|
||||||
# ---------------------------------------#
|
|
||||||
#top_border=$(echo -e '\u23BA')
|
|
||||||
case $OSTYPE in
|
case $OSTYPE in
|
||||||
linux-gnu*|cygwin|msys)
|
linux-gnu*|cygwin|msys)
|
||||||
top_border=${light_h}
|
set_borders "${light_h}" "${light_h}" "${light_v}" "${light_v}" "\u25AB" "\u25AB" "\u25AB" "\u25AB" "\u23AF"
|
||||||
bottom_border=${light_h}
|
|
||||||
left_border=${light_v}
|
|
||||||
right_border=${light_v}
|
|
||||||
left_top_border=$(echo -e "\u25AB")
|
|
||||||
right_top_border=$(echo -e "\u25AB")
|
|
||||||
left_bottom_border=$(echo -e "\u25AB")
|
|
||||||
right_bottom_border=$(echo -e "\u25AB")
|
|
||||||
box_break_line=$(echo -e "\u23AF")
|
|
||||||
;;&
|
;;&
|
||||||
darwin* )
|
darwin* )
|
||||||
top_border=${light_h}
|
set_borders "${light_h}" "${light_h}" "${light_v}" "${light_v}" "▫" "▫" "▫" "▫" "⎯"
|
||||||
bottom_border=${light_h}
|
|
||||||
left_border=${light_v}
|
|
||||||
right_border=${light_v}
|
|
||||||
left_top_border=$(echo -e "▫")
|
|
||||||
right_top_border=$(echo -e "▫")
|
|
||||||
left_bottom_border=$(echo -e "▫")
|
|
||||||
right_bottom_border=$(echo -e "▫")
|
|
||||||
box_break_line=$(echo -e "⎯")
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# ---------------------------------------#
|
|
||||||
}
|
}
|
||||||
|
|
||||||
box-rounded(){
|
box-rounded(){
|
||||||
# ---------------------------------------#
|
|
||||||
case $OSTYPE in
|
case $OSTYPE in
|
||||||
linux-gnu*|cygwin|msys)
|
linux-gnu*|cygwin|msys)
|
||||||
top_border=${light_h}
|
set_borders "${light_h}" "${light_h}" "${light_v}" "${light_v}" "\u256D" "\u256E" "\u2570" "\u256F" "\u25A2"
|
||||||
bottom_border=${light_h}
|
|
||||||
left_border=${light_v}
|
|
||||||
right_border=${light_v}
|
|
||||||
left_top_border=$(echo -e "\u256D")
|
|
||||||
right_top_border=$(echo -e "\u256E")
|
|
||||||
left_bottom_border=$(echo -e "\u2570")
|
|
||||||
right_bottom_border=$(echo -e "\u256F")
|
|
||||||
box_break_line=$(echo -e "\u25A2")
|
|
||||||
;;&
|
;;&
|
||||||
darwin* )
|
darwin* )
|
||||||
top_border=${light_h}
|
set_borders "${light_h}" "${light_h}" "${light_v}" "${light_v}" "╭" "╮" "╰" "╯" "▢"
|
||||||
bottom_border=${light_h}
|
|
||||||
left_border=${light_v}
|
|
||||||
right_border=${light_v}
|
|
||||||
left_top_border=$(echo -e "╭")
|
|
||||||
right_top_border=$(echo -e "╮")
|
|
||||||
left_bottom_border=$(echo -e "╰")
|
|
||||||
right_bottom_border=$(echo -e "╯")
|
|
||||||
box_break_line=$(echo -e "▢")
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# ---------------------------------------#
|
|
||||||
}
|
}
|
||||||
|
|
||||||
box-singlechar(){
|
box-singlechar(){
|
||||||
# ---------------------------------------#
|
set_borders "$borderchar" "$borderchar" "$borderchar" "$borderchar" "$borderchar" "$borderchar" "$borderchar" "$borderchar" "-"
|
||||||
top_border=$borderchar
|
|
||||||
bottom_border=$borderchar
|
|
||||||
left_border=$borderchar
|
|
||||||
right_border=$borderchar
|
|
||||||
left_top_border=$borderchar
|
|
||||||
right_top_border=$borderchar
|
|
||||||
left_bottom_border=$borderchar
|
|
||||||
right_bottom_border=$borderchar
|
|
||||||
box_break_line="-"
|
|
||||||
# ---------------------------------------#
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set-boxtype(){
|
set-boxtype(){
|
||||||
case $boxtype in
|
case $boxtype in
|
||||||
norm) box-norm ;;
|
norm) box-norm ;;
|
||||||
|
|
@ -1083,38 +990,31 @@ compare-versions(){
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
identify-system(){
|
identify_system() {
|
||||||
# OS distribution auto-detection
|
|
||||||
if type lsb_release >/dev/null 2>&1; then
|
if type lsb_release >/dev/null 2>&1; then
|
||||||
# linuxbase.org
|
|
||||||
ID=$(lsb_release -si)
|
ID=$(lsb_release -si)
|
||||||
OS=$(lsb_release -si)
|
OS=$(lsb_release -si)
|
||||||
VER=$(lsb_release -sr)
|
VER=$(lsb_release -sr)
|
||||||
elif [ -f /etc/debian_version ]; then
|
elif [ -f /etc/os-release ]; then
|
||||||
# Older Debian/Ubuntu/etc.
|
. /etc/os-release
|
||||||
ID=debian
|
ID=${ID:-$VERSION_ID}
|
||||||
OS=Debian
|
ID=${ID:-$VERSION}
|
||||||
VER=$(cat /etc/debian_version)
|
OS=$NAME
|
||||||
|
VER=$VERSION_ID
|
||||||
|
VER=${VER:-$VERSION}
|
||||||
elif [ -f /etc/lsb-release ]; then
|
elif [ -f /etc/lsb-release ]; then
|
||||||
# For Arch and some versions of Debian/Ubuntu without lsb_release command
|
|
||||||
. /etc/lsb-release
|
. /etc/lsb-release
|
||||||
ID=$DISTRIB_ID
|
ID=$DISTRIB_ID
|
||||||
OS=$DISTRIB_ID
|
OS=$DISTRIB_ID
|
||||||
VER=$DISTRIB_RELEASE
|
VER=$DISTRIB_RELEASE
|
||||||
VER=${VER:-$LSB_VERSION}
|
VER=${VER:-$LSB_VERSION}
|
||||||
elif [ -f /etc/os-release ]; then
|
elif [ -f /etc/debian_version ]; then
|
||||||
# freedesktop.org arch and systemd
|
ID=debian
|
||||||
. /etc/os-release
|
OS=Debian
|
||||||
ID=${ID:-VERSION_ID}
|
VER=$(cat /etc/debian_version)
|
||||||
ID=${ID:-VERSION}
|
|
||||||
OS=$NAME
|
|
||||||
VER=$VERSION_ID
|
|
||||||
VER=${VER:-$VERSION}
|
|
||||||
elif [ -f /etc/redhat-release ]; then
|
elif [ -f /etc/redhat-release ]; then
|
||||||
# Older Red Hat, CentOS, etc.
|
OS=$(awk '{print $1}' /etc/redhat-release)
|
||||||
OS=$(cat /etc/redhat-release | awk '{print $1}')
|
|
||||||
else
|
else
|
||||||
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
|
|
||||||
OS=$(uname -s)
|
OS=$(uname -s)
|
||||||
VER=$(uname -r)
|
VER=$(uname -r)
|
||||||
fi
|
fi
|
||||||
|
|
@ -1128,7 +1028,6 @@ ID(){
|
||||||
}
|
}
|
||||||
|
|
||||||
install_packages() {
|
install_packages() {
|
||||||
# Separate package names and file arguments
|
|
||||||
declare -a packages=()
|
declare -a packages=()
|
||||||
declare -a offline_packages=()
|
declare -a offline_packages=()
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
|
|
@ -1138,66 +1037,50 @@ install_packages(){
|
||||||
packages+=("$arg")
|
packages+=("$arg")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# Identify which distro is being run
|
identify_system
|
||||||
identify-system
|
|
||||||
|
|
||||||
# Match distribution with available utilities
|
|
||||||
# TODO: Add package name transformer lists
|
|
||||||
case $ID in
|
case $ID in
|
||||||
amzn | centos | fedora | rhel)
|
amzn | centos | fedora | rhel)
|
||||||
if [ "${#packages[@]}" -gt 0 ]; then
|
[ "${#packages[@]}" -gt 0 ] && run sudo yum install -y "${packages[@]}"
|
||||||
sudo yum install -y "${packages[@]}"
|
[ "${#offline_packages[@]}" -gt 0 ] && run sudo rpm -i "${packages[@]}"
|
||||||
fi
|
|
||||||
if [ "${#offline_packages[@]}" -gt 0 ]; then
|
|
||||||
sudo rpm -i "${packages[@]}"
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
arch | Arch | manjaro)
|
arch | Arch | manjaro)
|
||||||
if [ "${#packages[@]}" -gt 0 ]; then
|
if [ "${#packages[@]}" -gt 0 ]; then
|
||||||
sudo pacman -Syu
|
run sudo pacman -Syu
|
||||||
sudo pacman -S "${packages[@]}"
|
run sudo pacman -S "${packages[@]}"
|
||||||
fi
|
|
||||||
if [ "${#offline_packages[@]}" -gt 0 ]; then
|
|
||||||
sudo pacman -U "${offline_packages[@]}"
|
|
||||||
fi
|
fi
|
||||||
|
[ "${#offline_packages[@]}" -gt 0 ] && run sudo pacman -U "${offline_packages[@]}"
|
||||||
;;
|
;;
|
||||||
debian | ubuntu | Ubuntu)
|
debian | ubuntu | Ubuntu)
|
||||||
if [ "${#packages[@]}" -gt 0 ]; then
|
if [ "${#packages[@]}" -gt 0 ]; then
|
||||||
sudo apt-get update
|
run sudo apt-get update
|
||||||
sudo apt-get install "${packages[@]}"
|
run sudo apt-get install "${packages[@]}"
|
||||||
fi
|
|
||||||
if [ "${#offline_packages[@]}" -gt 0 ]; then
|
|
||||||
sudo dpkg -i "${offline_packages[@]}"
|
|
||||||
fi
|
fi
|
||||||
|
[ "${#offline_packages[@]}" -gt 0 ] && run sudo dpkg -i "${offline_packages[@]}"
|
||||||
;;
|
;;
|
||||||
opensuse | sles)
|
opensuse | sles)
|
||||||
if [ "${#packages[@]}" -gt 0 ]; then
|
if [ "${#packages[@]}" -gt 0 ]; then
|
||||||
sudo zypper refresh
|
run sudo zypper refresh
|
||||||
sudo zypper install "${packages[@]}"
|
run sudo zypper install "${packages[@]}"
|
||||||
fi
|
|
||||||
if [ "${#offline_packages[@]}" -gt 0 ]; then
|
|
||||||
sudo rpm -i "${offline_packages[@]}"
|
|
||||||
fi
|
fi
|
||||||
|
[ "${#offline_packages[@]}" -gt 0 ] && run sudo rpm -i "${offline_packages[@]}"
|
||||||
;;
|
;;
|
||||||
slackware)
|
slackware)
|
||||||
if [ "${#packages[@]}" -gt 0 ]; then
|
if [ "${#packages[@]}" -gt 0 ]; then
|
||||||
for package in "${packages[@]}"; do
|
for package in "${packages[@]}"; do
|
||||||
sudo installpkg "$package"
|
run sudo installpkg "$package"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
if [ "${#offline_packages[@]}" -gt 0 ]; then
|
if [ "${#offline_packages[@]}" -gt 0 ]; then
|
||||||
for package_file in "${offline_packages[@]}"; do
|
for package_file in "${offline_packages[@]}"; do
|
||||||
sudo installpkg "$package_file"
|
run sudo installpkg "$package_file"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
brew)
|
brew)
|
||||||
if [ "${#packages[@]}" -gt 0 ]; then
|
[ "${#packages[@]}" -gt 0 ] && run brew install "${packages[@]}"
|
||||||
brew install "${packages[@]}"
|
|
||||||
fi
|
|
||||||
if [ "${#offline_packages[@]}" -gt 0 ]; then
|
if [ "${#offline_packages[@]}" -gt 0 ]; then
|
||||||
for package_file in "${offline_packages[@]}"; do
|
for package_file in "${offline_packages[@]}"; do
|
||||||
brew install "$package_file"
|
run brew install "$package_file"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue