mirror of
https://github.com/Lissy93/dotfiles.git
synced 2024-11-22 07:23:10 +01:00
✍ Updates hr to allow usage as an alias
This commit is contained in:
parent
91b4bfa558
commit
cd2a571eda
37
utils/hr.sh
37
utils/hr.sh
@ -3,33 +3,44 @@
|
||||
# Simple script to output a solid line in the terminal
|
||||
# Useful for marking the end of a task in your bash log
|
||||
# Inspired by @LuRsT's script of the same name
|
||||
# Licensed under MIT (C) Alicia Sykes, 2021
|
||||
# Can be called directly, or source'd in *rc file
|
||||
# Licensed under MIT, (C) Alicia Sykes 2022
|
||||
|
||||
# Determine width of terminal
|
||||
COLS="$(tput cols)"
|
||||
if (( COLS <= 0 )) ; then
|
||||
COLS="${COLUMNS:-80}"
|
||||
hr_col_count="$(tput cols)"
|
||||
if [ ! -n "${hr_col_count+set}" ] || [ $hr_col_count -lt 1 ]; then
|
||||
hr_col_count="${COLUMNS:-80}"
|
||||
fi
|
||||
|
||||
# Colors
|
||||
CYAN_BG="\u001b[46;1m"
|
||||
RESET="\u001b[0m"
|
||||
hr_color="${hr_color:=\u001b[46;1m}"
|
||||
hr_reset="\u001b[0m"
|
||||
|
||||
# Prints the HR line
|
||||
hr() {
|
||||
hr_draw_char() {
|
||||
local CHAR="$1"
|
||||
local LINE=''
|
||||
LINE=$(printf "%*s" "$COLS")
|
||||
LINE=$(printf "%*s" "$hr_col_count")
|
||||
LINE="${LINE// /${CHAR}}"
|
||||
printf "${CYAN_BG}${LINE:0:${COLS}}${RESET}"
|
||||
printf "${hr_color}${LINE:0:${hr_col_count}}${hr_reset}"
|
||||
}
|
||||
|
||||
# Passes param and calls hr()
|
||||
start() {
|
||||
hr() {
|
||||
for WORD in "${@:--}"; do
|
||||
hr "$WORD"
|
||||
hr_draw_char "$WORD"
|
||||
done
|
||||
}
|
||||
|
||||
# Catch errors, and call start
|
||||
[ "$0" == "$BASH_SOURCE" ] && start "$@"
|
||||
# Determine if file is being run directly or sourced
|
||||
([[ -n $ZSH_EVAL_CONTEXT && $ZSH_EVAL_CONTEXT =~ :file$ ]] ||
|
||||
[[ -n $KSH_VERSION && $(cd "$(dirname -- "$0")" &&
|
||||
printf '%s' "${PWD%/}/")$(basename -- "$0") != "${.sh.file}" ]] ||
|
||||
[[ -n $BASH_VERSION ]] && (return 0 2>/dev/null)) && sourced=1 || sourced=0
|
||||
|
||||
# Either instantiate immediatley, or set alias for later
|
||||
if [ $sourced -eq 0 ]; then
|
||||
[ "$0" == "$BASH_SOURCE" ] && hr "$@"
|
||||
else
|
||||
export alias hr='hr'
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user