Skip to content

Commit

Permalink
✨ Add ctp-rofi script
Browse files Browse the repository at this point in the history
  • Loading branch information
mekb-turtle committed Jan 28, 2025
1 parent 3a5ab05 commit 5e26097
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
~/.bin/emojiclip: submodules/emojipicker/emojiclip
~/.bin/emojipicker/emojis: submodules/emojipicker/emojis
~/.bin/hyprstart: scripts/hyprstart
~/.bin/ctp-rofi: scripts/ctp-rofi
~/.bin/lock: scripts/lock
~/.bin/toggle-autolock: scripts/toggle-autolock
~/.bin/hypr-search-proc.pl: scripts/hypr-search-proc.pl
Expand Down
3 changes: 1 addition & 2 deletions keybinds
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ keybinds=(
"$MOD, A, exec, \$HOME/.bin/emojiclip rofi" # Emoji menu
"$MOD, B, exec, if pidof -sq waybar; then killall -SIGUSR1 waybar; else ~/.bin/rewaybar; fi" # Toggle waybar
"$MOD, C, exec, cliphist list | rofi -dmenu | cliphist decode | wl-copy" # Clipboard history
"$MOD, X, exec, \$HOME/.bin/ctp-rofi" # Rofi Catppuccin color picker, this code is a mess so I'm not including it here
"$MOD, X, exec, \$HOME/.bin/ctp-rofi" # Rofi Catppuccin color picker
"$MOD SHIFT, C, exec, true | wl-copy; cliphist wipe && notify-send 'cleared clipboard history' -a ''" # Clear clipboard history
"$MOD SHIFT, V, exec, ~/.bin/dictation" # Voice dictation, https://github.com/ideasman42/nerd-dictation, pain to setup so I'm not including it here
"$MOD, Z, exec, dunstctl history-pop" # Show last notification
"$MOD, L, exec, ~/.bin/lock" # Lock screen
"$MOD SHIFT, L, exec, ~/.bin/toggle-autolock" # Toggle automatic locking
Expand Down
82 changes: 82 additions & 0 deletions scripts/ctp-rofi
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
# This code is a mess lol
function ctp-rofi() {
set -euo pipefail
local file json palette disp_palette color format col out palettes FUNC
local -a list display
function dmenu-func() {
local ret
rofi -dmenu "$@" || {
# return 0 on cancel
ret="$?"
if [[ "$ret" == 1 ]]; then
return 0
fi
return "$ret"
}
}
file="${XDG_CACHE_HOME:-$HOME/.cache}/catppuccin-palette.json"
[[ -f $file ]] || {
curl -sL https://github.com/catppuccin/palette/raw/refs/heads/main/palette.json >"$file"
}
json="$(<"$file")"

FUNC=""
FUNC="$FUNC"'def h: .[1:];'
FUNC="$FUNC"'def r: map_values(round);'
FUNC="$FUNC"'def hr: to_entries | map(if .key == "h" then .value = (.value | round) else .value = (.value * 1000 | round) / 1000 end) | from_entries;'
FUNC="$FUNC"'def rgb: "rgb(\(.r), \(.g), \(.b))";'
FUNC="$FUNC"'def hsl: "hsl(\(.h), \(.s), \(.l))";'
FUNC="$FUNC"'def block: "<span color=\"\(.)\"><big>█</big></span>";'

while true; do
IFS=$'\n'

palettes="$(jq 'to_entries[] | select(.value|type=="object") | [.] | from_entries' <<<"$json")"
list=(null $(jq -r 'to_entries|map(.key)[]' <<<"$palettes"))
display=($'\u21a9\ufe0f Return' $(jq -r '.[]|.emoji + " " + .name' <<<"$palettes"))
palette="$(printf "%s\n" "${display[@]}" | dmenu-func -format i -p 'Palette:' -i)"
if [[ -z "$palette" ]]; then break; fi
if [[ "$palette" == 0 ]]; then
break
fi
disp_palette="${display["$palette"]}"
palette="${list["$palette"]}"

while true; do
list=(null $(jq -r '.[$p].colors | to_entries|map(.key)[]' --arg p "$palette" <<<"$json"))
display=("$disp_palette" $(jq -r "$FUNC"'.[$p].colors[] | "\(.hex|block) <tt>\(.name)</tt>:<tt>\t\(.hex)</tt>,<tt>\t\(.rgb|rgb)</tt>,<tt>\t\(.hsl|hr|hsl)</tt>"' --arg p "$palette" <<<"$json"))

color="$(printf "%s\n" "${display[@]}" | column -ts$'\t' | dmenu-func -theme-str 'window {width: 800px;}' -markup-rows -format i -p 'Color:' -i)"
if [[ -z "$color" ]]; then break; fi
if [[ "$color" == 0 ]]; then
# return to previous screen
break
fi
color="${list["$color"]}"

while true; do
col="$(jq <<<"$json" --arg p "$palette" --arg c "$color" "$FUNC"'.[$p].colors[$c]+{"id":$c}')"
hex="$(jq -r '.hex' <<<"$col")"
list=($(jq -r "$FUNC"'null, .hex, (.hex|h), (.rgb|rgb), (.hsl|hsl), .name, .id' <<<"$col"))
display=($(jq -r "$FUNC"'"\(.hex|block) \(.name)", "Hex: \(.hex)", "Hex: \(.hex|h)", "RGB: \(.rgb|hr|rgb)", "HSL: \(.hsl|hr|hsl)", "Name: \(.name)", "ID: \(.id)"' <<<"$col"))

format="$(printf "%s\n" "${display[@]}" | dmenu-func -select "Hex" -markup-rows -format i -p 'Format:' -i)"
if [[ -z "$format" ]]; then break; fi
if [[ "$format" == 0 ]]; then
# return to previous screen
break
fi
out="${list["$format"]}"

magick -size 256x256 "xc:$hex" /tmp/ctp-rofi.png
notify-send "$out" --app-name=Copied --icon=/tmp/ctp-rofi.png
wl-copy --type text/plain -- "$out"

return 0
done
done
done
return 1
}
ctp-rofi "$@"

0 comments on commit 5e26097

Please sign in to comment.