-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetPathData
More file actions
executable file
·69 lines (67 loc) · 1.57 KB
/
getPathData
File metadata and controls
executable file
·69 lines (67 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /usr/bin/env bash
if [ "$1" = '--help' ]; then
exit 1
elif [ "$1" = '--version' ]; then
exit 1
fi
# indexOf --delim
declare -a retVal=('--name')
# declare -i i=0
# while [[ "$1" =~ ^-([pdna]|-(path|dir|directory|name|all))$ ]]; do
# retVal[i]="-$1"
# shift
# ((++i))
# done
mapfile -d $'\003' -t < <(array_remove -d $'\003' --all --invert --regex '^-([pdna]|-(path|dir|directory|name|all))$' "$@")
if ((${#MAPFILE[@]} > 0)); then
retVal=("${MAPFILE[@]}")
fi
declare -a FILE_PATH_CHUNKS=()
mapfile -d $'\003' -t FILE_PATH_CHUNKS < <(array_remove -d $'\003' --all --regex '^-([pdna]|-(path|dir|directory|name|all))$' "$@")
declare -r ORIG_IFS="$IFS"
IFS=
declare FILE_PATH=
until ((${#FILE_PATH_CHUNKS[@]} <= 0)) || FILE_PATH="$(realpath "${FILE_PATH_CHUNKS[*]}")"; do
unset -v 'FILE_PATH_CHUNKS[-1]'
done
# if [ -e "${FILE_PATH_CHUNKS[*]}" ]; then
# readonly FILE_PATH="$1"
# else
# readonly FILE_PATH=$(realpath "$0")
# fi
declare -r retVal FILE_PATH
FILE_DIR=''
FILE_NAME=''
if [[ "$FILE_PATH" =~ ^(.*)/([^/]+)$ ]]; then
readonly FILE_DIR="${BASH_REMATCH[1]}" FILE_NAME="${BASH_REMATCH[2]}"
for item in "${retVal[@]}"; do
case "$item" in
(-p | --path)
echo "$FILE_PATH"
exit
;;
(-d | --dir | --directory)
echo "$FILE_DIR"
exit
;;
(-n | --name)
echo "$FILE_NAME"
exit
;;
# (-a | --all)
# declare -A MY=(
# [PATH]="$FILE_PATH"
# [DIR]="$FILE_DIR"
# [NAME]="$FILE_NAME"
# )
# declare -p MY
# exit
# ;;
(*) ;;
esac
done
else
readonly FILE_NAME="$0"
echo "$FILE_NAME: Failed to get dir" 1>&2
exit 1
fi