Initial commit
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
|
|
||||||
5
README
Normal file
5
README
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
A collection of useful bash "libraries"
|
||||||
|
|
||||||
|
- bashcols:
|
||||||
|
Allows easy colored output.
|
||||||
|
|
||||||
73
bashcols
Executable file
73
bashcols
Executable file
@@ -0,0 +1,73 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
eval "reset_esc=\"\\e[0m\""
|
||||||
|
|
||||||
|
# applies the given color id, executes the command, then resets the color
|
||||||
|
function colout() {
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
echo "usage: colout <color id> <command>"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local color=$1
|
||||||
|
shift
|
||||||
|
tput setaf $color
|
||||||
|
"$@"
|
||||||
|
tput sgr0
|
||||||
|
}
|
||||||
|
|
||||||
|
# defines a new color function
|
||||||
|
# and a variable named <colorname>_colid that contains the actual value for the color function
|
||||||
|
function defcol() {
|
||||||
|
if [[ $# -ne 2 ]]; then
|
||||||
|
echo "usage: defcol <color name> <color id>"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local name="$1"
|
||||||
|
local color="$2"
|
||||||
|
|
||||||
|
eval "${name}_colid=$color"
|
||||||
|
eval "${name}_esc=\"\\e[38;5;${color}m\""
|
||||||
|
eval "${name}_escbg=\"\\e[48;5;${color}m\""
|
||||||
|
eval "function $name { colout $color \"\$@\"; }"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# displays all 256 colors
|
||||||
|
function dispcollist() {
|
||||||
|
local width=${1:-16}
|
||||||
|
local idx=0
|
||||||
|
for colid in `seq 1 256`; do
|
||||||
|
colout $colid printf "%3s " $colid
|
||||||
|
idx=$(($idx+1))
|
||||||
|
if [[ $(($idx % $width)) -eq 0 ]]; then
|
||||||
|
printf "\n"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function colthis {
|
||||||
|
local name="$1"
|
||||||
|
shift
|
||||||
|
eval "printf \"\${${name}_esc}$@$reset_esc\""
|
||||||
|
}
|
||||||
|
|
||||||
|
# default colors
|
||||||
|
defcol red 1
|
||||||
|
defcol green 2
|
||||||
|
defcol brown 3
|
||||||
|
defcol blue 4
|
||||||
|
defcol magenta 5
|
||||||
|
defcol cyan 6
|
||||||
|
defcol white 7
|
||||||
|
defcol grey 8
|
||||||
|
defcol redl 9
|
||||||
|
defcol greenl 10
|
||||||
|
defcol yellow 11
|
||||||
|
defcol bluel 12
|
||||||
|
defcol magenta 13
|
||||||
|
defcol cyanl 14
|
||||||
|
defcol whitel 15
|
||||||
|
defcol black 16
|
||||||
|
|
||||||
Reference in New Issue
Block a user