aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/xd.sh
blob: b26d88b3fe88efe4af853cc9f6f4cf5720cc8066 (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
# Swap current directory with marked directory
xd() {

    # Refuse to deal with unwanted arguments
    if [ "$#" -gt 0 ] ; then
        printf >&2 'gd(): Unspecified argument\n'
        return 2
    fi

    # Complain if mark not actually set yet
    if [ -z "$PMD" ] ; then
        printf >&2 'gd(): Mark not set\n'
        return 1
    fi

    # Put the current and marked directories into positional params
    set -- "$PMD" "$PWD"

    # Try to change into the marked directory
    cd -- "$1" || return

    # If that worked, we can swap the mark, and we're done
    PMD=$2
}