aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/tor.sh
blob: e6e31341b94b56e9f4b1f97883f55540fc70632f (plain) (blame)
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
# Manage Torsocks for the current shell
tor() {

    # Check first argument to figure out operation
    case $1 in

        # Show whether Torsocks
        show|'')
            case $LD_PRELOAD: in
                (*/libtorsocks.so:*)
                    printf 'on\n'
                    ;;
                (*)
                    printf 'off\n'
                    ;;
            esac
            ;;

        # Turn Torsocks on or off
        on|off)
            command -v torsocks >/dev/null 2>&1 || return
            . "$(command -v torsocks)"
            ;;

        # Command not found
        *)
            printf >&2 \
                'tor(): %s: Unknown command (try "help")\n' \
                "$1"
            return 2
            ;;
    esac
}