Skip to content

Commit 22552b6

Browse files
version 2.1
1 parent f14429a commit 22552b6

26 files changed

+1180
-955
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976)
2+
13
Overview
24
--------------------------------------------
35
* Name: bashMultiTool
@@ -43,13 +45,13 @@ Package available in the Arch Linux user repo AUR
4345
**For other linux systems**
4446

4547
Download latest fixed release and run the makefile as per
46-
terminal commands below for version 2.0 latest release at time of writing
48+
terminal commands below for version 2.1 latest release at time of writing
4749
Note: If you install with this method you will not be informed of updates
4850
by system.
4951

5052
```sh
51-
curl -sL https://github.com/gavinlyonsrepo/bashmultitool/archive/2.0.tar.gz | tar xz
52-
cd bashmultitool-2.0
53+
curl -sL https://github.com/gavinlyonsrepo/bashmultitool/archive/2.1.tar.gz | tar xz
54+
cd bashmultitool-2.1
5355
sudo make install
5456
```
5557

@@ -96,22 +98,22 @@ A script to print library meta data is also installed.
9698
| bmtPrompt | bmtPromptFunc | 201-210 | Prompts | [ bmtPrompt help file](documentation/bmtPrompt.md)|
9799
| bmtNetwork | bmtNetworkFunc | 301-302 | Network related | [bmtNetwork help file](documentation/bmtNetwork.md)|
98100
| bmtLinux | bmtLinuxFunc | 401-408 | Linux related | [bmtLinux help file](documentation/bmtLinux.md)|
99-
| bmtFiles | bmtFilesFunc | 501-509 | File related | [bmtFiles help file](documentation/bmtFiles.md)|
101+
| bmtFiles | bmtFilesFunc | 501-510 | File related | [bmtFiles help file](documentation/bmtFiles.md)|
100102
| bmtData | btmDataFunc | 601-607 | Data related | [bmtData help file](documentation/bmtData.md)|
101-
| bmtTime | btmTimeFunc | 701-709 | Time related | [bmtTime help file](documentation/bmtTime.md)|
102-
| bmtMisc | bmtMiscFunc | 801-804 | Miscellaneous | [bmtMisc help file](documentation/bmtMisc.md)|
103-
| bmtTest | bmtTestFunc | 901 | library testing | [bmtTest help file](documentation/bmtTest.md)|
103+
| bmtTime | btmTimeFunc | 701-710 | Time related | [bmtTime help file](documentation/bmtTime.md)|
104+
| bmtMisc | bmtMiscFunc | 801-806 | Miscellaneous | [bmtMisc help file](documentation/bmtMisc.md)|
105+
| bmtTest | bmtTestFunc | 901 | internal library test | [bmtTest help file](documentation/bmtTest.md)|
104106

105107
The library contains eight section's, Each section has one file with one function.
106-
Which contains 50 sub-sections in total.
108+
Which contains 54 sub-sections in total.
107109
The sections are grouped per logical function.
108110
Printing, prompting, Linux related, file related,
109111
data related, time related , network related and miscellaneous.
110112
The sections are mostly independent of each other
111113
you can source them individually if you wish, however the prompt file *is*
112114
dependent on print. There is also a ninth test section bmtTest used to test library.
113115

114-
The repo also contains a *test folder* where test files used in development are available, one for each library file. There is also a testTest.sh which runs an semi-automated test on entire library and produces a report.
116+
The repo also contains a *test folder* where a test file used in development are available, one function for each library file. The test file "testTest.sh", runs an semi-automated test on entire library and produces a report. Pass the test file a number between 1-9 , 1-8 correspond to the sections, 9 will test entire library.
115117

116118
Example
117119
----------------------------

documentation/bmtFiles.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
| Library file | Function | Sections | Content | help file|
22
| ---- | ---- | ---- | ---- | ---- |
3-
| bmtFiles | bmtFilesFunc | 501-509 | File related | bmtFiles.md |
3+
| bmtFiles | bmtFilesFunc | 501-510 | File related | bmtFiles.md |
44

55
**Section Five, File**
66

@@ -13,6 +13,7 @@
1313
* 507 File size
1414
* 508 File size in bytes
1515
* 509 mime type exists?
16+
* 510 File name extraction
1617

1718
**Sub-Sections**
1819

@@ -92,3 +93,13 @@ Returns 4 If file/directory does not exist. , 3 If file or mimetype command not
9293
bmtFilesFunc getmimetype "$TESTOBJECTS/full.txt" >> /tmp/mytempfile123.txt
9394
echo $?
9495
```
96+
510) File name extraction
97+
Returns 0 for success, 2 for missing arguments , 3 for wrong 2nd argument value, 4 for missing file extension
98+
99+
1. Param1 Filepath
100+
2. Param2 1-4 1 for filename, 2 for basename, 3 for extension ,4 for folder path
101+
102+
```sh
103+
bmtFilesFunc filename "/foo/foo123/tv.png" 4
104+
echo " :: Folder name $?"
105+
```

documentation/bmtMisc.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
| Library file | Function | Sections | Content | help file |
22
| ---- | ---- | ---- | ---- | ---- |
3-
| bmtMisc | bmtMiscFunc | 801-804 | Miscellaneous | bmtMisc.md |
3+
| bmtMisc | bmtMiscFunc | 801-806 | Miscellaneous | bmtMisc.md |
44

55

66
**Section Eight , misc**
@@ -9,6 +9,8 @@
99
* 802 Get laptop battery level
1010
* 803 Create a multi-line box with text inside it
1111
* 804 Create a single line box with variable box character.
12+
* 805 Centered text with variable banner character
13+
* 806 Display gauge
1214

1315
**Sub-Sections**
1416

@@ -49,3 +51,24 @@ bmtMiscFunc drawbox 1 2 'first line' 'second line' 'third line'
4951
```sh
5052
bmtMiscFunc title 2 6 '#' 'hello'
5153
```
54+
55+
805) Centered text with option banner filler
56+
1. Param1 Text to center
57+
2. Param2 Banner symbol
58+
59+
```sh
60+
bmtMiscFunc centertext "Hello World" =
61+
```
62+
63+
806) Display Gauge, display a gauge bar showing variable value
64+
65+
1. Param1 Text label
66+
2. Param2 Value to display
67+
3. Param3 Minimum value of gauge
68+
4. Param4 Maximum value of gauge
69+
5. Param5 Gauge full symbol
70+
6. Param6 Gauge empty symbol
71+
72+
```sh
73+
bmtMiscFunc gauge "Volts" 25 1 50 "#" "."
74+
```

documentation/bmtNetwork.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@
1313

1414
Keyword checknet, first option url of website. Returns 0 for connectivity , 2 for no connectivity
1515

16+
1. Param1 The URL
17+
2. Param2 NOMES(optional) can be used to surpress verbose output.
18+
1619
```sh
1720
bmtNetworkFunc checknet "www.google.ie"
1821
```
1922

23+
```sh
24+
bmtNetworkFunc checknet "www.google.ie" "NOMES"
25+
```
26+
2027
302) weather
2128

2229
Weather report by wttr.in, uses wget utility

documentation/bmtPrint.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Colours: Black, Red, Green, Yellow, Blue, Purple, Cyan, White.
1111
Modes: normal, bold, underline, background, high intensity,
1212
bold high intensity, background high intensity.
1313

14+
1. Param1 mode
15+
2. Param2 text to print(optional can be left out just to change cursor colour
16+
for next objects or text printed )
1417

1518
**Sub-Sections**
1619

documentation/bmtTest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
| ---- | ---- | ---- | ---- | ---- |
33
| bmtTest | bmtTestFunc | 901 | Test | bmtTest.md |
44

5-
**Section nine, Time**
5+
**Section nine, Test**
66

77
Used to conduct semi-automated testing and test report of library function.
88

documentation/bmtTime.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
| Library file | Function | Sections | Content | help file |
22
| ---- | ---- | ---- | ---- | ---- |
3-
| bmtTime | bmtTimeFunc | 701-709 | Timing related | bmtTime.md |
3+
| bmtTime | bmtTimeFunc | 701-710 | Timing related | bmtTime.md |
44

55
**Section Seven, Time**
66

77
* 701 Convert time to epoch time
88
* 702 Print current time Stamp
9-
* 703 Spinner Animation for long non-verbose commands
9+
* 703 Spinner Animation multiple character for long non-verbose commands
1010
* 704 - 707 Stopwatch / timer
1111
* 708 Progress Bar
1212
* 709 Convert Epoch time to date format
13+
* 710 Spinner Animation single character for long non-verbose commands
1314

1415
**Sub-Sections**
1516

@@ -25,7 +26,7 @@ bmtTimeFunc epochconvert "2022-04-27 19:42:01 "
2526
bmtTimeFunc epochnow
2627
```
2728

28-
703) Animation for non-verbose process/commands that take long time
29+
703) Spinner Animation for non-verbose process/commands that take long time
2930

3031
```sh
3132
# call spinner section put run in background and save PID
@@ -71,7 +72,7 @@ percentage completed.
7172
pid=$!
7273
disown
7374
echo "START"
74-
sleep 25 #do stuff
75+
sleep 25 # do stuff 25 seconds for one progress bar complete pass
7576
echo " "
7677
echo "END"
7778
# Stop spin function with PID
@@ -86,3 +87,19 @@ percentage completed.
8687
bmtTimeFunc dateformat "1651084921" "%FT%T%z"
8788
# prints ~ 2022-04-27T19:42:01+0100
8889
```
90+
91+
710) Spinner Animation, number two for long non-verbose commands
92+
93+
```sh
94+
# call spinner section put run in background and save PID
95+
bmtTimeFunc spintwo &
96+
pid=$!
97+
disown
98+
99+
# 'do stuff'
100+
find ~ -name mint 2>/dev/null
101+
102+
# Stop spintwo function with PID
103+
kill $pid
104+
sleep 2
105+
```

documentation/misc/changelog.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ Version control
77

88
### version 1.1-2 200218
99
* increased color printing options
10-
* increased options from 10 to 16
10+
* increased sub-sections from 10 to 16
1111
* made library modular. multiple files
1212

1313
### version 1.2-3 280318
1414
* Added two new modes to printing options bringing total
1515
number of option to 56 (8 colours * 7 modes)
16-
* Increased number of functions from 16 to 26 including stopwatch.
16+
* Increased number of sub-sections from 16 to 26 including stopwatch.
1717

1818
### version 1.4-5 040718
1919
* updating PPA to Ubuntu 18.04 LTS (Bionic Beaver)
@@ -26,5 +26,8 @@ Version control
2626
* updating PPA to Ubuntu 20.04 LTS (Focal Fossa)
2727

2828
### Version 2.0-1 28-04-2022
29-
* updating PPA to Ubuntu 22.04 LTS (Jammy Jellyfish)
30-
* Added 23 new sub-sections.
29+
* updating PPA to Ubuntu 22.04 LTS (Jammy Jellyfish)
30+
* Added 23 new sub-sections.
31+
32+
### Version 2.1-2 21-09-2022
33+
* Added 4 new sub-sections, 510 710 805 806.

lib/bmtFiles

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,43 @@ case "$1" in
112112
printf "%s" "${mime_output}"
113113
;;
114114

115+
filename) #510 /tmp/text.txt
116+
[ -z "$2" ] && return 2
117+
case "$3" in
118+
1) #510-1 full filename text.txt
119+
printf "%s" "${2##*/}" # parameter expansion retain after /
120+
;;
121+
2) #510-2 basename text
122+
local filename basename
123+
filename="${2##*/}" # parameter expansion retain after /
124+
basename="${filename%.*}" # parameter expansion retain before .
125+
printf "%s" "${basename}"
126+
;;
127+
3) #510.3 extension .txt
128+
local filename extension
129+
filename="${2##*/}" # parameter expansion retain after /
130+
extension="${filename##*.}" # parameter expansion after .
131+
[[ "${filename}" = "${extension}" ]] && return 4
132+
133+
printf "%s" "${extension}"
134+
;;
135+
4) #folder path /tmp
136+
declare folderpath=${2:-.}
137+
folderpath=${2%/*}
138+
printf "%s" "${folderpath}"
139+
;;
140+
*)
141+
return 3
142+
;;
143+
esac
144+
return 0
145+
;;
146+
115147
*) # Catch all user typos
116148
printf '%s\n' "Error: Unknown keyword : bashmultitool :bmtFiles : bmtFilesFunc"
117149
return 255
118150
;;
151+
119152
esac
120153

121154
}

lib/bmtMisc

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ case "$1" in
1515

1616
password) #801
1717
local mylengthVar=0
18+
echo "Random Password generator :"
1819
if [ -z "$2" ]; then
1920
cd "/tmp/" || return 3
21+
echo "Output Path /tmp/"
2022
else
2123
cd "$2" || return 3
24+
echo "Output Path $2"
2225
fi
2326
touch passwordBMT.txt
24-
echo "Random Password generator"
2527
echo "Enter length:-"
2628
read -r mylengthVar
2729
# if just enter pressed set default 20
@@ -42,10 +44,10 @@ case "$1" in
4244
local Filepath="/sys/class/power_supply/$2/capacity"
4345
if ! [[ -f $Filepath ]]; then
4446
echo "File '$Filepath' not found."
45-
return 101
46-
elif ! [[ -f $Filepath ]]; then
47+
return 127
48+
elif ! [[ -r $Filepath ]]; then
4749
echo "File '$Filepath' unreadable."
48-
return 102
50+
return 128
4951
fi
5052

5153
read -r < "/sys/class/power_supply/$2/capacity"
@@ -92,6 +94,7 @@ case "$1" in
9294
local colortext="$3"
9395
local bannersymbol="$4"
9496
local textmsg="$5"
97+
local edge
9598

9699
edge=$(echo "$textmsg####" | sed "s/./$bannersymbol/g")
97100

@@ -103,6 +106,40 @@ case "$1" in
103106

104107
;;
105108

109+
centertext)
110+
local banner outputtext
111+
local inputtext=" ${2} " bannersymbol="${3:- }"
112+
local stringlength=${#inputtext}
113+
local bannerlength="$((($(tput cols) - stringlength) / 2))"
114+
115+
[[ -n "${bannersymbol}" ]] && bannersymbol="${bannersymbol:0:1}"
116+
for ((i = 0; i < bannerlength; i++)); do
117+
banner+="${bannersymbol}"
118+
done
119+
120+
outputtext="${banner}${inputtext}${banner}"
121+
[[ $((($(tput cols) - stringlength) % 2)) -ne 0 ]] && outputtext+="${bannersymbol}"
122+
printf "%s" "${outputtext}"
123+
;;
124+
125+
gauge)
126+
local label="$2"
127+
local value="$3"
128+
local min="$4"
129+
local max="$5"
130+
local symbol="$6"
131+
local symbolempty="$7"
132+
133+
printf "%s=%3d %d" "$label" "$value" "$min"
134+
echo -n "["
135+
for ((i = min ; i <= value; i++)); do echo -n "$symbol"; done
136+
for ((j = value+1 ; j <= max ; j++)); do echo -n "$symbolempty"; done
137+
echo -n "]"
138+
printf "%d" "$max"
139+
echo
140+
;;
141+
142+
106143
*) # Catch all users typos
107144
printf '%s\n' "Error: Unknown keyword : bashMultiTool: bmtMisc: bmtMiscFunc"
108145
return 255

0 commit comments

Comments
 (0)