blob: f1691f22b4d7f269e5a725e37dabf07df4cbcf7a (
plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
echo1() {
echo "$1"
}
ego() {
local portdir tmpdir category pkg target
# This is WAY faster than portageq:
# portdir=$(portageq portdir)
# tmpdir=$(portageq envvar PORTAGE_TMPDIR)/portage
eval $(
. /etc/make.globals
. /etc/make.conf
export PORTDIR PORTAGE_TMPDIR
export | sed -n '
s/^declare -x PORTDIR=/portdir=/p
s/^declare -x PORTAGE_TMPDIR=\(.*\)/tmpdir=\1\/portage/p'
)
case $1 in
*-*/*)
pkg=${1##*/}
category=${1%/*}
;;
?*)
pkg=$1
# require an ebuild so that we can block deprecated packages
# such as dev-libs/rep-gtk
category=$(echo1 $portdir/*-*/$pkg/*.ebuild)
[[ -f $category ]] || category=$(echo1 $portdir/*-*/$pkg*/*.ebuild)
[[ -f $category ]] || category=$(echo1 $portdir/*-*/*$pkg/*.ebuild)
[[ -f $category ]] || category=$(echo1 $portdir/*-*/*$pkg*/*.ebuild)
if [[ ! -f $category ]]; then
echo "Can't find $pkg in $portdir" >&2
return 1
fi
pkg=${category%/*}
pkg=${pkg##*/}
category=${category#$portdir/}
category=${category%%/*}
;;
*)
# Check if we're under $portdir first
pkg=${PWD##*/}
category=${PWD%/*}
category=${category##*/}
if [[ ! -d $portdir/$category/$pkg ]]; then
# Next check if we're in PORTAGE_TMPDIR
if [[ $PWD = $tmpdir/* ]]; then
pkg=${PWD#$tmpdir/}
pkg=${pkg%%/*}
pkg=${pkg%%-[0-9]*} # not really a valid assumption
category=$(echo1 $portdir/*-*/$pkg/*.ebuild)
if [[ ! -f $category ]]; then
echo "Can't find $pkg in $portdir" >&2
return 1
fi
category=${category#$portdir/}
category=${category%%/*}
else
echo "syntax: ego [pkgname]" >&2
echo "or simply ego from a dir under $portdir or $tmpdir" >&2
return 1
fi
fi
;;
esac
# go to tmpdir or portdir?
if [[ $PWD/ = */$category/$pkg/* ]]; then
[[ -n $tmpdir ]] || tmpdir=$(portageq envvar PORTAGE_TMPDIR)/portage
target=$(command ls -1td $tmpdir/$pkg-* 2>/dev/null | head -n 1)
if [[ -z $target ]]; then
echo "No matches found for $tmpdir/$pkg-*" >&2
return 1
fi
cd $target/work/$pkg* 2>/dev/null ||
cd $target/work 2>/dev/null ||
cd $target
else
cd $portdir/$category/$pkg
fi
}
|