Skip to content

Commit f48a1d4

Browse files
committed
* up to date README.md and RELEASENOTES.md
* fixed assertion code in rmdir_safer * r_absolutepath will now fail if it can't figure out the working directory for a provided relative path (empty path is OK but returns 1)
1 parent 08b948c commit f48a1d4

12 files changed

+251
-192
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required (VERSION 3.13)
22

3-
project( mulle-bashfunctions VERSION 6.6.1 LANGUAGES NONE)
3+
project( mulle-bashfunctions VERSION 6.6.2 LANGUAGES NONE)
44

55

66
#

README.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ tested on **Debian**, **FreeBSD**, **macOS**, **Manjaro**, **MinGW**,
2020

2121
## Developer Guide
2222

23+
### Use mulle-bashfunctions in an old bash script
24+
25+
Add this near the top of your script. This will load the default set of
26+
mulle-bashfunctions:
27+
28+
29+
``` bash
30+
eval "`mulle-bashfunctions load --if-missing `"
31+
[ -z "${MULLE_BASHGLOBAL_SH}" ] && exit 1
32+
```
33+
34+
### Create a new mulle-bash script
35+
2336
To create a new mulle-bashfunctions script say:
2437

2538
``` sh
@@ -29,7 +42,7 @@ chmod +x my-script.sh
2942

3043
Use **mulle-bashfunctions** also for discovery and documentation of the
3144
available functions. Lets say you want to produce identifiers
32-
for abitrary strings. You can use `apropos` to discover functionality:
45+
for arbitrary strings. You can use `apropos` to discover functionality:
3346

3447
``` sh
3548
mulle-bashfunctions apropos identifier
@@ -99,40 +112,47 @@ Use `include "<name>"` to get access to the functions not included in
99112
Usage:
100113
mulle-bashfunctions [command]
101114
102-
mulle-bashfunctions main purpose is to help load the library functions
103-
into an interactive shell. The library functions are almalgamated in a
104-
file called "mulle-bashfunctions.sh". There are variants though (none,
105-
minimal, all) with different sizes.
106-
107-
But mulle-bashfunctions can also
115+
Use mulle-bashfunctions to
108116
117+
* load the mulle-bashfunctions into an interactive shell
118+
* show documentation for the provided shell functions
109119
* embed "mulle-bashfunctions.sh" into another shell script
110120
* show the path to "mulle-bashfunctions.sh"
111121
* locate the "mulle-bashfunctions.sh" install path for a desired variant
112-
* show documentation for any of the defined functions
113122
* list the available libraries, which you can "include"
114123
* run an arbitrary mulle-bashfunction with eval and r-eval
124+
* get some information about the execution environment
115125
116-
Examples:
117-
Load "mulle-bashfunctions-all.sh" into the current interactive shell:
126+
Example:
127+
Load mulle-bashfunctions into the current interactive shell:
118128
119129
eval `mulle-bashfunctions load all`
120130
131+
Now try out an r_function, a function which returns a value in the global
132+
variable RVAL:
133+
134+
r_escaped_json '{ "url": "https://www.mulle-kybernetik.com" }'
135+
echo $RVAL
136+
121137
Commands:
122138
apropos <f> : search for a function by keywords
123139
embed : embed mulle-bashfunctions into a script
140+
common-unames : list of known values for uname
124141
env : print environment needed for "mulle-bashfunctions.sh"
125142
eval <cmd> : evaluate cmd inside of mulle-bashfunctions
143+
globals [-a] : list global MULLE_ prefixed variables, -a for all globals
126144
functions : list defined functions
127145
hostname : show system hostname as used by mulle-bashfunctions
128146
libraries : list available libraries
129-
load [variant] : use eval `mulle-bashfunctions load` to load
147+
load [variant] : eval `mulle-bashfunctions load <none|minimal|all>`
130148
man <function> : show documention for function, if available
131149
new <name> : prints a mulle-bash shell script
132150
path [variant] : path to "mulle-bashfunctions.sh"
133151
r-eval <cmd> : evaluate cmd inside of mulle-bashfunctions and print RVAL
152+
shell : path of executing shell
134153
username : show username as used by mulle-bashfunctions
135154
uname : show system short name as used by mulle-bashfunctions
155+
uuid : generate a UUID
136156
version : print currently used version
137157
versions : list installed versions
138158

RELEASENOTES.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
### 6.6.2
2+
3+
* up to date README.md and RELEASENOTES.md
4+
* fixed assertion code in `rmdir_safer`
5+
* `r_absolutepath` will now fail if it can't figure out the working directory for a provided relative path (empty path is OK but returns 1)
6+
7+
### 6.6.1
8+
9+
* fixed filepath_contains_filepath for the '.' directory where foo.sh now matches
10+
11+
## 6.6.0
12+
13+
* fix IFS restore in r_reverse_lines
14+
* add filepath_contains_filepath function to check if a path contains another
15+
* add r_url_path_encode function that preserves forward slashes
16+
* improve PATH fallback in mulle-bash
17+
* add globals command to list MULLE_ variables
18+
* fix dir_list_files IFS restore
19+
* fix sed and grep escaping painfully for zsh
20+
121
### 6.5.1
222

323
* updated sed escaping for mulle-template

cola/api.md.bud

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
## Developer Guide
22

3+
### Use mulle-bashfunctions in an old bash script
4+
5+
Add this near the top of your script. This will load the default set of
6+
mulle-bashfunctions:
7+
8+
9+
``` bash
10+
eval "`mulle-bashfunctions load --if-missing `"
11+
[ -z "${MULLE_BASHGLOBAL_SH}" ] && exit 1
12+
```
13+
14+
### Create a new mulle-bash script
15+
316
To create a new mulle-bashfunctions script say:
417

518
``` sh
@@ -9,7 +22,7 @@ chmod +x my-script.sh
922

1023
Use **mulle-bashfunctions** also for discovery and documentation of the
1124
available functions. Lets say you want to produce identifiers
12-
for abitrary strings. You can use `apropos` to discover functionality:
25+
for arbitrary strings. You can use `apropos` to discover functionality:
1326

1427
``` sh
1528
mulle-bashfunctions apropos identifier

mulle-bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fi
151151
# this is "our" version
152152
# the actual loaded version may differ (and will change this variable)
153153
#
154-
MULLE_BASHFUNCTIONS_VERSION="6.6.1"
154+
MULLE_BASHFUNCTIONS_VERSION="6.6.2"
155155
MULLE_BASHFUNCTIONS_LIBEXEC_DIRNAME="libexec"
156156
MULLE_EXECUTABLE="$1"
157157

mulle-bashfunctions

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,22 +1267,33 @@ MULLE_UNAME=\"${MULLE_UNAME}\""
12671267

12681268
'load')
12691269
local format
1270+
local check
12701271

1271-
[ $# -ne 0 ] && format="-$1"
1272+
[ $# -ne 0 -a "$1" = "--if-missing" ] && check='YES' && shift
1273+
[ $# -ne 0 ] && format="-$1" && shift
1274+
1275+
if [ "${check}" = 'YES' ]
1276+
then
1277+
echo "if [ -z \"\${MULLE_BASHGLOBAL_SH}\" ]; then"
1278+
fi
12721279

12731280
echo "\
1274-
MULLE_BASHFUNCTIONS_LIBEXEC_DIR=\"${MULLE_BASHFUNCTIONS_LIBEXEC_DIR}\" ;
1275-
export MULLE_BASHFUNCTIONS_LIBEXEC_DIR ;
1276-
MULLE_USERNAME=\"${MULLE_USERNAME}\" ;
1277-
export MULLE_USERNAME ;
1278-
MULLE_HOSTNAME=\"${MULLE_HOSTNAME}\" ;
1279-
export MULLE_HOSTNAME ;
1280-
MULLE_UNAME=\"${MULLE_UNAME}\" ;
1281-
export MULLE_UNAME ;
1282-
. \"${MULLE_BASHFUNCTIONS_LIBEXEC_DIR}/mulle-bashfunctions${format}.sh\"
1283-
"
1281+
MULLE_BASHFUNCTIONS_LIBEXEC_DIR=\"${MULLE_BASHFUNCTIONS_LIBEXEC_DIR}\"
1282+
export MULLE_BASHFUNCTIONS_LIBEXEC_DIR
1283+
MULLE_USERNAME=\"${MULLE_USERNAME}\"
1284+
export MULLE_USERNAME
1285+
MULLE_HOSTNAME=\"${MULLE_HOSTNAME}\"
1286+
export MULLE_HOSTNAME
1287+
MULLE_UNAME=\"${MULLE_UNAME}\"
1288+
export MULLE_UNAME
1289+
. \"${MULLE_BASHFUNCTIONS_LIBEXEC_DIR}/mulle-bashfunctions${format}.sh\""
1290+
if [ "${check}" = 'YES' ]
1291+
then
1292+
echo "fi"
1293+
fi
12841294
;;
12851295

1296+
12861297
'common-unames')
12871298
cat <<EOF
12881299
android

src/mulle-bashfunctions-all-embed.sh

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,43 +3258,35 @@ function is_relativepath()
32583258

32593259
function r_absolutepath()
32603260
{
3261-
local directory="$1"
3262-
local working="${2:-${PWD}}"
3261+
local filepath="$1"
3262+
local working="$2"
32633263

3264-
case "${directory}" in
3264+
case "${filepath}" in
32653265
"")
32663266
RVAL=''
3267+
return 1
32673268
;;
32683269

32693270
/*|~*)
3270-
RVAL="${directory}"
3271-
;;
3272-
3273-
*)
3274-
RVAL="${working}/${directory}"
3271+
RVAL="${filepath}"
3272+
return 0
32753273
;;
32763274
esac
3275+
3276+
working="${working:-`pwd`}"
3277+
if ! is_absolutepath "${working}"
3278+
then
3279+
fail "working directory \"${working}\" must be an absolute path"
3280+
fi
3281+
3282+
RVAL="${working%%/}/${filepath}"
32773283
}
32783284

32793285

32803286
function r_simplified_absolutepath()
32813287
{
3282-
local directory="$1"
3283-
local working="${2:-${PWD}}"
3284-
3285-
case "${1}" in
3286-
"")
3287-
RVAL=''
3288-
;;
3289-
3290-
/*|~*)
3291-
r_simplified_path "${directory}"
3292-
;;
3293-
3294-
*)
3295-
r_simplified_path "${working}/${directory}"
3296-
;;
3297-
esac
3288+
r_absolutepath "$@"
3289+
r_simplified_path "${RVAL}"
32983290
}
32993291

33003292
function r_symlink_relpath()
@@ -3563,29 +3555,33 @@ function r_mkdir_parent_if_missing()
35633555

35643556
function dir_is_empty()
35653557
{
3566-
[ -z "$1" ] && _internal_fail "empty path"
3558+
local directory="$1"
3559+
3560+
[ -z "${directory}" ] && _internal_fail "empty path"
35673561

3568-
if [ ! -d "$1" ]
3562+
if [ ! -d "${directory}" ]
35693563
then
35703564
return 2
35713565
fi
35723566

35733567
local empty
35743568

3575-
empty="`ls -A "$1" 2> /dev/null`"
3569+
empty="`ls -A "${directory}" 2> /dev/null`"
35763570
[ -z "$empty" ]
35773571
}
35783572

35793573

35803574
rmdir_safer()
35813575
{
3582-
[ -z "$1" ] && _internal_fail "empty path"
3576+
local directory="$1"
3577+
3578+
[ -z "${directory}" ] && _internal_fail "empty path"
35833579

35843580
[ $"PWD" = "${directory}" ] && fail "Refuse to remove PWD"
35853581

3586-
if [ -d "$1" ]
3582+
if [ -d "${directory}" ]
35873583
then
3588-
r_assert_sane_path "$1"
3584+
r_assert_sane_path "${directory}"
35893585

35903586
case "${MULLE_UNAME}" in
35913587
'android'|'sunos')
@@ -3602,11 +3598,13 @@ rmdir_safer()
36023598

36033599
rmdir_if_empty()
36043600
{
3605-
[ -z "$1" ] && _internal_fail "empty path"
3601+
local directory="$1"
36063602

3607-
if dir_is_empty "$1"
3603+
[ -z "${directory}" ] && _internal_fail "empty path"
3604+
3605+
if dir_is_empty "${directory}"
36083606
then
3609-
exekutor rmdir "$1" >&2 || fail "failed to remove $1"
3607+
exekutor rmdir "${directory}" >&2 || fail "failed to remove $1"
36103608
fi
36113609
}
36123610

@@ -3626,6 +3624,7 @@ _create_file_if_missing()
36263624

36273625
r_dirname "${filepath}"
36283626
directory="${RVAL}"
3627+
36293628
if [ ! -z "${directory}" ]
36303629
then
36313630
mkdir_if_missing "${directory}"

0 commit comments

Comments
 (0)