parent
a3cd3a96d2
commit
bd1fb9ed40
206
bin/mbxcolors
206
bin/mbxcolors
|
@ -3,10 +3,9 @@
|
|||
# Dependencies: jgmenu, xdotool, xcolor, gcolor3, xdg-utils, xclip, notify-send
|
||||
# TODO Imagick colors - separate menu big around 700 named colors
|
||||
# TODO export to .gpl (GIMP,Inkscape)
|
||||
# TODO Current Wallpaper palette
|
||||
# TODO PL translation
|
||||
|
||||
VERSION="0.2.6"
|
||||
VERSION="0.3.0"
|
||||
TEMP_DIR=/tmp/colormenu
|
||||
ME=${0##*/}
|
||||
|
||||
|
@ -26,9 +25,9 @@ action=copy
|
|||
#What thing to expose on top of main menu: recently picked colors, last used colors or last used palette
|
||||
expose=picked
|
||||
#Show HTML colors? yes|no
|
||||
htmlcolors=no
|
||||
htmlcolors=yes
|
||||
#Show built in palettes? (slow)
|
||||
builtin_palettes=no
|
||||
builtin_palettes=yes
|
||||
#Position on screen: topleft, top, topright, left, center, right, bottomleft, bottom, bottomright
|
||||
position=left
|
||||
EOF
|
||||
|
@ -125,46 +124,52 @@ newpalette() {
|
|||
}
|
||||
palettes() {
|
||||
[ -n "$1" ] && pdir="$CNF_DIR/palettes/my/" || pdir="$DATA_DIR/palettes/"
|
||||
for file in "$pdir"*.clr;do
|
||||
if [[ -n "$1" ]]; then
|
||||
out2+=("^tag(mypalettes)")
|
||||
out2+=("^sep(My palettes)")
|
||||
else
|
||||
out2+=("^tag(builtpalettes)")
|
||||
out2+=("^sep(Built-in palettes)")
|
||||
fi
|
||||
for file in "$pdir"*.clr ;do
|
||||
filename=${file##*/}
|
||||
palette=${filename%.*}
|
||||
pal=${palette//_/ }
|
||||
tagname=${palette// /_}
|
||||
out1+=("${pal^},^checkout($tagname)")
|
||||
out2+=("^tag($tagname)")
|
||||
out2+=("^sep(${pal^})")
|
||||
out2+=("${pal^},^checkout($tagname)")
|
||||
out3+=("^tag($tagname)")
|
||||
out3+=("^sep(${pal^})")
|
||||
out3+=("EXPOSE_ON_ROOTMENU,$ME setvar expose=$filename;$ME")
|
||||
out3+=("^sep()")
|
||||
while read -r color name;
|
||||
do
|
||||
#name=$(printf "%22s %s\n" "$name")
|
||||
#fg=$(fgcolor $color)
|
||||
#out2+=("<tt><span bgcolor='$color' fgcolor='$fg'><sub> </sub>$color<sup>$name </sup></span></tt>,$ME getcolorcode '$color' '$file',,,#${palette}")
|
||||
out2+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt>,$ME getcolorcode '$color' '$file';$ME setvar expose=palette,,,#${palette}")
|
||||
out3+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt>,$ME getcolorcode '$color' '$file',,,#${palette}")
|
||||
done < "$file"
|
||||
if [[ -n "$1" ]] ; then
|
||||
out2+=("^sep()")
|
||||
out2+=("<b>Add color...</b> from screen,$ME pickcolor '$file'")
|
||||
out3+=("^sep()")
|
||||
out3+=("<b>Add color...</b> from screen,$ME pickcolor '$file'")
|
||||
if hash gcolor3 2>/dev/null; then
|
||||
out2+=("^sep()")
|
||||
out2+=("<b>Add</b> color from selector...,$ME addcolor '$file'")
|
||||
out3+=("^sep()")
|
||||
out3+=("<b>Add</b> color from selector...,$ME addcolor '$file'")
|
||||
fi
|
||||
out2+=("^sep()")
|
||||
out2+=("<b>Edit</b> palette file,xdg-open '$file'")
|
||||
out2+=("^sep(Danger zone...)")
|
||||
out2+=("<b>Delete</b> palette: ${palette^},^checkout($tagname-del)")
|
||||
out3+=("^tag($tagname-del)")
|
||||
out3+=("^sep(Are you sure?)")
|
||||
out3+=("Yes,rm '$file';$ME")
|
||||
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")
|
||||
fi
|
||||
done
|
||||
#if [[ $# = 0 ]] ; then
|
||||
if [[ -n "$1" ]] ; then
|
||||
out1+=("^sep()")
|
||||
out1+=("<b>Add new</b> palette...,$ME newpalette;$ME")
|
||||
out1+=("Open palette directory,xdg-open $CNF_DIR/palettes/my/")
|
||||
out2+=("^sep()")
|
||||
out2+=("<b>Add new</b> palette...,$ME newpalette;$ME")
|
||||
out2+=("Open palette directory,xdg-open $CNF_DIR/palettes/my/")
|
||||
fi
|
||||
}
|
||||
|
||||
if [ $htmlcolors = "yes" ] && [ $expose != "html" ]; then
|
||||
if [ $htmlcolors = "yes" ]; then
|
||||
htmlroot="^sep()
|
||||
<b>HTML</b> colors,^checkout(html)
|
||||
"
|
||||
|
@ -189,76 +194,7 @@ position() {
|
|||
center|*) POSITION_MODE="center";;
|
||||
esac
|
||||
}
|
||||
mkconfigfile() {
|
||||
if [[ -f /usr/share/mbxtools/configure.inc ]];then
|
||||
. /usr/share/mbxtools/configure.inc
|
||||
elif [[ -f /usr/share/mb-jgtools/pipemenu-standalone.cfg ]];then
|
||||
. /usr/share/mb-jgtools/pipemenu-standalone.cfg
|
||||
. $HOME/.config/mabox/mabox.conf
|
||||
else
|
||||
MENU_ITEMS=$(mktemp)
|
||||
CONFIG_FILE=$(mktemp)
|
||||
cat <<EOF > ${CONFIG_FILE}
|
||||
position_mode = ${POSITION_MODE:-center}
|
||||
menu_halign = ${MENU_HALIGN:-center}
|
||||
menu_valign = ${MENU_VALIGN:-center}
|
||||
|
||||
csv_cmd = apps
|
||||
stay_alive = 0
|
||||
hide_back_items = ${HIDE_BACK_ITEMS:-0}
|
||||
terminal_exec = terminator
|
||||
terminal_args = -e
|
||||
tabs = ${TABS:-220}
|
||||
menu_border = ${jgtools_border:-0}
|
||||
|
||||
# MENU MARGIN
|
||||
menu_margin_x = ${menu_margin_x:-0}
|
||||
menu_margin_y = ${panels_topmargin:-0}
|
||||
sub_spacing = ${submenu_spacing:-2}
|
||||
|
||||
menu_width = $JGWIDTH
|
||||
menu_height_min = ${MENU_HEIGHT_MIN:-0}
|
||||
menu_height_max = ${MENU_HEIGHT_MAX:-0}
|
||||
menu_padding_top = ${MENU_PADDING_TOP:-70}
|
||||
menu_padding_right = ${jgtools_padding:-0}
|
||||
menu_padding_bottom = ${jgtools_padding:-0}
|
||||
menu_padding_left = ${jgtools_padding:-0}
|
||||
menu_radius = ${MENU_RADIUS:-0}
|
||||
|
||||
#item_height = ${jgmenu_item_height:-30}
|
||||
#item_halign = ${ITEM_HALIGN:-left}
|
||||
#item_padding_x = 4
|
||||
|
||||
#item_margin_x = ${item_margin_x:-0}
|
||||
item_margin_y = ${item_margin_y:-0}
|
||||
#item_radius = ${item_radius:-2}
|
||||
#item_border = ${item_border:-0}
|
||||
|
||||
columns = ${COLUMNS:-1}
|
||||
menu_gradient_pos = ${menu_gradient_pos:- none}
|
||||
#color_menu_bg = ${color_menu_bg:-#222222 80}
|
||||
#color_menu_bg_to = ${color_menu_bg_to:- #000000 100}
|
||||
#color_menu_border = ${color_menu_border:-#2f9b85 100}
|
||||
#color_norm_bg = ${color_norm_bg:-#000000 0}
|
||||
#color_norm_fg = ${color_norm_fg:-#CCCCCC 100}
|
||||
#color_sel_bg = ${color_sel_bg:-#169f6f 60}
|
||||
#color_sel_fg = ${color_sel_fg:-#f8f8f8 100}
|
||||
#color_sel_border = ${color_sel_border:-#504e65 100}
|
||||
#color_sep_fg = ${color_sep_fg:-#4D4D4D 100}
|
||||
#color_sep_bg = ${color_sep_bg:-#262626 100}
|
||||
#color_title_fg = ${color_title_fg:-#4D4D4D 100}
|
||||
#color_title_border = ${color_title_border:-#169f6f 100}
|
||||
#color_title_bg = ${color_title_bg:-#262626 100}
|
||||
#color_scroll_ind = ${COLOR_SCROLL_IND:-#504e65 100}
|
||||
|
||||
sep_markup = weight="bold"
|
||||
sep_height = ${sep_height:-5}
|
||||
#font = ${jgmenu_font:-Noto Sans Medium 9}
|
||||
icon_size = ${jgmenu_icon_size:-16}
|
||||
icon_theme = ${jgmenu_icon_theme:-Numix-Square}
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
main () {
|
||||
# Mabox Linux
|
||||
if [[ -f /usr/share/mb-jgtools/pipemenu-standalone.cfg ]];then
|
||||
|
@ -290,21 +226,12 @@ out+=("<b>Add</b> color from selector...,$ME addcolor")
|
|||
fi
|
||||
# exposed thing
|
||||
case "$expose" in
|
||||
|
||||
html)
|
||||
htmlroot=". ${CNF_DIR}/htmlsub.csv"
|
||||
htmlsub=". ${CNF_DIR}/htmlclrs.csv"
|
||||
htmlclrs=""
|
||||
;;
|
||||
palette)
|
||||
pal=$(cat "$CNF_DIR/.palette")
|
||||
filename=${pal##*/}
|
||||
palette=${filename%.*}
|
||||
out+=("^sep(<i><span font_weight='light'>Last used palette</span> ${palette^}</i>)")
|
||||
while read -r color name;do
|
||||
#name=$(printf "%22s %s\n" "$name")
|
||||
#fg=$(fgcolor $color)
|
||||
#out+=("<tt><span bgcolor='$color' fgcolor='$fg'><sub> </sub>$color<sup>$name</sup></span></tt>,$ME getcolorcode '$color'")
|
||||
out+=("<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt> ,$ME getcolorcode '$color'")
|
||||
done < "${pal}"
|
||||
;;
|
||||
|
@ -313,17 +240,13 @@ case "$expose" in
|
|||
if (( ${#MAPFILE[@]} > 1 )); then
|
||||
out+=("^sep(<i><small>Recently used colors:</small></i>)")
|
||||
while read -r color name;do
|
||||
#name=$(printf "%22s %s\n" "$name")
|
||||
#fg=$(fgcolor $color)
|
||||
#out+=("<tt><span bgcolor='$color' fgcolor='$fg'><sub> </sub>$color<sup>$name</sup></span></tt>,$ME getcolorcode '$color'")
|
||||
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' $USED;$ME")
|
||||
done < <(grep ^# $USED)
|
||||
out+=("^sep()")
|
||||
out+=("<b>Clear</b> recently used colors,echo > $USED;$ME")
|
||||
fi
|
||||
;;
|
||||
picked|*)
|
||||
picked)
|
||||
mapfile -t < $RECENT
|
||||
if (( ${#MAPFILE[@]} > 1 )); then
|
||||
out+=("^sep(<i><small>Recently picked colors:</small></i>)")
|
||||
|
@ -333,30 +256,76 @@ case "$expose" in
|
|||
out2+=("<b>Clear</b> all,echo > $RECENT;$ME")
|
||||
out2+=("^sep(Just remove one color...)")
|
||||
while read -r color name;do
|
||||
# name=$(printf "%22s %s\n" "$name")
|
||||
# fg=$(fgcolor $color)
|
||||
# out+=("<tt><span bgcolor='$color' fgcolor='$fg'><sub> </sub>$color<sup>$name</sup></span></tt>,$ME getcolorcode '$color'")
|
||||
|
||||
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")
|
||||
#echo "<tt><small>$color</small> <span bgcolor='$color'><sub> </sub> <sup> </sup></span></tt> ,sed '/${color:1:6}/d' $RECENT;$ME"
|
||||
done < <(grep ^# $RECENT)
|
||||
|
||||
out+=("^sep()")
|
||||
out+=("<b>New palette</b> from recently picked,$ME recent2palette;$ME")
|
||||
#out+=("<b>Clear</b> recently picked,echo > $RECENT;$ME")
|
||||
out+=("<b>Clear</b> recently picked,^checkout(pickeddel)")
|
||||
fi
|
||||
;;
|
||||
wallpaper)
|
||||
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
|
||||
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)")
|
||||
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"
|
||||
;;
|
||||
*)
|
||||
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//_/ }
|
||||
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}")
|
||||
done < "$palfile"
|
||||
fi
|
||||
;;
|
||||
|
||||
esac
|
||||
#if [[ "$CNF_DIR"/palettes/my/*.clr ]]; then
|
||||
out+=("^sep(Color palettes)")
|
||||
if [ "$(find "$CNF_DIR"/palettes/my/*.clr -maxdepth 1 -type f -iname \*.clr)" ]; then
|
||||
out1+=("^sep(My palletes)")
|
||||
out+=("My palettes,^checkout(mypalettes)")
|
||||
palettes my
|
||||
fi
|
||||
if [[ $builtin_palettes == "yes" ]];then
|
||||
out1+=("^sep(Built-in palettes)")
|
||||
out+=("Built-in palettes,^checkout(builtpalettes)")
|
||||
palettes
|
||||
fi
|
||||
# WALLPAPER COLORS
|
||||
out+=("Current Wallpaper colors,^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
|
||||
convert ${WALLPATH} -resize 25% -colors 16 -unique-colors txt:- |grep -v '^#'| awk '{print $3}' > "$WALLPALDIR/$WALLPAPER.clr"
|
||||
fi
|
||||
#mapfile -t wallcolors < "$WALLPALDIR/$WALLPAPER.clr"
|
||||
out2+=("^tag(wallcolors)")
|
||||
out2+=("^sep(Current wallpaper colors)")
|
||||
out2+=("EXPOSE_IN_ROOTMENU ,$ME setvar expose=wallpaper;$ME")
|
||||
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)")
|
||||
|
@ -373,6 +342,7 @@ $(printf '%s\n' "${out2[@]}")
|
|||
|
||||
${htmlclrs}
|
||||
$(printf '%s\n' "${out3[@]}")
|
||||
$(printf '%s\n' "${out4[@]}")
|
||||
EOF
|
||||
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
|
||||
#printf '%s\n' "${out3[@]}"
|
||||
|
@ -415,7 +385,7 @@ 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>html</b> HTML Colors,$ME setvar expose=html;$ME")
|
||||
out2+=("<b>wallpaper</b> colors ,$ME setvar expose=wallpaper;$ME")
|
||||
|
||||
out2+=("^tag(showhtml)")
|
||||
out2+=("^sep(Show HTML colors?)")
|
||||
|
|
Loading…
Reference in New Issue