bible: fix dirname. Closes #76

This commit is contained in:
Dylan Araps
2019-09-19 16:23:20 +03:00
parent 6508ca0c9d
commit ea8fd2369c
4 changed files with 17 additions and 9 deletions

View File

@@ -9,7 +9,11 @@ Alternative to the `dirname` command.
```sh
dirname() {
# Usage: dirname "path"
printf '%s\n' "${1%/*}/"
dir=${1%%/}
[[ $dir == */* ]] || dir=.
printf '%s\n' "${dir%/*}"
}
```
@@ -17,10 +21,10 @@ dirname() {
```shell
$ dirname ~/Pictures/Wallpapers/1.jpg
/home/black/Pictures/Wallpapers/
/home/black/Pictures/Wallpapers
$ dirname ~/Pictures/Downloads/
/home/black/Pictures/
/home/black/Pictures
```
## Get the base-name of a file path