mbxcolors/bin/mbxcolors

627 lines
21 KiB
Plaintext
Raw Permalink Normal View History

2021-10-09 00:21:44 +02:00
#!/usr/bin/env bash
2022-04-22 02:17:44 +02:00
# Copyright (C) Daniel Napora 2021-22 <napcok@gmail.com>
2022-04-25 02:58:43 +02:00
# Dependencies: jgmenu, xdotool, xcolor, gcolor3, gpick, pastel, xdg-utils, xclip, notify-send
2021-10-27 02:39:14 +02:00
# TODO export to .gpl (GIMP,Inkscape)
2021-10-09 00:21:44 +02:00
2022-06-10 10:16:49 +02:00
VERSION="0.9.8"
TEMP_DIR=/tmp/colormenu
2021-10-26 15:35:39 +02:00
ME=${0##*/}
2021-10-09 00:21:44 +02:00
2021-10-29 02:00:19 +02:00
DATA_DIR="/usr/share/$ME"
2021-10-09 00:21:44 +02:00
CNF_DIR="$HOME/.config/mbxcolors"
CNF_FILE="$CNF_DIR/mbxcolors.cfg"
RECENT="$CNF_DIR/recent.clr"
USED="$CNF_DIR/.used"
LASTPAL="$CNF_DIR/.palette"
2021-10-29 12:57:41 +02:00
[ ! -d "$CNF_DIR" ] && mkdir -p "$CNF_DIR"
2021-10-09 00:21:44 +02:00
if [ ! -f $CNF_FILE ]; then
cat <<EOF > ${CNF_FILE}
# Paste mode: hex,rgb or rgba
format=hex
#Action when color is clicked: paste (imadietely) or copy (to clipboard)
2021-10-29 12:57:41 +02:00
action=copy
2021-10-09 00:21:44 +02:00
#What thing to expose on top of main menu: recently picked colors, last used colors or last used palette
2021-10-29 11:38:53 +02:00
expose=picked
2021-10-09 00:21:44 +02:00
#Show HTML colors? yes|no
htmlcolors=yes
2022-04-24 18:43:34 +02:00
#Color picker (gpick or xcolor)
picker=gpick
#Show built in palettes? (slow)
builtin_palettes=yes
2022-04-25 02:58:43 +02:00
# Random wallpaper dir
walldir=/usr/share/backgrounds
2021-10-09 00:21:44 +02:00
#Position on screen: topleft, top, topright, left, center, right, bottomleft, bottom, bottomright
2021-10-09 14:55:42 +02:00
position=left
2021-10-09 00:21:44 +02:00
EOF
fi
source <(grep = $CNF_FILE)
2022-04-25 02:58:43 +02:00
RANDWALLDIR=${walldir:-/usr/share/backgrounds}
2021-10-09 00:21:44 +02:00
if [ ! -f $RECENT ]; then
cat <<EOF > ${RECENT}
#FFFFFF White
#C0C0C0 Silver
#808080 Gray
#000000 Black
EOF
fi
fgcolor() {
r=$(printf "%d" 0x${1:1:2}) g=$(printf "%d" 0x${1:3:2}) b=$(printf "%d" 0x${1:5:2})
[ "$((r*299+g*587+b*114))" -gt 149000 ] && echo "#111111" || echo "#EEEEEE"
}
hex2rgb() {
r=$(printf "%d" 0x${1:1:2}) g=$(printf "%d" 0x${1:3:2}) b=$(printf "%d" 0x${1:5:2})
echo "rgb($r, $g, $b)"
}
hex2rgba() {
r=$(printf "%d" 0x${1:1:2}) g=$(printf "%d" 0x${1:3:2}) b=$(printf "%d" 0x${1:5:2})
echo "rgba($r, $g, $b, 1.0)"
}
pickcolor() {
size=${xcolor_preview_size:-255}
scale=${xcolor_scale:-8}
2022-04-24 18:43:34 +02:00
picker=${picker:-gpick}
if [ "$picker" == "gpick" ]; then
command="gpick -pso 2>/dev/null"
else
command="xcolor --preview-size ${size} --scale ${scale}"
2022-04-24 18:43:34 +02:00
fi
color="$(${command})"
if [ -n "${color}" ]; then
2021-10-09 00:21:44 +02:00
echo "$color " > "$RECENT".tmp
# add on top deduplicate
awk '!x[$0]++' "$RECENT" >> "$RECENT".tmp
awk '!x[$0]++' "$RECENT".tmp > "$RECENT"
[ -n "$1" ] && file="$1"
echo "$color " >> "$file"
setvar expose=picked
fi
$ME
}
2021-10-28 22:31:59 +02:00
addcolor() {
2021-10-28 21:26:47 +02:00
color=$(gcolor3)
if [ -n "${color}" ]; then
echo "$color " > "$RECENT".tmp
# add on top deduplicate
awk '!x[$0]++' "$RECENT" >> "$RECENT".tmp
awk '!x[$0]++' "$RECENT".tmp > "$RECENT"
[ -n "$1" ] && file="$1"
echo "$color " >> "$file"
setvar expose=picked
fi
2021-10-09 00:21:44 +02:00
$ME
}
getcolorcode() {
if [ $action = "paste" ];then
case "$format" in
rgb) clr=$(hex2rgb $1);xdotool type --delay 0 "$clr";;
rgba) clr=$(hex2rgba $1);xdotool type --delay 0 "$clr";;
*) xdotool type --delay 0 "$1";;
esac
2021-10-29 02:00:19 +02:00
else # copy to clipboard
2021-10-09 00:21:44 +02:00
case "$format" in
rgb) clr=$(hex2rgb $1);echo $clr | tr -d "\n" | xclip -sel c;;
rgba) clr=$(hex2rgba $1);echo $clr | tr -d "\n" | xclip -sel c;;
*) clr="$1";echo "$1" | tr -d "\n" | xclip -sel c;;
2021-10-09 00:21:44 +02:00
esac
mkdir -p $TEMP_DIR
2021-10-29 11:38:53 +02:00
FNAME="$TEMP_DIR/${1:1:6}.png"
convert -size 100x100 xc:"$1" "$FNAME"
2022-04-24 18:43:34 +02:00
notify-send ColorMenu "$clr copied to clipboard" --icon="$FNAME" --expire-time=120000
2021-10-09 00:21:44 +02:00
fi
echo "$1" > "$USED".tmp
# add on top and deduplicate
awk '!x[$0]++' "$USED" >> "$USED".tmp
awk '!x[$0]++' "$USED".tmp > "$USED"
[[ $2 ]] && echo "$2" > "$LASTPAL"
}
recent2palette () {
DATE=$(date +"%Y%m%d-%H%M%S")
2021-10-27 17:38:03 +02:00
mkdir -p "$CNF_DIR/palettes/my"
grep ^# $RECENT |tac > "$CNF_DIR/palettes/my/My_palette_$DATE.clr"
2022-05-24 02:06:37 +02:00
grep ^# $RECENT |pastel sort-by brightness|pastel format hex > "$CNF_DIR/palettes/my/My_palette_$DATE.clr"
2021-10-09 00:21:44 +02:00
}
newpalette() {
DATE=$(date +"%Y%m%d-%H%M%S")
2021-10-27 17:38:03 +02:00
mkdir -p "$CNF_DIR/palettes/my"
touch "$CNF_DIR/palettes/my/My_palette_$DATE.clr"
2021-10-09 00:21:44 +02:00
}
palettes() {
2021-10-29 11:38:53 +02:00
[ -n "$1" ] && pdir="$CNF_DIR/palettes/my/" || pdir="$DATA_DIR/palettes/"
if [[ -n "$1" ]]; then
out2+=("^tag(mypalettes)")
2022-04-24 18:43:34 +02:00
out2+=("^sep($MYPALETTES)")
else
out2+=("^tag(builtpalettes)")
2022-04-24 18:43:34 +02:00
out2+=("^sep($BUILTIN_PAL)")
fi
for file in "$pdir"*.clr ;do
2021-10-09 00:21:44 +02:00
filename=${file##*/}
palette=${filename%.*}
pal=${palette//_/ }
tagname=${palette// /_}
out2+=("${pal^},^checkout($tagname)")
out3+=("^tag($tagname)")
out3+=("^sep(${pal^})")
2022-04-24 18:43:34 +02:00
out3+=("$EXPOSE_IN_ROOTMENU,$ME setvar expose=$filename;$ME")
out3+=("^sep()")
2021-10-09 00:21:44 +02:00
while read -r color name;
do
out3+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt>,$ME getcolorcode '$color' '$file',,,#${palette}")
2021-10-09 00:21:44 +02:00
done < "$file"
2021-10-28 12:27:15 +02:00
if [[ -n "$1" ]] ; then
out3+=("^sep()")
out3+=("<b>Add color...</b> from screen,$ME pickcolor '$file'")
2021-10-28 21:30:12 +02:00
if hash gcolor3 2>/dev/null; then
out3+=("^sep()")
out3+=("<b>Add</b> color from selector...,$ME addcolor '$file'")
2021-10-28 12:27:15 +02:00
fi
out3+=("^sep()")
out3+=("<b>Edit</b> palette file,xdg-open '$file'")
out3+=("^sep(Danger zone...)")
out3+=("<b>Delete</b> palette: ${palette^},^checkout($tagname-del)")
out4+=("^tag($tagname-del)")
out4+=("^sep(Are you sure?)")
out4+=("Yes,rm '$file';$ME")
2021-10-28 12:27:15 +02:00
fi
2021-10-09 00:21:44 +02:00
done
2021-10-27 21:09:10 +02:00
#if [[ $# = 0 ]] ; then
if [[ -n "$1" ]] ; then
out2+=("^sep()")
out2+=("<b>Add new</b> palette...,$ME newpalette;$ME")
out2+=("Open palette directory,xdg-open $CNF_DIR/palettes/my/")
2021-10-27 17:38:03 +02:00
fi
2021-10-09 00:21:44 +02:00
}
position() {
case "$position" in
ipc) POSITION_MODE="ipc";;
pointer) POSITION_MODE="pointer";;
topleft) POSITION_MODE="fixed" MENU_VALIGN="top" MENU_HALIGN="left";;
top) POSITIOM_MODE="fixed" MENU_VALIGN="top" MENU_HALIGN="center";;
topright) POSITION_MODE="fixed" MENU_VALIGN="top" MENU_HALIGN="right";;
left) POSITION_MODE="fixed" MENU_VALIGN="center" MENU_HALIGN="left";;
right) POSITION_MODE="fixed" MENU_VALIGN="center" MENU_HALIGN="right";;
bottomleft) POSITION_MODE="fixed" MENU_VALIGN="bottom" MENU_HALIGN="left";;
bottom) POSITION_MODE="fixed" MENU_VALIGN="bottom" MENU_HALIGN="center";;
bottomright) POSITION_MODE="fixed" MENU_VALIGN="bottom" MENU_HALIGN="right";;
2022-04-24 18:43:34 +02:00
center|*) POSITION_MODE="center" MENU_VALIGN="center" MENU_HALIGN="center";;
2021-10-09 00:21:44 +02:00
esac
}
main () {
if [[ -f /usr/share/mb-jgtools/pipemenu-standalone.cfg ]];then
. /usr/share/mb-jgtools/pipemenu-standalone.cfg
. $HOME/.config/mabox/mabox.conf
fi
2022-04-24 18:43:34 +02:00
case $LANG in
pl*)
COLORMENU="Menu kolorów"
2022-04-28 14:44:58 +02:00
COPY_COLOR_CODE="Kopiuj kod koloru"
COLLECT_COLORS="Dodaj kolory"
2022-04-24 18:43:34 +02:00
PICK_FROM_SCREEN="<b>Pobierz</b> kolor z ekranu..."
ADD_FROM_SELECTOR="<b>Dodaj</b> kolor..."
LASTUSED_PAL="Ostatnio używana paleta"
RECENTLYUSED="Ostatnio użyte kolory"
RECENTLYPICKED="Ostatnio dodane kolory"
CLEAR_ALL="Usuń wszystkie"
CLEAR_ALL2="<b>Usuń</b> wszystkie"
CLEAR_RECUSED="<b>Usuń</b> ostatnio użyte kolory"
NEWPAL_FROMREC="<b>Nowa paleta</b> z ostatnio dodanych"
CLEAR_RECPICKED="<b>Usuń</b> ostatnio dodane"
REMOVEONE="Usuń tylko jeden kolor..."
WALLCOLORS="Kolory z tapety"
2022-04-25 02:58:43 +02:00
RANDWALL="Ustaw <b>losową tapetę</b>"
2022-04-24 18:43:34 +02:00
IMAGICKCOLORS="Kolory <b>Image Magick</b>"
HTMLCOLORS="Kolory <b>HTML</b>"
PALETTE="Paleta:"
COLORPALETTES="Palety kolorów"
MYPALETTES="Moje palety"
BUILTIN_PAL="Wbudowane palety"
EXPOSE_IN_ROOTMENU="Pokaż w menu głównym"
SETTINGS="Ustawienia"
PREFERENCES="Konfiguruj..."
2022-06-10 10:16:49 +02:00
HELP="Pomoc"
2022-04-24 18:43:34 +02:00
;;
*)
COLORMENU="ColorMenu"
2022-04-28 14:44:58 +02:00
COPY_COLOR_CODE="Copy Color Code"
COLLECT_COLORS="Collect Colors"
2022-04-24 18:43:34 +02:00
PICK_FROM_SCREEN="<b>Pick</b> color from screen..."
ADD_FROM_SELECTOR="<b>Add</b> color from selector..."
LASTUSED_PAL="Last used palette"
RECENTLYUSED="Recently used colors"
RECENTLYPICKED="Recently picked colors"
CLEAR_ALL="Clear All"
CLEAR_ALL2="<b>Clear</b> all"
CLEAR_RECUSED="<b>Clear</b> recently used colors"
NEWPAL_FROMREC="<b>New palette</b> from recently picked"
CLEAR_RECPICKED="<b>Clear</b> recently picked"
REMOVEONE="Just remove one color..."
WALLCOLORS="Wallpaper colors"
2022-04-25 02:58:43 +02:00
RANDWALL="Set <b>random wallpaper</b>"
2022-04-24 18:43:34 +02:00
IMAGICKCOLORS="<b>Image Magick</b> Colors"
HTMLCOLORS="<b>HTML</b> colors"
PALETTE="Palette:"
COLORPALETTES="Color palettes"
MYPALETTES="My palettes"
BUILTIN_PAL="Built-in palettes"
EXPOSE_IN_ROOTMENU="Expose in rootmenu"
SETTINGS="Settings"
PREFERENCES="Preferences"
2022-06-10 10:16:49 +02:00
HELP="About and Help"
2022-04-24 18:43:34 +02:00
;;
esac
2021-10-09 00:21:44 +02:00
[ "$1" = "ipc" ] && position="ipc"
MENU_PADDING_TOP=${jgtools_padding:-0}
JGWIDTH="220"
ITEM_HALIGN="center"
jgmenu_icon_size=0
menu_margin_x=${submenu_spacing:-0}
2021-10-10 11:56:59 +02:00
[ $(pidof picom) ] && MENU_RADIUS=$jgtools_radius
2021-10-09 00:21:44 +02:00
#jgmenu_font="Noto Sans Medium 10"
position
mkconfigfile
trap "rm -f ${CONFIG_FILE} ${MENU_ITEMS}" EXIT
2022-04-28 14:44:58 +02:00
out+=("^sep($COLORMENU)")
out+=("^sep()")
out+=("^sep($COLLECT_COLORS...)")
2022-04-24 18:43:34 +02:00
out+=("$PICK_FROM_SCREEN,$ME pickcolor")
2021-10-28 21:42:12 +02:00
if hash gcolor3 2>/dev/null; then
2021-10-28 12:27:15 +02:00
out+=("^sep()")
2022-04-24 18:43:34 +02:00
out+=("$ADD_FROM_SELECTOR,$ME addcolor")
2021-10-28 12:27:15 +02:00
fi
2022-04-28 14:44:58 +02:00
out+=("^sep($COPY_COLOR_CODE...<sup> [$action $format]</sup>)")
2021-10-09 00:21:44 +02:00
# exposed thing
case "$expose" in
palette)
pal=$(cat "$CNF_DIR/.palette")
filename=${pal##*/}
palette=${filename%.*}
2022-04-24 18:43:34 +02:00
out+=("^sep(<i><span font_weight='light'>$LASTUSED_PAL</span> ${palette^}</i>)")
2021-10-09 00:21:44 +02:00
while read -r color name;do
2021-10-27 02:39:14 +02:00
out+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt> ,$ME getcolorcode '$color'")
2021-10-09 00:21:44 +02:00
done < "${pal}"
;;
2021-10-29 11:38:53 +02:00
used)
mapfile -t < $USED
if (( ${#MAPFILE[@]} > 1 )); then
2022-04-24 18:43:34 +02:00
out+=("^sep(<i><small>$RECENTLYUSED</small></i>)")
2021-10-29 11:38:53 +02:00
while read -r color name;do
out+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt> ,$ME getcolorcode '$color'")
done < <(grep ^# $USED)
out+=("^sep()")
2022-04-24 18:43:34 +02:00
out+=("$CLEAR_RECUSED,echo > $USED;$ME")
2021-10-29 11:38:53 +02:00
fi
;;
picked)
2021-10-29 02:00:19 +02:00
mapfile -t < $RECENT
if (( ${#MAPFILE[@]} > 1 )); then
2022-04-24 18:43:34 +02:00
out+=("^sep(<i><small>$RECENTLYPICKED</small></i>)")
# for clear/delete
out2+=("^tag(pickeddel)")
2022-04-24 18:43:34 +02:00
out2+=("^sep($CLEAR_ALL)")
out2+=("$CLEAR_ALL2,echo > $RECENT;$ME")
out2+=("^sep($REMOVEONE)")
2021-10-09 00:21:44 +02:00
while read -r color name;do
2021-10-27 02:39:14 +02:00
out+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt> ,$ME getcolorcode '$color'")
out2+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt> ,sed -i '/${color:1:6}/d' $RECENT;$ME")
2021-10-09 00:21:44 +02:00
done < <(grep ^# $RECENT)
2021-10-09 00:21:44 +02:00
out+=("^sep()")
2022-04-24 18:43:34 +02:00
out+=("$NEWPAL_FROMREC,$ME recent2palette;$ME")
out+=("$CLEAR_RECPICKED,^checkout(pickeddel)")
2021-10-29 02:00:19 +02:00
fi
2021-10-09 00:21:44 +02:00
;;
wallpaper)
WALLPALDIR="$HOME/.config/mbxcolors/palettes/wallp"
mkdir -p "$WALLPALDIR"
read WALLPATH<<< $(grep file "$HOME/.config/nitrogen/bg-saved.cfg" | cut -d'=' -f2)
WALLPAPER=${WALLPATH##*/}
if [ ! -f "$WALLPALDIR/$WALLPAPER.clr" ]; then
2022-05-24 02:06:37 +02:00
convert ${WALLPATH} -resize 25% -colors 16 -unique-colors txt:- |grep -v '^#'| awk '{print substr($3,1,7)}' |pastel sort-by brightness |pastel format hex > "$WALLPALDIR/$WALLPAPER.clr"
fi
#mapfile -t wallcolors < "$WALLPALDIR/$WALLPAPER.clr"
2022-04-28 14:44:58 +02:00
out+=("^sep(<i><small>$WALLCOLORS</small></i>)")
while read -r color name;do
out+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt> ,$ME getcolorcode '$color'")
done < "$WALLPALDIR/$WALLPAPER.clr"
2022-04-25 02:58:43 +02:00
out+=("^sep()")
out+=("$RANDWALL,nitrogen --random ${RANDWALLDIR} --set-scaled --save;$ME")
;;
*)
if [ -f "$DATA_DIR/palettes/$expose" ];then
palfile="$DATA_DIR/palettes/$expose"
elif [ -f "$CNF_DIR/palettes/my/$expose" ];then
palfile="$CNF_DIR/palettes/my/$expose"
fi
if [ $palfile ];then
palette=${expose%.*}
pal=${palette//_/ }
2022-04-28 14:44:58 +02:00
out+=("^sep(<i><small>$PALETTE ${pal^}</small></i>)")
while read -r color name;
do
out+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt>,$ME getcolorcode '$color' '$file';$ME setvar expose=palette,,,#${palette}")
done < "$palfile"
fi
;;
2021-10-09 00:21:44 +02:00
esac
2021-10-27 17:38:03 +02:00
#if [[ "$CNF_DIR"/palettes/my/*.clr ]]; then
2022-04-24 18:43:34 +02:00
out+=("^sep($COLORPALETTES)")
2022-04-28 14:44:58 +02:00
if [ "$(find "$CNF_DIR"/palettes/my/*.clr -maxdepth 1 -type f -iname \*.clr 2>/dev/null)" ]; then
2022-04-24 18:43:34 +02:00
out+=("$MYPALETTES,^checkout(mypalettes)")
2021-10-27 17:38:03 +02:00
palettes my
fi
if [[ $builtin_palettes == "yes" ]];then
2022-04-24 18:43:34 +02:00
out+=("$BUILTIN_PAL,^checkout(builtpalettes)")
2021-10-09 00:21:44 +02:00
palettes
fi
# WALLPAPER COLORS
2022-04-25 02:58:43 +02:00
if [ "$expose" != "wallpaper" ];then
2022-04-24 18:43:34 +02:00
out+=("$WALLCOLORS,^checkout(wallcolors)")
read WALLPAPER<<< $(grep file "$HOME/.config/nitrogen/bg-saved.cfg | cut -d'=' -f2")
WALLPALDIR="$HOME/.config/mbxcolors/palettes/wallp"
mkdir -p "$WALLPALDIR"
read WALLPATH<<< $(grep file "$HOME/.config/nitrogen/bg-saved.cfg" | cut -d'=' -f2)
WALLPAPER=${WALLPATH##*/}
if [ ! -f "$WALLPALDIR/$WALLPAPER.clr" ]; then
2022-05-24 02:06:37 +02:00
convert ${WALLPATH} -resize 25% -colors 16 -unique-colors txt:- |grep -v '^#'| awk '{print substr($3,1,7)}' |pastel sort-by brightness |pastel format hex > "$WALLPALDIR/$WALLPAPER.clr"
fi
#mapfile -t wallcolors < "$WALLPALDIR/$WALLPAPER.clr"
out2+=("^tag(wallcolors)")
2022-04-24 18:43:34 +02:00
out2+=("^sep($WALLCOLORS)")
out2+=("$EXPOSE_IN_ROOTMENU ,$ME setvar expose=wallpaper;$ME")
2022-04-22 19:48:31 +02:00
out2+=("^sep()")
while read -r color name;do
out2+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt> ,$ME getcolorcode '$color'")
done < "$WALLPALDIR/$WALLPAPER.clr"
2022-04-25 02:58:43 +02:00
out2+=("^sep()")
2022-05-24 02:06:37 +02:00
out2+=("$RANDWALL,nitrogen --random ${RANDWALLDIR} --set-scaled --save;$ME setvar expose=wallpaper;$ME")
2022-04-25 02:58:43 +02:00
fi
2022-04-24 18:43:34 +02:00
out1+=("$IMAGICKCOLORS,mbxcolors imagick")
2022-04-28 14:44:58 +02:00
2022-04-24 18:43:34 +02:00
out1+=("^sep($SETTINGS)")
out1+=("$PREFERENCES,^pipe($ME preferences)")
2022-06-10 10:16:49 +02:00
2022-04-22 02:17:44 +02:00
out1+=("^sep()")
2022-06-10 10:16:49 +02:00
LNG=${LANG:0:2}
if [[ -f "/usr/share/mbxcolors/help/$LNG.html" ]];then
out1+=("$HELP,yhtml /usr/share/mbxcolors/help/$LNG.html 'Mabox Help - ColorMenu'")
else
out1+=("$HELP,yhtml /usr/share/mbxcolors/help/en.html 'Mabox Help - ColorMenu'")
fi
2022-04-24 18:43:34 +02:00
if [ $htmlcolors = "yes" ]; then
htmlroot="^sep()
${HTMLCOLORS},^checkout(html)
"
htmlsub="^tag(html)
. ${DATA_DIR}/htmlsub.csv"
htmlclrs=". ${DATA_DIR}/htmlclrs.csv"
else
htmlroot="" htmlsub="" htmlclrs=""
fi
2021-10-09 00:21:44 +02:00
cat << EOF > ${MENU_ITEMS}
$(printf '%s\n' "${out[@]}")
${htmlroot}
$(printf '%s\n' "${out1[@]}")
${htmlsub}
$(printf '%s\n' "${out2[@]}")
${htmlclrs}
$(printf '%s\n' "${out3[@]}")
$(printf '%s\n' "${out4[@]}")
2021-10-09 00:21:44 +02:00
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
#printf '%s\n' "${out3[@]}"
exit 0
}
2021-10-29 02:00:19 +02:00
imagick() {
2022-04-24 18:43:34 +02:00
if [[ -f /usr/share/mb-jgtools/pipemenu-standalone.cfg ]];then
. /usr/share/mb-jgtools/pipemenu-standalone.cfg
. $HOME/.config/mabox/mabox.conf
fi
case $LANG in
pl*) TYPE_TO_SEARCH="pisz aby wyszukać"
IMAGICKCOLORS="Kolory Image Magick"
BACK="Wróć do Menu Kolorów"
;;
*) TYPE_TO_SEARCH="type to search"
IMAGICKCOLORS="Image Magick Colors"
BACK="Back to ColorMenu"
;;
esac
#MENU_PADDING_TOP=${jgtools_padding:-24}
2022-05-01 17:32:05 +02:00
MENU_PADDING_TOP=$((jgtools_padding+24))
2022-04-24 18:43:34 +02:00
JGWIDTH="300"
ITEM_HALIGN="center"
jgmenu_icon_size=0
menu_margin_x=${submenu_spacing:-0}
[ $(pidof picom) ] && MENU_RADIUS=$jgtools_radius
jgmenu_font="Noto Sans Medium 12"
MENU_HALIGN="center"
MENU_VALIGN="center"
TABS="280"
icons=0
iconmargin=0
item_height_factor=240
MENU_HEIGHT_MAX=480
mkconfigfile
trap "rm -f ${CONFIG_FILE} ${MENU_ITEMS}" EXIT
out+=("^sep($IMAGICKCOLORS)")
out+=("$BACK,mbxcolors")
out+=("^sep()")
while read -r color name;do
out+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span> $name</tt> ,$ME getcolorcode '$color'")
done < "$DATA_DIR/imagick.txt"
cat << EOF > ${MENU_ITEMS}
2022-05-01 17:32:05 +02:00
@search,,$((jgtools_padding + 32)),$((jgtools_padding + 4)),292,20,4,left,top,auto,#262626,"""<big></big> <i>$TYPE_TO_SEARCH</i>"""
2022-04-24 18:43:34 +02:00
$(printf '%s\n' "${out[@]}")
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
2021-10-29 02:00:19 +02:00
}
2021-10-09 00:21:44 +02:00
preferences() {
2022-04-24 18:43:34 +02:00
case $LANG in
pl*)
SETTINGS="Ustawienia"
CLICK_ACTION="Akcja po kliknięciu w kolor:"
EXPOSE="Pokaż w menu głównym:"
HTMLCOLORS="Kolory HTML:"
HTML="Pokaż kolory HTML?"
BUILTIN="Wbudowane palety:"
BUILT="Pokaż wbudowane palety?"
PICKER="Pobieranie kolorów z ekranu:"
POSITION="Pozycja:"
RESET="Zresetuj ustawienia"
EDIT_CONF="Edytuj plik konfiguracyjny"
OPEN_DIR="Otwórz katalog z konfiguracją"
OUTFORMAT="Format wyjściowy"
PASTE="<b>paste</b> (wklej natychmiast)"
COPY="<b>copy</b> (kopiuj do schowka)"
SHOW_IN_ROOT="Pokazuj w menu głównym"
PICKED="<b>picked</b> ostatnio dodane kolory"
USED="<b>used</b> ostatnio użyte kolory"
PALETTE="<b>palette</b> ostatnio użyta paleta"
WALLPAPER="<b>wallpaper</b> kolory z tapety"
COLORPICKER="Pobieracz kolorów"
POS="Pozycja na ekranie"
;;
*)
SETTINGS="Settings"
CLICK_ACTION="Color click action:"
EXPOSE="Expose in rootmenu:"
HTMLCOLORS="HTML colors:"
HTML="Show HTML colors?"
BUILTIN="Built-in palettes:"
BUILT="Show Built-in palettes?"
PICKER="Color picker:"
POSITION="Position:"
RESET="Reset to defaults"
EDIT_CONF="Edit config file"
OPEN_DIR="Open config directory"
OUTFORMAT="Output format"
PASTE="<b>paste</b> (paste color immediately)"
COPY="<b>copy</b> (copy color to clipboard)"
SHOW_IN_ROOT="Show on top of rootmenu"
PICKED="<b>picked</b> recently picked colors"
USED="<b>used</b> recently used colors"
PALETTE="<b>palette</b> recently used palette"
WALLPAPER="<b>wallpaper</b> colors"
COLORPICKER="Color Picker"
POS="Position on screen"
;;
esac
2021-10-09 00:21:44 +02:00
2022-04-24 18:43:34 +02:00
out2+=("^sep($SETTINGS)")
out2+=("<tt>$(printf "%-20s %20s" "$CLICK_ACTION" "[<b>$action</b>]")</tt>,^checkout(action)")
2021-10-09 00:21:44 +02:00
out2+=("<tt>$(printf "%-20s %20s" "Format:" "[<b>$format</b>]")</tt>,^checkout(format)")
out2+=("^sep()")
2022-04-24 18:43:34 +02:00
out2+=("<tt>$(printf "%-20s %20s" "$EXPOSE" "[<b>$expose</b>]")</tt>,^checkout(expose)")
out2+=("<tt>$(printf "%-20s %20s" "$HTMLCOLORS:" "[<b>$htmlcolors</b>]")</tt>,^checkout(showhtml)")
out2+=("<tt>$(printf "%-20s %20s" "$BUILTIN" "[<b>$builtin_palettes</b>]")</tt>,^checkout(builtinpalettes)")
out2+=("<tt>$(printf "%-20s %20s" "$PICKER" "[<b>$picker</b>]")</tt>,^checkout(picker)")
2021-10-09 00:21:44 +02:00
out2+=("^sep()")
2022-04-24 18:43:34 +02:00
out2+=("<tt>$(printf "%-20s %20s" "$POSITION" "[<b>$position</b>]")</tt>,^checkout(position)")
2021-10-09 00:21:44 +02:00
out2+=("^sep()")
2022-04-24 18:43:34 +02:00
out2+=("$RESET,rm $CNF_FILE;$ME")
2021-10-09 00:21:44 +02:00
out2+=("^sep()")
2022-04-24 18:43:34 +02:00
out2+=("$EDIT_CONF,xdg-open $CNF_FILE")
out2+=("$OPEN_DIR,xdg-open $CNF_DIR")
2021-10-09 00:21:44 +02:00
out2+=("^tag(format)")
2022-04-24 18:43:34 +02:00
out2+=("^sep($OUTFORMAT)")
2021-10-09 00:21:44 +02:00
out2+=("<b>hex</b> <i>#579C8E</i>,$ME setvar format=hex;$ME")
out2+=("<b>rgb</b> <i>rgb(87&#44; 156&#44; 142)</i>,$ME setvar format=rgb;$ME")
out2+=("<b>rgba</b> <i>rgba(87&#44; 156&#44; 142&#44; 1.0)</i>,$ME setvar format=rgba;$ME")
out2+=("^tag(action)")
2022-04-24 18:43:34 +02:00
out2+=("^sep($CLICK_ACTION)")
out2+=("$PASTE,$ME setvar action=paste;$ME")
out2+=("$COPY,$ME setvar action=copy;$ME")
2021-10-09 00:21:44 +02:00
out2+=("^tag(expose)")
2022-04-24 18:43:34 +02:00
out2+=("^sep($SHOW_IN_ROOT)")
out2+=("$PICKED,$ME setvar expose=picked;$ME")
out2+=("$USED,$ME setvar expose=used;$ME")
out2+=("$PALETTE,$ME setvar expose=palette;$ME")
out2+=("$WALLPAPER,$ME setvar expose=wallpaper;$ME")
2021-10-09 00:21:44 +02:00
out2+=("^tag(showhtml)")
2022-04-24 18:43:34 +02:00
out2+=("^sep($HTML)")
2021-10-09 00:21:44 +02:00
out2+=("yes,$ME setvar htmlcolors=yes;$ME")
out2+=("no,$ME setvar htmlcolors=no;$ME")
out2+=("^tag(builtinpalettes)")
2022-04-24 18:43:34 +02:00
out2+=("^sep($BUILT)")
out2+=("yes,$ME setvar builtin_palettes=yes;$ME")
out2+=("no,$ME setvar builtin_palettes=no;$ME")
2022-04-24 18:43:34 +02:00
out2+=("^tag(picker)")
out2+=("^sep($COLORPICKER)")
out2+=("gpick,$ME setvar picker=gpick;$ME")
out2+=("xcolor,$ME setvar picker=xcolor;$ME")
2021-10-09 00:21:44 +02:00
out2+=("^tag(position)")
2022-04-24 18:43:34 +02:00
out2+=("^sep($POS)")
2021-10-09 00:21:44 +02:00
out2+=("center,$ME setvar position=center;$ME")
out2+=("topleft,$ME setvar position=topleft;$ME")
out2+=("top,$ME setvar position=top;$ME")
out2+=("topright,$ME setvar position=topright;$ME")
out2+=("left,$ME setvar position=left;$ME")
out2+=("right,$ME setvar position=right;$ME")
out2+=("bottomleft,$ME setvar position=bottomleft;$ME")
out2+=("bottom,$ME setvar position=bottom;$ME")
out2+=("bottomright,$ME setvar position=bottomright;$ME")
printf '%s\n' "${out2[@]}"
}
setvar() {
search=$(echo $1|cut -d= -f1)
FILE=${CNF_FILE}
if grep -Rq $search $FILE
then #found
sed -i s/^"$search".*$/"$1"/ $FILE
else #not found
echo $1 >> $FILE
fi
}
case "$1" in
-h|--help|help) usage;;
--pickcolor|pickcolor) pickcolor "$2";;
--addcolor|addcolor) addcolor "$2" ;;
2021-10-09 00:21:44 +02:00
-g|--getcolorcode|getcolorcode) getcolorcode "$2" "$3";;
-p|preferences) preferences;;
-s|setvar) setvar "$2";;
ipc) main "$1";;
recent2palette) recent2palette ;;
newpalette) newpalette;;
2021-10-29 02:00:19 +02:00
imagick) imagick;;
2021-10-09 00:21:44 +02:00
*) main;;
esac
exit 0