RSS

BASH Script for getting HEX/ANSI color values, with DMENU.

27 Δεκ.

I had some spare time, because of the Christmas holidays and thought to make a simple script, for getting the hex/ansi values of the main 16 colors used in DOS and various BBS stuff, like ANSI drawing and MODs.

It uses DMENU for selection and also XCLIP to copy the color code into the clipboard. You first select the type of color code, like HEX value or ANSI escape code and then the color. From the time i wrote it, i find my self using it a lot more 🙂 so i hope you also like it.

#!/bin/bash

#Description: Copies to clipboard the color hex/ansi value
#Depends: xclip, dmenu
#Author: XQTR of Another Droid BBS!
#Date: 2023/12

MENU="dmenu -i -p"

declare -Ag mci
mci[black]="|00"
mci[blue]="|01"
mci[green]="|02"
mci[cyan]="|03"
mci[red]="|04"
mci[magenta]="|05"
mci[brown]="|06"
mci[gray]="|07"
mci[darkgray]="|08"
mci[lightblue]="|09"
mci[lightgreen]="|10"
mci[lightcyan]="|11"
mci[lightred]="|12"
mci[lightmagenta]="|13"
mci[yellow]="|14"
mci[white]="|15"

declare -Ag dos
dos[black]="#000000" #black
dos[blue]="#729fcf" #blue
dos[green]="#4e9a06" #green
dos[cyan]="#06989a" #cyan
dos[red]="#cc0000" #red
dos[magenta]="#75507b" #magenta
dos[brown]="#c4a000" #yellow
dos[gray]="#d3d7cf" #gray
dos[darkgray]="#555753" #bright black
dos[lightblue]="#32afff" #br blue
dos[lightgreen]="#8ae234" #br green
dos[lightcyan]="#34e2e2" #br cyan
dos[lightred]="#ef2929" #br red
dos[lightmagenta]="#ad7fa8" #br magenta
dos[yellow]="#fce94f" #br yellow
dos[white]="#ffffff" #white

declare -Ag windows
windows[black]="#000000" #black
windows[blue]="#0000AA" #blue
windows[green]="#00AA00" #green
windows[cyan]="#00AAAA" #cyan
windows[red]="#AA0000" #red
windows[magenta]="#AA00AA" #magenta
windows[brown]="#AA5500" #brown
windows[gray]="#AAAAAA" #gray
windows[darkgray]="#555555" #dark gray
windows[lightblue]="#5555FF" #br blue
windows[lightgreen]="#55FF55" #br green
windows[lightcyan]="#55FFFF" #br cyan
windows[lightred]="#FF5555" #br red
windows[lightmagenta]="#FF55FF" #br magenta
windows[yellow]="#FFFF55" #yellow
windows[white]="#FFFFFF" #white

declare -Ag ansi
ansi[black]="\e[0;30m"
ansi[blue]="\e[0;34m"
ansi[green]="\e[0;32m"
ansi[cyan]="\e[0;36m"
ansi[red]="\e[0;31m"
ansi[magenta]="\e[0;35m"
ansi[brown]="\e[0;33m"
ansi[gray]="\e[0;37m"
ansi[darkgray]="\e[1;30m"
ansi[lightblue]="\e[1;34m"
ansi[lightgreen]="\e[1;32m"
ansi[lightcyan]="\e[1;36m"
ansi[lightred]="\e[1;31m"
ansi[lightmagenta]="\e[1;35m"
ansi[yellow]="\e[1;33m"
ansi[white]="\e[1;37m"

COLORS="ansi\ndos\nwindows\nmci"
selected="$(echo -e "${COLORS}" | ${MENU} "Select Type:")"
[ -z "${selected}" ] && exit 1
case "$selected" in
  dos)  colsel="$(printf '%s\n' "${!dos[@]}" | ${MENU} "Select Color:")"
        echo "${dos["${colsel}"]}" | xclip -r -selection clipboard ;;
  windows)  colsel="$(printf '%s\n' "${!windows[@]}" | ${MENU} "Select Color:")"
            echo "${windows["${colsel}"]}" | xclip -r -selection clipboard ;;
  ansi) colsel="$(printf '%s\n' "${!ansi[@]}" | ${MENU} "Select Color:")"
        echo "${ansi["${colsel}"]}" | xclip -r -selection clipboard ;;
  mci)  colsel="$(printf '%s\n' "${!mci[@]}" | ${MENU} "Select Color:")"
        echo "${mci["${colsel}"]}" | xclip -r -selection clipboard ;;
  *) exit 1 ;;
esac
 
 

Ετικέτες: , , ,

Σχολιάστε