-
Notifications
You must be signed in to change notification settings - Fork 119
/
zzmcd.sh
53 lines (48 loc) · 1.32 KB
/
zzmcd.sh
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
# ----------------------------------------------------------------------------
# Cria diretórios e subdiretórios, e muda diretório de trabalho (primeiro).
#
# Opções:
# -n: Cria os diretórios, mas não muda o diretório de trabalho atual.
# -s: Apenas simula o comando mkdir com os argumentos
#
# Uso: zzmcd [-n|-s] <dir[/subdir]> [dir[/subdir]]
# Ex.: zzmcd tmp1/tmp2
#
# Autor: Itamar <itamarnet (a) yahoo com br>
# Desde: 2018-03-30
# Versão: 1
# Licença: GPL
# Tags: diretório, emulação
# ----------------------------------------------------------------------------
zzmcd ()
{
zzzz -h mcd "$1" && return
local opt dir erro
# Verificação das opções
while test "${1#-}" != "$1"
do
case "$1" in
-n) opt="n"; shift;;
-s) opt="s"; shift;;
--) shift; break;;
-*) zztool -e uso mcd; return 1;;
esac
done
# Verificação dos parâmetros
test -n "$1" || { zztool -e uso mcd; return 1; }
# Cria/simula os diretório
case "$opt" in
s) echo mkdir -p $*; erro=0 ;;
*)
mkdir -p $* 2>/dev/null && test 'n' = "$opt" && erro=0
# Verificando diretórios que falharam
for dir in $*
do
test -d "$dir" || zztool erro "'$dir' não criado."
done
;;
esac
# Desloca-se ao primeiro diretório criado no último nivel possível
test -d "$1" && test -z "$opt" && cd "$1"
return $erro
}