summaryrefslogtreecommitdiff
path: root/.zsh/zshfunctions
blob: b9c074e41e2a1af028b96a6750dc27cf982f7c80 (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
# Nice mappings to restart/... the services
Start Stop Reload Restart ()
{
    [[ $UID != 0 ]] && SUDO="sudo"
    $SUDO /etc/init.d/$1 ${0:l}
}

# Change to the directory of a specific package
cdu ()
{
    local cp
    
    [[ -n $1 ]] && cp=$(eix -e $1 --format "<category>/<name>" 2>/dev/null | head -n1)

    cd /usr/portage/${cp}
}

# Open the ebuild with a specified command
open_ebuild ()
{
    local ebuild=$(equery --debug w $2 2> /dev/null)

    if [[ -z $ebuild ]]; then
        echo "Trying masked packages too..."
        ebuild=$(equery --debug w -m $2 2> /dev/null)
    fi

    if [[ -n $ebuild ]]; then
        $1 $ebuild
    else
        echo "No ebuild found"
    fi
}

if [[ $UID == 0 ]]; then

    # unpack a package
    unpack()
    {
        ebuild $(equery w -m $1) clean unpack
    }

    # set job count to 1 if there is only one package to install
    emerge()
    {
        local e=$(whence -p emerge)
        if [[ $# < 3 ]]; then
            $e --jobs=1 $@
        else
            $e $@
        fi
    }
fi