aboutsummaryrefslogtreecommitdiff
path: root/intellij-idea/run
blob: 9b8a5764046cc926b8c12b5a5d977e5e2db032cf (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
#!/bin/bash

if [ -z "$DISPLAY" ]; then
    echo "\$DISPLAY is not set"
    DISPLAYS=( $(netstat -lnt | awk '/127.0.0.1:60/ { split($4,a,":"); print "localhost:" substr(a[2],3) ".0" }') )

    if [ "${#DISPLAYS[@]}" = 0 ]; then
        echo "No X11 ports available"
        exit 1
    fi

    if [ "${#DISPLAYS[@]}" > 1 ]; then
        echo "More than 1 X11 port available. Which one do you want?"
        for i in "${DISPLAYS[@]}"; do
            echo "export DISPLAY=\"$i\""
        done
        exit 1
    else
        export DISPLAY="${DISPLAYS[0]}"
    fi
fi

docker run -ti --rm --net=host \
    -e DISPLAY \
    -e XAUTHORITY=$HOME/.Xauthority \
    -v /usr/share/zoneinfo/America/Los_Angeles:/etc/localtime:ro \
    -v $HOME:$HOME \
    intellij-idea "$@"