Compare commits

...

6 Commits

Author SHA1 Message Date
cfcb399d20 Add bashparam 2021-07-27 18:56:03 +02:00
Micyp
4183072ea8 add bashutils 2021-07-27 15:32:31 +02:00
e1b576a4b7 fix typos in default color names 2021-02-10 20:39:52 +01:00
f49c74f12b syntax improvements 2021-01-14 10:37:13 +01:00
Micyp
4cf9387cb8 replace shebang with vim modeline, improve syntax 2021-01-13 19:17:58 +01:00
6dbb80d10f bashcols: replace tabs with spaces in default color list 2020-12-09 20:28:25 +01:00
3 changed files with 60 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/bash # vim: syntax=bash:
eval "reset_esc=\"\\e[0m\"" reset_esc='\e[0m'
# applies the given color id, executes the command, then resets the color # applies the given color id, executes the command, then resets the color
function colout() { function colout() {
@@ -9,9 +9,9 @@ function colout() {
return return
fi fi
local color=$1 local color="$1"
shift shift
tput setaf $color tput setaf "$color"
"$@" "$@"
tput sgr0 tput sgr0
} }
@@ -37,7 +37,7 @@ function defcol() {
function dispcollist() { function dispcollist() {
local width=${1:-16} local width=${1:-16}
local idx=0 local idx=0
for colid in `seq 1 256`; do for colid in {1..256}; do
colout $colid printf "%3s " $colid colout $colid printf "%3s " $colid
idx=$(($idx+1)) idx=$(($idx+1))
if [[ $(($idx % $width)) -eq 0 ]]; then if [[ $(($idx % $width)) -eq 0 ]]; then
@@ -49,24 +49,24 @@ function dispcollist() {
function colthis { function colthis {
local name="$1" local name="$1"
shift shift
eval "printf \"\${${name}_esc}$@$reset_esc\"" eval "printf \"%s\" \"\${${name}_esc}$@$reset_esc\""
} }
# default colors # default colors
defcol red 1 defcol red 1
defcol green 2 defcol green 2
defcol brown 3 defcol brown 3
defcol blue 4 defcol blue 4
defcol magenta 5 defcol magenta 5
defcol cyan 6 defcol cyan 6
defcol white 7 defcol white 7
defcol grey 8 defcol grey 8
defcol redl 9 defcol redl 9
defcol greenl 10 defcol greenl 10
defcol yellow 11 defcol yellow 11
defcol bluel 12 defcol bluel 12
defcol magenta 13 defcol magenta 13
defcol cyanl 14 defcol cyanl 14
defcol whitel 15 defcol whitel 15
defcol black 16 defcol black 16

22
bashparam Normal file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/bash
declare -A __params
function has_param {
[[ -z ${__params[$1]} ]]
}
function get_param {
echo "${__params[$1]}"
}
# set_param <longname> <value>
function set_param {
if [[ -z $2 ]]; then
>&2 echo "${FUNCNAME}: non-zero value expected"
return 1
fi
$__params[${1:2}]=${2}
}

16
bashutils Normal file
View File

@@ -0,0 +1,16 @@
#!/hint/bash
function shasum {
command shasum <<<"$1" | awk '{ print $1 }'
}
# once <command>
function once {
local flagname="__onceflag_$(shasum "$*")"
if [[ -z ${!flagname} ]]; then
declare -g "${flagname}"=1
"$@"
fi
}