-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_find
executable file
·50 lines (39 loc) · 931 Bytes
/
_find
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
#!/bin/bash
# _find - Wrapper del comando "find".
# Modo de empleo: _find UBICACION PATRON
#region Constantes
CLR_DIR="\e[94m"
CLR_FILE="\e[92m"
CLR_PATH="\e[93m"
CLR_FIN="\e[m"
#endregion
main() {
# $1: Ubicación a buscar.
# $2: Patrón del nombre del archivo a buscar.
local ubicacion="$1"
if [ "$ubicacion" == "." ]; then
ubicacion=$(pwd)
fi
for archivo in $(_find "$ubicacion" "$2"); do
mostrar_archivo "$archivo"
done
}
_find() {
# $1: Ubicación a buscar.
# $2: Patrón del nombre del archivo a buscar.
find "$1" -name "$2" 2>/dev/null
}
mostrar_archivo() {
local archivo=$1
local dir=${archivo%/*}
local nombre=${archivo##*/}
local path="${dir}/${nombre}"
local color=
if [ -d "$path" ]; then
color=${CLR_DIR}
else
color=${CLR_FILE}
fi
echo -e "${CLR_PATH}${dir}/${color}${nombre}${CLR_FIN}"
}
main "$@"