big update :)

master 0.9.0
Daniel Napora 2022-04-24 18:43:34 +02:00
parent 5cb3025154
commit a0fa13432d
3 changed files with 241 additions and 68 deletions

View File

@ -5,7 +5,7 @@
# TODO export to .gpl (GIMP,Inkscape)
# TODO PL translation
VERSION="0.3.1"
VERSION="0.9.0"
TEMP_DIR=/tmp/colormenu
ME=${0##*/}
@ -26,6 +26,8 @@ action=copy
expose=picked
#Show HTML colors? yes|no
htmlcolors=yes
#Color picker (gpick or xcolor)
picker=gpick
#Show built in palettes? (slow)
builtin_palettes=yes
#Position on screen: topleft, top, topright, left, center, right, bottomleft, bottom, bottomright
@ -56,11 +58,14 @@ hex2rgba() {
echo "rgba($r, $g, $b, 1.0)"
}
pickcolor() {
#color=$(colorpicker --short --one-shot --preview)
#color=$(xcolor --preview-size "${preview-size:-255}" --scale "${scale:-8}")
size=${xcolor_preview_size:-255}
scale=${xcolor_scale:-8}
picker=${picker:-gpick}
if [ "$picker" == "gpick" ]; then
command="gpick -pso 2>/dev/null"
else
command="xcolor --preview-size ${size} --scale ${scale}"
fi
color="$(${command})"
if [ -n "${color}" ]; then
echo "$color " > "$RECENT".tmp
@ -103,7 +108,7 @@ getcolorcode() {
mkdir -p $TEMP_DIR
FNAME="$TEMP_DIR/${1:1:6}.png"
convert -size 100x100 xc:"$1" "$FNAME"
notify-send ColorMenu "$clr" --icon="$FNAME" --expire-time=120000
notify-send ColorMenu "$clr copied to clipboard" --icon="$FNAME" --expire-time=120000
fi
echo "$1" > "$USED".tmp
# add on top and deduplicate
@ -126,10 +131,10 @@ palettes() {
[ -n "$1" ] && pdir="$CNF_DIR/palettes/my/" || pdir="$DATA_DIR/palettes/"
if [[ -n "$1" ]]; then
out2+=("^tag(mypalettes)")
out2+=("^sep(My palettes)")
out2+=("^sep($MYPALETTES)")
else
out2+=("^tag(builtpalettes)")
out2+=("^sep(Built-in palettes)")
out2+=("^sep($BUILTIN_PAL)")
fi
for file in "$pdir"*.clr ;do
filename=${file##*/}
@ -139,7 +144,7 @@ palettes() {
out2+=("${pal^},^checkout($tagname)")
out3+=("^tag($tagname)")
out3+=("^sep(${pal^})")
out3+=("EXPOSE_IN_ROOTMENU,$ME setvar expose=$filename;$ME")
out3+=("$EXPOSE_IN_ROOTMENU,$ME setvar expose=$filename;$ME")
out3+=("^sep()")
while read -r color name;
do
@ -169,16 +174,6 @@ palettes() {
fi
}
if [ $htmlcolors = "yes" ]; then
htmlroot="^sep()
<b>HTML</b> colors,^checkout(html)
"
htmlsub="^tag(html)
. ${DATA_DIR}/htmlsub.csv"
htmlclrs=". ${DATA_DIR}/htmlclrs.csv"
else
htmlroot="" htmlsub="" htmlclrs=""
fi
position() {
case "$position" in
ipc) POSITION_MODE="ipc";;
@ -191,17 +186,67 @@ position() {
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";;
center|*) POSITION_MODE="center";;
center|*) POSITION_MODE="center" MENU_VALIGN="center" MENU_HALIGN="center";;
esac
}
main () {
# Mabox Linux
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*)
COLORMENU="Menu kolorów"
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"
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..."
QUIT="Wyjdź"
;;
*)
COLORMENU="ColorMenu"
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"
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"
QUIT="Quit"
;;
esac
[ "$1" = "ipc" ] && position="ipc"
MENU_PADDING_TOP=${jgtools_padding:-0}
@ -213,16 +258,15 @@ menu_margin_x=${submenu_spacing:-0}
#jgmenu_font="Noto Sans Medium 10"
position
mkconfigfile
trap "rm -f ${CONFIG_FILE} ${MENU_ITEMS}" EXIT
out+=("^sep(ColorMenu <sup><span font_weight='light'> [$action $format]</span></sup>)")
out+=("^sep($COLORMENU <sup><span font_weight='light'> [$action $format]</span></sup>)")
#out+=("^sep(<span bgcolor='#800000'> </span><span fgcolor='#800000' bgcolor='#FABD2F'> mbx </span><span fgcolor='#FABD2F' bgcolor='#800000'> colors </span><span bgcolor='#FABD2F'> </span> <sup><span font_weight='light'>[$action $format]</span></sup>)")
out+=("<b>Pick</b> color from screen...,$ME pickcolor")
out+=("$PICK_FROM_SCREEN,$ME pickcolor")
if hash gcolor3 2>/dev/null; then
out+=("^sep()")
out+=("<b>Add</b> color from selector...,$ME addcolor")
out+=("$ADD_FROM_SELECTOR,$ME addcolor")
fi
# exposed thing
case "$expose" in
@ -230,7 +274,7 @@ case "$expose" in
pal=$(cat "$CNF_DIR/.palette")
filename=${pal##*/}
palette=${filename%.*}
out+=("^sep(<i><span font_weight='light'>Last used palette</span> ${palette^}</i>)")
out+=("^sep(<i><span font_weight='light'>$LASTUSED_PAL</span> ${palette^}</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 < "${pal}"
@ -238,23 +282,23 @@ case "$expose" in
used)
mapfile -t < $USED
if (( ${#MAPFILE[@]} > 1 )); then
out+=("^sep(<i><small>Recently used colors:</small></i>)")
out+=("^sep(<i><small>$RECENTLYUSED</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 < <(grep ^# $USED)
out+=("^sep()")
out+=("<b>Clear</b> recently used colors,echo > $USED;$ME")
out+=("$CLEAR_RECUSED,echo > $USED;$ME")
fi
;;
picked)
mapfile -t < $RECENT
if (( ${#MAPFILE[@]} > 1 )); then
out+=("^sep(<i><small>Recently picked colors:</small></i>)")
out+=("^sep(<i><small>$RECENTLYPICKED</small></i>)")
# for clear/delete
out2+=("^tag(pickeddel)")
out2+=("^sep(Clear All)")
out2+=("<b>Clear</b> all,echo > $RECENT;$ME")
out2+=("^sep(Just remove one color...)")
out2+=("^sep($CLEAR_ALL)")
out2+=("$CLEAR_ALL2,echo > $RECENT;$ME")
out2+=("^sep($REMOVEONE)")
while read -r color name;do
out+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt> ,$ME getcolorcode '$color'")
@ -262,8 +306,8 @@ case "$expose" in
done < <(grep ^# $RECENT)
out+=("^sep()")
out+=("<b>New palette</b> from recently picked,$ME recent2palette;$ME")
out+=("<b>Clear</b> recently picked,^checkout(pickeddel)")
out+=("$NEWPAL_FROMREC,$ME recent2palette;$ME")
out+=("$CLEAR_RECPICKED,^checkout(pickeddel)")
fi
;;
wallpaper)
@ -276,7 +320,7 @@ case "$expose" in
convert ${WALLPATH} -resize 25% -colors 16 -unique-colors txt:- |grep -v '^#'| awk '{print $3}' > "$WALLPALDIR/$WALLPAPER.clr"
fi
#mapfile -t wallcolors < "$WALLPALDIR/$WALLPAPER.clr"
out+=("^sep(Wallpaper colors)")
out+=("^sep($WALLCOLORS)")
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"
@ -290,7 +334,7 @@ case "$expose" in
if [ $palfile ];then
palette=${expose%.*}
pal=${palette//_/ }
out+=("^sep(Palette: ${pal^})")
out+=("^sep($PALETTE ${pal^})")
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}")
@ -300,17 +344,17 @@ case "$expose" in
esac
#if [[ "$CNF_DIR"/palettes/my/*.clr ]]; then
out+=("^sep(Color palettes)")
out+=("^sep($COLORPALETTES)")
if [ "$(find "$CNF_DIR"/palettes/my/*.clr -maxdepth 1 -type f -iname \*.clr)" ]; then
out+=("My palettes,^checkout(mypalettes)")
out+=("$MYPALETTES,^checkout(mypalettes)")
palettes my
fi
if [[ $builtin_palettes == "yes" ]];then
out+=("Built-in palettes,^checkout(builtpalettes)")
out+=("$BUILTIN_PAL,^checkout(builtpalettes)")
palettes
fi
# WALLPAPER COLORS
out+=("Current Wallpaper colors,^checkout(wallcolors)")
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"
@ -321,17 +365,29 @@ if [ ! -f "$WALLPALDIR/$WALLPAPER.clr" ]; then
fi
#mapfile -t wallcolors < "$WALLPALDIR/$WALLPAPER.clr"
out2+=("^tag(wallcolors)")
out2+=("^sep(Current wallpaper colors)")
out2+=("EXPOSE_IN_ROOTMENU ,$ME setvar expose=wallpaper;$ME")
out2+=("^sep($WALLCOLORS)")
out2+=("$EXPOSE_IN_ROOTMENU ,$ME setvar expose=wallpaper;$ME")
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"
out1+=("^sep(Settings)")
out1+=("Preferences,^pipe($ME preferences)")
out1+=("$IMAGICKCOLORS,mbxcolors imagick")
out1+=("^sep($SETTINGS)")
out1+=("$PREFERENCES,^pipe($ME preferences)")
out1+=("^sep()")
out1+=("QUIT,^quit()")
out1+=("$QUIT,^quit()")
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
cat << EOF > ${MENU_ITEMS}
$(printf '%s\n' "${out[@]}")
@ -351,55 +407,158 @@ exit 0
}
imagick() {
echo "not implemented"
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}
MENU_PADDING_TOP=$((jgtools_padding+12))
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}
@search,,25,15,292,20,4,left,top,auto,#262626,"""<big></big> <i>$TYPE_TO_SEARCH</i>"""
$(printf '%s\n' "${out[@]}")
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
}
preferences() {
out2+=("^sep(Settings)")
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
out2+=("<tt>$(printf "%-20s %20s" "Color click action:" "[<b>$action</b>]")</tt>,^checkout(action)")
out2+=("^sep($SETTINGS)")
out2+=("<tt>$(printf "%-20s %20s" "$CLICK_ACTION" "[<b>$action</b>]")</tt>,^checkout(action)")
out2+=("<tt>$(printf "%-20s %20s" "Format:" "[<b>$format</b>]")</tt>,^checkout(format)")
out2+=("^sep()")
out2+=("<tt>$(printf "%-20s %20s" "Expose on top:" "[<b>$expose</b>]")</tt>,^checkout(expose)")
out2+=("<tt>$(printf "%-20s %20s" "HTML colors:" "[<b>$htmlcolors</b>]")</tt>,^checkout(showhtml)")
out2+=("<tt>$(printf "%-20s %20s" "Built-in palettes:" "[<b>$builtin_palettes</b>]")</tt>,^checkout(builtinpalettes)")
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)")
out2+=("^sep()")
out2+=("<tt>$(printf "%-20s %20s" "Position:" "[<b>$position</b>]")</tt>,^checkout(position)")
out2+=("<tt>$(printf "%-20s %20s" "$POSITION" "[<b>$position</b>]")</tt>,^checkout(position)")
out2+=("^sep()")
out2+=("Reset to defaults,rm $CNF_FILE;$ME")
out2+=("$RESET,rm $CNF_FILE;$ME")
out2+=("^sep()")
out2+=("Edit config file,xdg-open $CNF_FILE")
out2+=("Open config directory,xdg-open $CNF_DIR")
out2+=("$EDIT_CONF,xdg-open $CNF_FILE")
out2+=("$OPEN_DIR,xdg-open $CNF_DIR")
out2+=("^tag(format)")
out2+=("^sep(Output format)")
out2+=("^sep($OUTFORMAT)")
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)")
out2+=("^sep(Color action)")
out2+=("<b>paste</b> (paste color immediately),$ME setvar action=paste;$ME")
out2+=("<b>copy</b> (copy color to clipboard),$ME setvar action=copy;$ME")
out2+=("^sep($CLICK_ACTION)")
out2+=("$PASTE,$ME setvar action=paste;$ME")
out2+=("$COPY,$ME setvar action=copy;$ME")
out2+=("^tag(expose)")
out2+=("^sep(Show on top of rootmenu)")
out2+=("<b>picked</b> recently picked colors,$ME setvar expose=picked;$ME")
out2+=("<b>used</b> recently used colors,$ME setvar expose=used;$ME")
out2+=("<b>palette</b> recently used palette,$ME setvar expose=palette;$ME")
out2+=("<b>wallpaper</b> colors ,$ME setvar expose=wallpaper;$ME")
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")
out2+=("^tag(showhtml)")
out2+=("^sep(Show HTML colors?)")
out2+=("^sep($HTML)")
out2+=("yes,$ME setvar htmlcolors=yes;$ME")
out2+=("no,$ME setvar htmlcolors=no;$ME")
out2+=("^tag(builtinpalettes)")
out2+=("^sep(Show Built-in palettes?)")
out2+=("^sep($BUILT)")
out2+=("yes,$ME setvar builtin_palettes=yes;$ME")
out2+=("no,$ME setvar builtin_palettes=no;$ME")
out2+=("^tag(picker)")
out2+=("^sep($COLORPICKER)")
out2+=("gpick,$ME setvar picker=gpick;$ME")
out2+=("xcolor,$ME setvar picker=xcolor;$ME")
out2+=("^tag(position)")
out2+=("^sep(Position on screen)")
out2+=("^sep($POS)")
out2+=("center,$ME setvar position=center;$ME")
out2+=("topleft,$ME setvar position=topleft;$ME")
out2+=("top,$ME setvar position=top;$ME")

View File

@ -0,0 +1,13 @@
[Desktop Entry]
Version=1.0
Type=Application
Name=Image Magick colors
Name[pl]=Kolory Image Magick
Comment=Image Magick colors picker
Keywords=
StartupNotify=false
Icon=mbxcolors
TryExec=mbxcolors imagick
Exec=mbxcolors imagick
Categories=Graphics;
#NoDisplay=true

View File

@ -1,7 +1,8 @@
[Desktop Entry]
Version=1.0
Type=Application
Name=MBX Colors
Name=ColorMenu
Name[pl]=Menu Kolorów
Comment=Pick, paste and manage colors
Keywords=
StartupNotify=false