I’m sure some of you have absolute monstrosities of sigils (I know I do, in my .zshrc alone). Post them without context, and try and guess what other users’s lines are. If you want to provide context or guess, use the markdown editor to spoiler-tag your guesses and explanations!

  • Gamma@programming.devOPM
    link
    fedilink
    English
    arrow-up
    4
    ·
    1 year ago
    ZDOTDIR="${${(%):-%x}:P:h}"
    
    Literal explanation
    • ${(%)...} enable prompt sequences
    • %x a prompt sequence which expands to the current file being executed
    • :P resolve symlinks
    • :h the parent directory
    Full context

    This line is in my ~/.config/zsh/.zshenv, which I symlink into my home directory. This resolves the symlink and sets $ZDOTDIR to the directory in which my zsh config files actually live, that way they aren’t all in my home directory.

  • Gamma@programming.devOPM
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 year ago

    Here’s one with a bit more context (and actually in Bash, rather than Zsh:

    typeset -A any
    while ((${#anys})); do
    	any[${anys:0:1}]="/${anys:0:1}/!d;"
    	anys=${anys:1}
    done
    anys=${any[*]}
    
    Literal explanation
    • Iterate through the characters in $anys
    • For each character $c, define any[$c] to be the string /$c/!d (e.g.: any[x]='/x/!d')
    • Concatenate the values in ${any[@]}
    Full context

    This is building a sed command to delete all lines which don’t contain every character of the string $anys. The associative array and concatenation is to ensure I don’t repeat myself when building the command. This is used in a program called dewordle, which prints all remaining words in a dictionary given the current known information in a game of wordle.

  • Reptorian@programming.dev
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    1 year ago

    Feel free to delete this post if you don’t feel that this fits though I think the language I use is very similar to bash in some ways (G’MIC). Here’s a real-world example of my own code in G’MIC that’s pretty much painful to parse:

    command "out2display : skip ${""1=},${""2=},${""3=},${""4=1},${""5=1},${""6=},${""7=},${""8=},${""9=},${""10=} if narg($""1) if $""1 $__bg rv blend alpha fi fi xalp if narg($""6) if narg($""2)&&narg($""3)&&narg($""4)&&narg($""5) {$""4},{$""5},1,{s#0},i(#-1,$""2+x,$""3+y) f. begin(ww=w-1;hh=h-1;);(x<(2+narg($""7))||x>ww-2)||(y<(2+narg($""7))||y>hh-2)?(xor($""6,i)>128?0:255):i j[0] [-1],$""2,$""3 rm. if narg($""8)&&narg($""9)&&narg($""10) if $""8==0||$""8>2 {$""4},{$""5},1,{s#0},i(#0,$__nw+($__min_tile*$""9)-$""2+x-$""4,$""3+y) f. begin(ww=w-1;hh=h-1;);(x<(2+narg($""7))||x>ww-2)||(y<(2+narg($""7))||y>hh-2)?(xor($""6,i)>128?0:255):i j[0] [-1],{$__nw+($__min_tile*$""9)-$""2-$""4},$""3 rm. fi if $""8==1||$""8>2 {$""4},{$""5},1,{s#0},i(#0,$""2+x,$__nh+($__min_tile*$""10)-$""3+y-$""5) f. begin(ww=w-1;hh=h-1;);(x<(2+narg($""7))||x>ww-2)||(y<(2+narg($""7))||y>hh-2)?(xor($""6,i)>128?0:255):i j[0] [-1],$""2,{$__nh+($__min_tile*$""10)-$""3-$""5} rm. fi if $""8==2||$""8>2 {$""4},{$""5},1,{s#0},i(#0,$__nw+($__min_tile*$""9)-$""2+x-$""4,$__nh+($__min_tile*$""10)-$""3+y-$""5) f. begin(ww=w-1;hh=h-1;);(x<(2+narg($""7))||x>ww-2)||(y<(2+narg($""7))||y>hh-2)?(xor($""6,i)>128?0:255):i j[0] [-1],{$__nw+($__min_tile*$""9)-$""2-$""4},{$__nh+($__min_tile*$""10)-$""3-$""5} rm. fi fi fi fi if narg($""7) f[0] begin(ww=w-1;hh=h-1;);(x%$__min_tile==0||y%$__min_tile==0)||(x==ww||y==hh)?$""7:i fi"
    

    That was before I figured out how to properly code in local commands.

  • Gamma@programming.devOPM
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago
    reply=( ${(M)dirs:#*/$~pattern}(Noe['REPLY=${(l[3][0])#REPLY:t}'][1]) )
    
    Literal explanation
    • $~pattern interpret globbing characters (like *, ?, or [a-z]) in the parameter $pattern,
    • ${(M)dirs:#*/$~pattern} filter the array $dirs to those matching */$~pattern.
    • ${...}(...) everything in (...) are globbing qualifiers
    • (N) enable nullglob
    • (oe[...]) sort by the result of the shell snippet, where $REPLY is used as input and output
    • ${...REPLY:t} remove all leading path components from $REPLY
    • ${...#REPLY:t} substitute the length of that string
    • ${(l[3][0])#REPLY:t} left-pad with zeroes to a length of 3
    • reply=( ... ) save as $reply
    Full context

    This line is in a function which dynamically expands ~[g:abc] to one of my git repos, choosing the shortest directory matching path/to/abc*, or if no match is found, the shortest matching *abc*. So between /long/path/to/abcdef and /short/abcdefg, it would choose the first one (provided both of those were in the search paths I configured).

  • narshee@iusearchlinux.fyi
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I don’t have a riddle and I can’t read Bashisms. In posix shell the most unreadable things are parameter expansion, but compared to the lines OP posted they seems straight forward.

  • xcjs@programming.dev
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    1 year ago

    It’s not bash itself that was the complex part exactly, but I have a CI/CD pipeline that generates epub files from markdown. In some cases I have custom designed covers, but where a cover doesn’t exist I have a bash script generate one using Imagemagick.

    I wanted to generate the cover in one command to lessen performance impacts and disk I/O, but it took me a few weeks to figure out how to do it all in a single Imagemagick command:

    convert \
        -size 960x1536 \
        -background "${backgroundColor}" \
        -fill "${textColor}" \
        -font "Liberation-Serif" \
        -pointsize 96 \
        -gravity north \
        caption:"${title}" \
        -bordercolor "rgb(0, 0, 0)" \
        -border 2 \
        -bordercolor "${borderColor}" \
        -border 40 \
        -background none \
        -fill "${textColor}" \
        -font "Liberation-Serif" \
        -pointsize 48 \
        -gravity south \
        -geometry +0-800 \
        -annotate +0+40 "${author}" \
        "${destination}cover.jpg"
    

    Eventually it made an abstract sense to me, and I was able to bring it down to two commands and then finally one. This generates a cover with a selected background color (based on content type) and contains title text that will wrap to an inner border.

    I think I had to give up on the author being wrapped, but it’s much smaller than the title anyway.