Search code examples
bashvimzenity

subshell in var assignment prevents proper document highlighting


I am yad'fying an alarm script I use from the terminal multiple times a day for quick reminders. Anyway, this var assignment:

killOrSnz=$((sleep .1 ; wmctrl -r yadAC -e 0,6,30,0,0) | yad --title yadAC --image="$imgClk" --text "Alarm:\n${am}" --form --field="Hit Enter key to stop the alarm\nor enter a number of minutes\nthe alarm should snooze." --button="gtk-cancel:1" --button="gtk-ok:0"|sed -r 's/^([0-9]{1,})\|[ ]*$/\1/')

is causing me grief. The var works fine, as intended, except that all of the code below it is no longer highlighted in my vim session, making my eyes hurt just to look at it never mind scan for problems or to make alterations.

I borrowed the idea of piping yad command thru wmctrl to gain better control over window geometry, which is great from another post on here, but there was of course no mention of the potential side-affects. I want to keep fine control over the window placement of apps, but it would just be nice to do so while maintaining document highlighting.

I did try to rearrange the pipe and subshell to see if I could get it to work another way that didn't interfere with my vim highlighting, but there was no love to be had any which way but this way.


Solution

  • It appears that VIM's parser is fooled by the $((, mistaking it for the start of an arithmetic expression rather than a command substitution whose first character is a parentheses. Since there is no matching )), the colorizer gets confused about what is what. Try adding an explicit space between the two open parens:

    killOrSnz=$( (sleep .1; ... )