summaryrefslogtreecommitdiffstats
path: root/nix-script-show-generation.sh
blob: 27320adf1430da528cd6913ac60387c733ef3c1f (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
#!/usr/bin/env bash

source $(dirname ${BASH_SOURCE[0]})/nix-utils.sh

usage() {
    cat <<EOS
    $(help_synopsis "${BASH_SOURCE[0]}" "[-s | -u] [-h]")

        -s       Show system generation
        -u       Show user generation (default)
        -h       Show this help and exit

    Show the number of the current generations. Defaults to user
    profile, but system profile can be checked as well.

    Example usage:

        # To show the system generation which is current.
        # With verbosity on.
        nix-script -v show-generations -s

$(help_end)
EOS
}

SYSTEM=0
USER=1

while getopts "suh" OPTION
do
    case $OPTION in
        s)
            SYSTEM=1
            USER=0
            stdout "Showing system generation"
            ;;
        u)
            SYSTEM=0
            USER=1
            stdout "Showing user generation"
            ;;
        h)
            stdout "Showing usage"
            usage
            exit 0
            ;;
    esac
done

([[ $SYSTEM -eq 1 ]] && current_system_generation) || current_user_generation

stdout "Ready"