#! /bin/bash # +-------------------------------------------------------+ # | shell utilities Autor: Alexander Elgert | # | Copyright: GNU General Public License | # +-------------------------------------------------------+ # # you can call this function package with the environment variable # f2p_show_dot=true ./line--- # to see the dependancy graph of this package # function line---() { # draw a line # Usage: $FUNCNAME # [ "${1:0:1}" = "-" ] && return # line with a negative length cannot be drawn local fill="----------------------------------------------------------------------------------------------------" # setting a variable with a length of 100 Bytes local fx="$((${1:-${COLUMNS:-80}}/${#fill}))" # calculate the number of passes we need - number of digits is number of passes [ "$2" != "" ] && fill="${fill//-/${2:0:1}}" # replace the "-" with the new value while [ "$fx" -gt "0" ]; do fill="$fill$fill" fx=$((fx>>1)) # shift done out="${fill:0:${1:-${COLUMNS:-80}}}" # take "$1" as length, fallback "$COLUMNS", fallback "80" echo "${out:1}" # cut one byte to compensate the newline } # now call the package function or the dotfile if [ "$f2p_show_dot" = "true" ]; then { echo ' digraph "line---" { "line---" [ URL = "functions/line---", tooltip = "click ME", label = "line---()", color = "orange" ]; } '; } | dot -Tps | display else line--- "$@" fi