foo
This commit is contained in:
parent
92e06f1e4c
commit
5f59eec0fc
251
qgds
251
qgds
@ -1,251 +0,0 @@
|
||||
[1mdiff --git a/bsf b/bsf[m
|
||||
[1mindex 83cf953..6f55713 100644[m
|
||||
[1m--- a/bsf[m
|
||||
[1m+++ b/bsf[m
|
||||
[36m@@ -1,9 +1,9 @@[m
|
||||
#!/bin/bash[m
|
||||
[m
|
||||
[31m-# Bash Framework[m
|
||||
[32m+[m[32m# Bash Framework bsf[m
|
||||
# Some useful bash functions to make things easier.[m
|
||||
#[m
|
||||
[31m-# Copyright (C) 2017-2019 willipink.eu[m
|
||||
[32m+[m[32m# Copyright (C) 2017-2020 willipink.eu[m
|
||||
# Author Moritz Münch moritzmuench@mailbox.org[m
|
||||
#[m
|
||||
# This program is free software: you can redistribute it and/or modify[m
|
||||
[36m@@ -20,107 +20,103 @@[m
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.[m
|
||||
[m
|
||||
[m
|
||||
[31m-[m
|
||||
[31m-# Variables[m
|
||||
[31m-[m
|
||||
# supress colors if used to write to a log[m
|
||||
[31m-LOG=True[m
|
||||
[31m-for arg in $*; do[m
|
||||
[32m+[m[32mLOG=False[m
|
||||
[32m+[m[32mfor arg in "$@"; do[m
|
||||
if [[ "$arg" == "--log" ]]; then[m
|
||||
[31m- LOG=False[m
|
||||
[32m+[m[32m LOG=True[m
|
||||
fi[m
|
||||
done[m
|
||||
[m
|
||||
[31m-[m
|
||||
[31m-## colors (use ANSI escape codes)[m
|
||||
[31m-if [[ "$LOG" == True ]]; then[m
|
||||
[31m- normal () { printf '\033[0m' ; }[m
|
||||
[31m- red () { printf '\033[0;31m' ; }[m
|
||||
[31m- green () { printf '\033[0;32m' ; }[m
|
||||
[31m- black () { printf '\033[0;30m' ; }[m
|
||||
[31m- brown () { printf '\033[0;33m' ; }[m
|
||||
[31m- orange () { printf '\033[0;33m' ; }[m
|
||||
[31m- blue () { printf '\033[0;34m' ; }[m
|
||||
[31m- purple () { printf '\033[0;35m' ; }[m
|
||||
[31m- cyan () { printf '\033[0;36m' ; }[m
|
||||
[31m- gray () { printf '\033[0;37m' ; }[m
|
||||
[31m- grey () { printf '\033[1;30m' ; }[m
|
||||
[31m- lred () { printf '\033[1;31m' ; }[m
|
||||
[31m- lgreen () { printf '\033[1;32m' ; }[m
|
||||
[31m- yellow () { printf '\033[1;33m' ; }[m
|
||||
[31m- lblue () { printf '\033[1;34m' ; }[m
|
||||
[31m- lpurple (){ printf '\033[1;35m' ; }[m
|
||||
[31m- lcyan () { printf '\033[1;36m' ; }[m
|
||||
[31m- white () { printf '\033[1;37m' ; }[m
|
||||
[31m-else[m
|
||||
[31m- normal () { return; }[m
|
||||
[31m- red () { return; }[m
|
||||
[31m- green () { return; }[m
|
||||
[31m- black () { return; }[m
|
||||
[31m- brown () { return; }[m
|
||||
[31m- orange () { return; }[m
|
||||
[31m- blue () { return; }[m
|
||||
[31m- purple () { return; }[m
|
||||
[31m- cyan () { return; }[m
|
||||
[31m- gray () { return; }[m
|
||||
[31m- grey () { return; }[m
|
||||
[31m- lred () { return; }[m
|
||||
[31m- lgreen () { return; }[m
|
||||
[31m- yellow () { return; }[m
|
||||
[31m- lblue () { return; }[m
|
||||
[31m- lpurple (){ return; }[m
|
||||
[31m- lcyan () { return; }[m
|
||||
[31m- white () { return; }[m
|
||||
[32m+[m[32m# colors (ANSI escape codes)[m
|
||||
[32m+[m[32mif [[ "$LOG" == False ]]; then[m
|
||||
[32m+[m[32m nor='\033[0m'[m
|
||||
[32m+[m[32m red='\033[0;31m'[m
|
||||
[32m+[m[32m gre='\033[0;32m'[m
|
||||
[32m+[m[32m bla='\033[0;30m'[m
|
||||
[32m+[m[32m bro='\033[0;33m'[m
|
||||
[32m+[m[32m ora='\033[0;33m'[m
|
||||
[32m+[m[32m blu='\033[0;34m'[m
|
||||
[32m+[m[32m pur='\033[0;35m'[m
|
||||
[32m+[m[32m cya='\033[0;36m'[m
|
||||
[32m+[m[32m gra='\033[0;37m'[m
|
||||
[32m+[m[32m gre='\033[1;30m'[m
|
||||
[32m+[m[32m lre='\033[1;31m'[m
|
||||
[32m+[m[32m lgr='\033[1;32m'[m
|
||||
[32m+[m[32m yel='\033[1;33m'[m
|
||||
[32m+[m[32m lbl='\033[1;34m'[m
|
||||
[32m+[m[32m lpu='\033[1;35m'[m
|
||||
[32m+[m[32m lcy='\033[1;36m'[m
|
||||
[32m+[m[32m whi='\033[1;37m'[m
|
||||
fi[m
|
||||
[m
|
||||
[m
|
||||
[31m-[m
|
||||
[31m-# Functions[m
|
||||
[31m-say () {[m
|
||||
[31m- # Print something to stdout.[m
|
||||
[31m-[m
|
||||
[31m- # Use printf for safety purposes, see http://www.etalabs.net/sh_tricks.html[m
|
||||
[31m-[m
|
||||
[31m- # @param what to print[m
|
||||
[31m-[m
|
||||
[31m- printf %s\\n "$*"[m
|
||||
[32m+[m[32m# Styling[m
|
||||
[32m+[m[32m section_prefix=' ::: '[m
|
||||
[32m+[m[32msubsection_prefix=' :: '[m
|
||||
[32m+[m[32m paragraph_prefix=' : '[m
|
||||
[32m+[m[32m section_color=$lbl[m
|
||||
[32m+[m[32m subsection_color=$ora[m
|
||||
[32m+[m[32m paragraph_color=$nor[m
|
||||
[32m+[m
|
||||
[32m+[m
|
||||
[32m+[m[32m# Formatting functions[m[41m [m
|
||||
[32m+[m[32mprint () {[m
|
||||
[32m+[m[32m # Print something safely to stdout[m
|
||||
[32m+[m[32m # Usage: print [n] stuff to print[m
|
||||
[32m+[m[32m # n will print a newline[m
|
||||
[32m+[m[32m for arg in "$@"; do[m
|
||||
[32m+[m[32m if [[ "$arg" == 'n' ]]; then[m
|
||||
[32m+[m[32m printf \\n[m
|
||||
[32m+[m[32m else[m
|
||||
[32m+[m[32m echo -ne "$arg"[m
|
||||
[32m+[m[32m fi[m
|
||||
[32m+[m[32m shift[m
|
||||
[32m+[m[32m done[m
|
||||
return 0[m
|
||||
}[m
|
||||
[m
|
||||
[m
|
||||
[31m-sayn () {[m
|
||||
[31m- # Like say without linebreak.[m
|
||||
[31m-[m
|
||||
[31m- # @param what to print[m
|
||||
[31m-[m
|
||||
[31m- printf %s "$*"[m
|
||||
[31m- return 0[m
|
||||
[32m+[m[32msection() {[m
|
||||
[32m+[m[32m # print a styled section[m
|
||||
[32m+[m[32m # initialize $SECTION to 0 or increment by 1[m
|
||||
[32m+[m[32m if [[ -z ${SECTION+x} ]]; then # +x seems to be a trick to also catch empty strings like SECTION=''[m
|
||||
[32m+[m[32m SECTION=1[m
|
||||
[32m+[m[32m else[m
|
||||
[32m+[m[32m SECTION=$(($SECTION+1))[m
|
||||
[32m+[m[32m fi[m
|
||||
[32m+[m[32m print n n n "$section_color$section_prefix${SECTION}. $*$nor"[m
|
||||
}[m
|
||||
[m
|
||||
[31m-sayc() {[m
|
||||
[31m- # quick styler, usage "style *color*"[m
|
||||
[m
|
||||
[31m- if [[ "$1" == "" ]]; then[m
|
||||
[31m- blue[m
|
||||
[32m+[m[32msubsection() {[m
|
||||
[32m+[m[32m # print a styled subsection[m
|
||||
[32m+[m[32m # initialize $SUBSECTION to 0 or increment by 1[m
|
||||
[32m+[m[32m if [[ -z ${SUBSECTION+x} ]]; then # +x seems to be a trick to also catch empty strings like SECTION=''[m
|
||||
[32m+[m[32m SUBSECTION=1[m
|
||||
else[m
|
||||
[31m- $1[m
|
||||
[32m+[m[32m SUBSECTION=$(($SUBSECTION+1))[m
|
||||
fi[m
|
||||
[31m- sayn " ::: "[m
|
||||
[31m- shift[m
|
||||
[31m- say "$*"[m
|
||||
[31m- normal[m
|
||||
[31m- return 0[m
|
||||
[32m+[m[32m print n n "$subsection_color$subsection_prefix${SECTION}.${SUBSECTION} $*$nor"[m
|
||||
}[m
|
||||
[m
|
||||
[31m-saycn() {[m
|
||||
[31m- $1[m
|
||||
[31m- sayn " ::: "[m
|
||||
[31m- shift[m
|
||||
[31m- sayn "$*"[m
|
||||
[31m- normal[m
|
||||
[31m- return 0[m
|
||||
[31m-}[m
|
||||
[m
|
||||
[32m+[m[32mparagraph() {[m
|
||||
[32m+[m[32m # print a styled subsection[m
|
||||
[32m+[m[32m print n "$paragraph_color$paragraph_prefix$*$nor"[m
|
||||
[32m+[m[32m}[m
|
||||
[32m+[m[32m# examples[m
|
||||
[32m+[m[32m# paragraph lol[m
|
||||
[32m+[m[32m# paragraph next[m
|
||||
[32m+[m[32m# section big[m
|
||||
[32m+[m[32m# section relly big[m
|
||||
[32m+[m[32m# subsection a[m
|
||||
[32m+[m[32m# paragraph 1[m
|
||||
[32m+[m[32m# subsection b[m
|
||||
[32m+[m[32m# paragraph 2[m
|
||||
[32m+[m
|
||||
[32m+[m
|
||||
[32m+[m[32m# Helper functions[m
|
||||
root () {[m
|
||||
# Exit immediately if user is not root[m
|
||||
# Usage: root[m
|
||||
[36m@@ -132,35 +128,30 @@[m [mroot () {[m
|
||||
fi[m
|
||||
}[m
|
||||
[m
|
||||
[32m+[m
|
||||
ok() {[m
|
||||
# Check if last call had errors. If so, print error message and exit.[m
|
||||
[31m- # Usage: ok <command>[m
|
||||
[32m+[m[32m # Usage: ok[m
|
||||
[m
|
||||
if [[ "$?" -ne 0 ]]; then[m
|
||||
[31m- sayc red "ERROR, aborting."[m
|
||||
[32m+[m[32m print $red ' ... ERROR, aborting!' $nor n[m
|
||||
exit 1[m
|
||||
else[m
|
||||
[31m- sayc green "$0 ... done"[m
|
||||
[32m+[m[32m print " ...$lgr done$nor" n[m
|
||||
return 0[m
|
||||
fi[m
|
||||
}[m
|
||||
[m
|
||||
[31m-try() {[m
|
||||
[31m- # Do a job and check if it ran successfull.[m
|
||||
[31m- # Usage: try <command>[m
|
||||
[m
|
||||
[31m- $* && ok[m
|
||||
[31m-}[m
|
||||
[31m-[m
|
||||
[31m-trycm() {[m
|
||||
[31m- # Do a job, write a message, color it and check if it ran successfull.[m
|
||||
[31m- # Usage: trycmd <color> <message> <command>[m
|
||||
[32m+[m[32mtry() {[m
|
||||
[32m+[m[32m # Print a message, execute a command silent print errors to stdout[m
|
||||
[32m+[m[32m # and abort the command goes wrong[m
|
||||
[32m+[m[32m # Usage: try message command [command2 ...][m
|
||||
[m
|
||||
[31m- if [[ "$2" != "" ]]; then[m
|
||||
[31m- say[m
|
||||
[31m- sayc "$1" "$2"[m
|
||||
[31m- fi[m
|
||||
[31m- shift && shift[m
|
||||
[31m- saycn normal "$*"[m
|
||||
[31m- try $*[m
|
||||
[32m+[m[32m message="$1"[m
|
||||
[32m+[m[32m shift[m
|
||||
[32m+[m[32m paragraph "$pur${message}$nor: $*"[m
|
||||
[32m+[m[32m $* 1> /dev/null && ok[m
|
||||
}[m
|
||||
[32m+[m[32m# examples[m
|
||||
[32m+[m[32m# try testnachricht lsblk[m
|
Loading…
x
Reference in New Issue
Block a user