+PROG=ucolour
+tmux_prefix=
+[ -n "$TMUX" ] && tmux_prefix="\033Ptmux;\033"
+
+function parse_colour() {
+ local arg=$1; shift
+ local safe=${arg//[1-9]/}
+
+ if [ "$safe" = "0" -o -z "$safe" ]; then
+ # Hack to get existing.
+ local index=$(
+ local index
+ exec < /dev/tty
+ local oldstty=$(stty -g)
+ stty raw -echo min 0
+ echo -en "$tmux_prefix\033]4;$arg;?\007" > /dev/tty
+ local ret=1
+ local tries=0
+ while [ $ret -gt 0 ]; do
+ tries=$((tries+1))
+ IFS='' read -t 0
+ ret=$?
+ if [ $tries -gt 2 ]; then
+ [ $tries -gt 3 ] && break
+ sleep 1
+ fi
+ done
+ IFS='' read -r index
+ stty $oldstty
+ echo "$index"
+ )
+ if [ -n "$index" ]; then
+ index=${index##*;}
+ index=${index%?}
+ echo "$index"
+ echo >&2 "$PROG: Colour $arg is $index."
+ return 0
+ fi
+ else
+ echo "$arg"
+ return 0
+ fi
+
+ echo ""
+ return 1
+}
+