Allow overriding colours in uxrvt palette.
authorIain Patterson <me@iain.cx>
Wed, 18 May 2016 13:02:52 +0000 (14:02 +0100)
committerIain Patterson <me@iain.cx>
Tue, 24 May 2016 09:15:24 +0000 (10:15 +0100)
opt/bin/ucolour

index a3d0600..2b5fc1f 100755 (executable)
 #          -f   Set foreground.
 #          -F   Set highlight foreground.
 #          -m   Set mouse.
 #          -f   Set foreground.
 #          -F   Set highlight foreground.
 #          -m   Set mouse.
+#          -P   Palette index.
+#          -p   Set palette reference with -P.
 # Notes: Border defaults to background.
 # Notes: Border defaults to background.
+#        The -P and -p flags must be used together.
 #
 
 BG=
 #
 
 BG=
@@ -20,22 +23,32 @@ bd=
 fg=
 cu=
 mo=
 fg=
 cu=
 mo=
+pc=
+ps=
 tmux_prefix=
 tmux_prefix=
-while getopts ":B:F:b:c:d:f:m:" opt; do
+while getopts ":B:F:P:b:c:d:f:m:p:" opt; do
   case $opt in
     B) BG=$OPTARG;;
     F) FG=$OPTARG;;
   case $opt in
     B) BG=$OPTARG;;
     F) FG=$OPTARG;;
+    P) pc=$OPTARG;;
     b) bg=$OPTARG;;
     c) cu=$OPTARG;;
     d) bd=$OPTARG;;
     f) fg=$OPTARG;;
     m) mo=$OPTARG;;
     b) bg=$OPTARG;;
     c) cu=$OPTARG;;
     d) bd=$OPTARG;;
     f) fg=$OPTARG;;
     m) mo=$OPTARG;;
+    p) ps=$OPTARG;;
   esac
 done
 shift $((OPTIND-1))
 
   esac
 done
 shift $((OPTIND-1))
 
+if [ -n "$pc" -o -n "$ps" ]; then
+  if [ -z "$pc" -o -z "$ps" ]; then
+    echo >&2 "$PROG: Must use -P and -p together."
+    exit 1
+  fi
+fi
 [ -n "$bg" -a -z "$bd" ] && bd=$bg
 [ -n "$bg" -a -z "$bd" ] && bd=$bg
-if [ -z "$BG$FG$bd$bg$cu$fg$mo" ]; then
+if [ -z "$BG$FG$bd$bg$cu$fg$mo$pc" ]; then
   echo >&2 "Usage: ucolour option <colour> [option <colour> ...]"
   echo >&2 "Options: -b   Set background."
   echo >&2 "         -B   Set highlight background."
   echo >&2 "Usage: ucolour option <colour> [option <colour> ...]"
   echo >&2 "Options: -b   Set background."
   echo >&2 "         -B   Set highlight background."
@@ -44,7 +57,10 @@ if [ -z "$BG$FG$bd$bg$cu$fg$mo" ]; then
   echo >&2 "         -f   Set foreground."
   echo >&2 "         -F   Set highlight foreground."
   echo >&2 "         -m   Set mouse."
   echo >&2 "         -f   Set foreground."
   echo >&2 "         -F   Set highlight foreground."
   echo >&2 "         -m   Set mouse."
+  echo >&2 "         -P   Palette index."
+  echo >&2 "         -p   Set palette reference with -P."
   echo >&2 "Notes: Border defaults to background."
   echo >&2 "Notes: Border defaults to background."
+  echo >&2 "       The -P and -p flags must be used together."
   exit 1
 fi
 
   exit 1
 fi
 
@@ -56,4 +72,5 @@ fi
 [ -n "$cu" ] && echo -en "$tmux_prefix\033]12;$cu\007"
 [ -n "$fg" ] && echo -en "$tmux_prefix\033]10;$fg\007"
 [ -n "$mo" ] && echo -en "$tmux_prefix\033]13;$mo\007"
 [ -n "$cu" ] && echo -en "$tmux_prefix\033]12;$cu\007"
 [ -n "$fg" ] && echo -en "$tmux_prefix\033]10;$fg\007"
 [ -n "$mo" ] && echo -en "$tmux_prefix\033]13;$mo\007"
+[ -n "$pc" ] && echo -en "$tmux_prefix\033]4;$pc;$ps\007"
 exit 0
 exit 0