forked from CamilleScholtz/bin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdp
executable file
·42 lines (34 loc) · 794 Bytes
/
cdp
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
#!/bin/bash
#
# cdp - cd to port
# onodera, https://github.com/onodera-punpun
## CONFIGURATION
# Config location
config="/etc/mk.conf"
## EXECUTE
if [[ "$#" -ge 1 ]]; then
order="$(grep "^order" "$config" | cut -d " " -f 2-)"
location="$(ports -l | grep "/$@$")"
# Order
# TODO: Find a better way of doing this?
# TODO: Doesn't work with source
if [[ "$(echo "$location" | wc -l)" -ge 2 ]]; then
for line in $order; do
echo a
locationorder="$(echo "$location" | grep "^$line/")"
if [[ -n "$locationorder" ]]; then
location="$locationorder"
echo "$location"
break
fi
done
fi
if [[ -d "/usr/ports/$location" ]] && [[ -n "$location" ]]; then
cd "/usr/ports/$location"
else
echo "cdp: invalid port $1"
cd "/usr/ports"
fi
else
cd "/usr/ports"
fi