-
Notifications
You must be signed in to change notification settings - Fork 1
/
pushDir.sh
executable file
·65 lines (54 loc) · 1.59 KB
/
pushDir.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
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
#
set -e
myPath=$(dirname $(realpath $0))
. "${myPath}/preprocess.sh"
if [[ $# -gt 0 ]]; then
if [[ ${1} == '-c' ]]; then
dir_pattern_seed="${2}"
fi
fi
[[ -d ${rootfs} && -x ${rootfs} ]] \
|| { echo "directory ${rootfs} does not exists or is unexecutable"; exit 1; }
if [[ -n ${dir_pattern_seed} ]]; then
eval "$(grep '^[[:space:]]*PORTAGE_TMPDIR=' \
${rootfs}usr/share/portage/config/make.globals \
${rootfs}etc/portage/make.conf | tail -1 | cut -d':' -f2)"
dirs=$(LC_ALL=C find ${rootfs}${PORTAGE_TMPDIR##/} -maxdepth 4 -type d)
dir_pattern=
while read -r p; do
if [[ ${p} != "" ]]; then
dir_pattern+="\/[^\/]*${p}[^\/]*"
fi
done <<<"${dir_pattern_seed//\//$'\n'}"
declare -a select_dirs
while read -r p; do
if [[ -z ${dir_len} ]]; then
dir_len=${#p}
fi
if [[ ${#p} -gt ${dir_len} ]]; then
continue
fi
select_dirs+=("${p}")
done <<<$(eval "<<<'${dirs}' sed -nE '/${dir_pattern}/p'")
if [[ ${#select_dirs[@]} -gt 1 ]]; then
echo -e "\e[36mselect one from:\e[0m"
for (( i = 0; i < ${#select_dirs[@]}; i++ )); do
echo " [${i}] ${select_dirs[i]}"
done
read -p "select: " theindex
select_dirs[0]="${select_dirs[${theindex}]}"
elif [[ ${#select_dirs[@]} -lt 1 || ${select_dirs[0]} == "" ]]; then
echo "no matched path!"
exit 0
fi
if [[ -d ${select_dirs[0]} ]]; then
pushingdir=${select_dirs[0]}
fi
fi
: ${pushingdir:=${rootfs}}
echo ">>> shell into ${pushingdir} ..."
echo "[press CTRL-D to exit]"
pushd ${pushingdir} >/dev/null
unset _PREPROCESSED
eval "exec ${SHELL} -i"