Lua Config For Advanced Shell Scripting

Hi there having trouble trying to get the syntax correct. Here’s my hyprlang code block for screenshots. The problem seems to with more complex shell scripting. 

# Region → annotate in satty → auto-copy to clipboard (most useful daily bind)
bind = , XF86SELECTIVESCREENSHOT, exec, grim -g "$(slurp)" - | satty --filename - --copy-command wl-copy --early-exit --fullscreen
# Fullscreen screenshot → annotate → copy
bind = SHIFT, XF86SELECTIVESCREENSHOT, exec, grim - | satty --filename - --copy-command wl-copy --early-exit --fullscreen
# Region → annotate → save to file (with timestamp)
bind = SUPER SHIFT, XF86SELECTIVESCREENSHOT, exec, grim -g "$(slurp)" -t ppm - | satty --filename - --output-filename ~/Pictures/Screenshots/satty-$(date +%Y%m%d-%H%M%S).png
# Quick region capture → save directly (no edit)
bind = CTRL SHIFT, XF86SELECTIVESCREENSHOT, exec, mkdir -p ~/Pictures/Screenshots && grim -g "$(slurp)" ~/Pictures/Screenshots/screenshot-$(date +%Y-%m-%d-%H%M%S).png

hl.bind("XF86SELECTIVESCREENSHOT",
        h1.dsp.exec_cmd("grim -g "$(slurp)" - | satty --filename - --copy-command wl-copy --early-exit --fullscreen"))

hl.bind("SHIFT + XF86SELECTIVESCREENSHOT",
        h1.dsp.exec_cmd("grim - | satty --filename - --copy-command wl-copy --early-exit --fullscreen"))

hl.bind("SUPER + SHIFT + XF86SELECTIVESCREENSHOT",
        h1.dsp.exec_cmd("grim -g "$(slurp)" -t ppm - | satty --filename - --output-filename ~/Pictures/Screenshots/satty-$(date +%Y%m%d-%H%M%S).png"))

hl.bind("CTRL + SHIFT = XF86SELECTIVESCREENSHOT",
        h1.dsp.exec_cmd("mkdir -p ~/Pictures/Screenshots && grim -g "$(slurp)" ~/Pictures/Screenshots/screenshot-$(date +%Y-%m-%d-%H%M%S).png"))

What am I missing here? Surely it’s a Lua and / or shell scripting syntax, escape issue, etc.?

Bunch of places you break the string sent to sh.

h1.dsp.exec_cmd("mkdir -p ~/Pictures/Screenshots && grim -g "$(slurp)" ~/Pictures/Screenshots/screenshot-$(date +%Y-%m-%d-%H%M%S).png"))

Got it working. The key is Lua [[ ]].

hl.bind(“XF86SELECTIVESCREENSHOT”,
hl.dsp.exec_cmd([[grim -g “$(slurp)” - | satty --filename - --copy-command wl-copy --early-exit --fullscreen]]))

hl.bind(“SHIFT + XF86SELECTIVESCREENSHOT”,
hl.dsp.exec_cmd([[grim - | satty --filename - --copy-command wl-copy --early-exit --fullscreen]]))

hl.bind(“SUPER + SHIFT + XF86SELECTIVESCREENSHOT”,
hl.dsp.exec_cmd([[grim -g “$(slurp)” -t ppm - | satty --filename - --output-filename ~/Pictures/Screenshots/satty-$(date +%Y%m%d-%H%M%S).png]]))

hl.bind(“CTRL + SHIFT + XF86SELECTIVESCREENSHOT”,
hl.dsp.exec_cmd([[mkdir -p ~/Pictures/Screenshots && grim -g “$(slurp)” ~/Pictures/Screenshots/screenshot-$(date +%Y-%m-%d-%H%M%S).png]]))

You can use backslashes in lua if you only have quotes

local run_cmd      = "WOFI_RUN=$(wofi --dmenu) ; [ -n \"$WOFI_RUN\" ] && alacritty -e bash --rcfile ~/.aliases -ic \"$WOFI_RUN ; echo ; read -n 1 -p 'Press any key to Exit ...' wait\""

Also it’s better to use with variables if you have a very long command with concatenation like operator .. in lua like this

local private_term = "HOME=/tmp HISTFILE=/dev/null " .. terminal .. config_opts .. " --working-directory /tmp -e bash --rcfile ~/.aliases"

Also syntax with [[ ]] also valid as stated.