Codebase list kali-defaults / fedb2d8
Merge branch 'treecd' into 'kali/master' Add kali_treecd function g0t mi1k 4 years ago
1 changed file(s) with 53 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
11
22 # Add /usr/local/sbin, /usr/sbin and /sbin to the PATH for all users
33 if ! echo "$PATH" | tr : '\n' | grep -q "^/sbin$"; then
4 PATH="/usr/local/sbin:/usr/sbin:/sbin:$PATH"
4 PATH="/usr/local/sbin:/usr/sbin:/sbin:$PATH"
55 fi
6
7
8 ## kali_treecd (<location> <package-name> <depth> <folders-only>)
9 kali_treecd () {
10 ## Location to use: /usr/share/example
11 location="${1-/}"
12 ## Package name: example
13 package="$2"
14 ## Depth: 0-9 (default to 1)
15 depth="${3:-1}"
16 ## List only folders: true/false (default to true)
17 folders="${4:-true}"
18
19
20 ## Package Description ~ $ awk -F ': ' '/^Description: / {print $2}' ./example/debian/control
21 [ ! -z "${package}" ] \
22 && description="$( dpkg-query -f'${binary:Synopsis}\n' -W ${package} 2>/dev/null )"
23
24
25 ## Feedback - Banner
26 [ ! -z "${description}" ] \
27 && echo "> ${package} ~ ${description}"
28
29
30 ## Move to location
31 cd "${location}"
32
33
34 ## List output
35 if [ "$( which tree )" ]; then
36 ## Check to see if folders only
37 [ "${folders}" = "true" ] \
38 && folder="-d" \
39 || folder=""
40
41 ## Using tree, display output
42 tree ${folder} -L ${depth} --prune --noreport "${location}"
43 else
44 ## Feedback - Location
45 echo "${location}"
46
47 ## Check to see if folders only
48 [ "${folders}" = "true" ] \
49 && folder="-type d" \
50 || folder=""
51
52 ## Using find/sed, display output
53 find "${location}" -maxdepth ${depth} -mindepth 1 ${folder} \
54 | sort \
55 | sed -e 's/[^-][^\/]*\//-/g; s/^/ /; s/-/|/'
56 fi
57 }