improved readabality

This commit is contained in:
pvincent
2024-03-05 23:29:55 +04:00
parent c9fd0aca3e
commit a06a05045e
7 changed files with 33 additions and 44 deletions
+7 -10
View File
@@ -1,22 +1,19 @@
#!/bin/bash
usage() {
echo "Usage: $(basename "$0") <REGEX> <STRING> <FILE>"
function usage {
builtin echo "Usage: $(basename "$0") <REGEX> <STRING> <FILE>"
}
if [[ $# -ne 3 ]]; then
usage
exit 2
fi
[[ $# -ne 3 ]] && usage && exit 2
REGEX=$1
STRING=$2
FILE=$3
if ! grep -Eq "$REGEX" "$FILE"; then
printf "$STRING\n" >>$FILE
echo appended
printf "%s\n" "$STRING" >>"$FILE"
echo 'appended'
else
sed -Ei "s|$REGEX|$STRING|g" $FILE
echo replaced
sed -Ei "s|$REGEX|$STRING|g" "$FILE"
echo 'replaced'
fi
+4 -4
View File
@@ -3,7 +3,7 @@
# Clears the entire current line regardless of terminal size.
# See the magic by running:
# { sleep 1; clear_this_line ; }&
clear_this_line(){
clear_this_line() {
printf '\r'
cols="$(tput cols)"
for i in $(seq "$cols"); do
@@ -16,7 +16,7 @@ clear_this_line(){
# Usage: erase_lines [AMOUNT]
# See the magic by running:
# { sleep 1; erase_lines 2; }&
erase_lines(){
erase_lines() {
# Default line count to 1.
test -z "$1" && lines="1" || lines="$1"
@@ -30,10 +30,10 @@ erase_lines(){
if [ "$lines" = 1 ]; then
clear_this_line
else
lines=$((lines-1))
lines=$((lines - 1))
clear_this_line
for i in $(seq "$lines"); do
printf "$UP"
buildtin echo "$UP"
clear_this_line
done
fi
+6 -4
View File
@@ -2,11 +2,13 @@
SIZE=${1:-12}
re='^[0-9]+$'
if ! [[ $SIZE =~ $re ]] ;then
echo "error: SIZE=$SIZE Not a number" >&2; exit 1
if ! [[ $SIZE =~ $re ]]; then
echo "error: SIZE=$SIZE Not a number" >&2
exit 1
fi
if [[ $SIZE -lt 4 || $SIZE -gt 20 ]]; then
echo "expected SIZE=$SIZE not in range [4..20]" >&2; exit 1
echo "expected SIZE=$SIZE not in range [4..20]" >&2
exit 1
fi
tr -cd '[:alnum:]' < /dev/urandom | fold -w $SIZE | head -n1
tr -cd '[:alnum:]' </dev/urandom | fold -w "$SIZE" | head -n1
+1 -1
View File
@@ -94,7 +94,7 @@ fi
COMMAND="${1:-ask}"
if [[ $COMMAND == 'ask' ]]; then
echo -n "Press 'M' for Major, 'm' for minor, 'p' for patch ? "
read -n1 input
read -rn1 input
echo
COMMAND="-$input"
fi