SHARE
TWEET

Untitled

a guest Feb 24th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. ## loads $HOME/.config/gcolors.conf
  3. ## supports mtPaint and GIMP palette formats (read/write)
  4. ## remembers last used color, window size and location
  5.  
  6. if ! [ -f $HOME/.config/gcolors.conf ] ; then
  7.     cp /usr/share/X11/rgb.txt $HOME/.config/gcolors.conf
  8. fi
  9. palettefile="$HOME/.config/gcolors.conf"
  10.  
  11. [ "$1" != "" -a -f "$1" ] && palettefile=$1
  12.  
  13. export palettefile
  14. export geofile=/tmp/yadcol_geometry.txt valfile=/tmp/yadcol_lastused.txt
  15.  
  16. function savegeo {
  17.     WINDOWID=$(xprop -root _NET_ACTIVE_WINDOW)
  18.     WINDOWID=${WINDOWID##* }
  19.     XWININFO=$(xwininfo -id $WINDOWID)
  20.     set -- ${@} ${XWININFO#* X: }
  21.     AX=$1 AY=$5 RX=$9 RY=${13}
  22.     echo -n "${15}x${17}+$((AX-RX))+$((AY-RY))" > $geofile
  23. };export -f savegeo
  24.  
  25. fileheader=$(grep '^[^ 0-9].*' -o "$palettefile")   #extract GIMP file header
  26. [[ $fileheader ]] && fileheader=${fileheader}$'\n'  #keep variable empty if header does not exist
  27.  
  28. while : ;do
  29.     colorval=$(yad --color --title="Fake gcolor2 (fallback if binary is missing)" \
  30.     --window-icon=/usr/share/pixmaps/puppy/graphics.svg \
  31.     --init-color="$(< $valfile)"  --geometry="$(< $geofile)" \
  32.     --always-print-result --gtk-palette --expand-palette \
  33.     --palette=<(awk "/^[ 0-9]/" "$palettefile") \
  34.     --${disable}button="Save color:bash -c 'savegeo; kill -s SIGUSR2 \$YAD_PID'" \
  35.     --button="Edit gcolors.conf:defaulttexteditor $HOME/.config/gcolors.conf" \
  36.     --button="Quit:9" )
  37.     ret=$?
  38.     case $ret in
  39.         0) : OK; echo -n $colorval; echo $colorval > "$valfile" ; break ;;
  40.         1) : SAVE; newname=$(gxmessage -title "Save color" -bg $colorval -c -entrytext 'NewColorName' $'\n\t'"Color $colorval")
  41.             (($?)) || printf '%s%d %d %d\t%s\n%s\n' "$fileheader" 0\x${colorval:1:2} 0\x${colorval:3:2} 0\x${colorval:5:2} "$newname" "$(awk '/^[ 0-9]/' "$palettefile")" > "$palettefile"
  42.             echo $colorval > "$valfile" ;;
  43.         *) : CANCEL; break ;; #ret = 9 or 252
  44.     esac
  45. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top