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!

  • varsock
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    set – “${@[0,eoo]:/(#m)^-*/${MATCH:a}}” “${@[eoo+1,-1]:a}”

    spoiler

    The given script appears to be written in the Zsh shell syntax. Let’s break it down step by step:

    1. set --: This command sets the positional parameters of the script. In Zsh, the -- option is used to signify the end of options and the beginning of positional parameters.

    2. "${@[0,eoo]:/(#m)^-*/${MATCH:a}}": This part refers to the expansion of the positional parameters, specifically targeting the elements from index 0 to the end of options offset (eoo). Here’s what the individual components mean:

      • ${@[0,eoo]}: This refers to a sub-array of positional parameters from index 0 to eoo. It extracts the elements corresponding to command-line options.
      • /(#m)^-*: This is a pattern match within a substitution. It matches any occurrences of hyphens (-) at the beginning of each element. The (#m) flag enables multiline mode for pattern matching.
      • ${MATCH:a}: This is the replacement part of the substitution. It expands the matched pattern (${MATCH}) and applies the :a modifier, which removes leading hyphens from the matched string.

      In summary, this part removes leading hyphens from the command-line options.

    3. "${@[eoo+1,-1]:a}": This part refers to the expansion of the positional parameters, specifically targeting the elements from the end of options offset (eoo + 1) to the last element. Here’s what the individual components mean:

      • ${@[eoo+1,-1]}: This refers to a sub-array of positional parameters from the end of options offset (eoo + 1) to the last element. It extracts the arguments that come after the command-line options.
      • :a: This applies the :a modifier, which removes leading hyphens from each element.

      In summary, this part removes leading hyphens from the command-line arguments that come after the options.

    Overall, the script modifies the command-line options and arguments by removing leading hyphens. The modified values are then set as the new positional parameters using the set command. The exact purpose or context of the script can only be determined by understanding its broader context and usage.

    • GammaOPM
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago
      Corrections

      It impressively identified exactly what eoo meant, and handled the array splicing, but it tripped over Zsh’s globbing syntax.

      /(#m)^-*: This is a pattern match within a substitution. It matches any occurrences of hyphens (-) at the beginning of each element.

      1. The : in ${foo:/pat/repl} requires pat to match the whole element
      2. The ^ actually negates the match, rather than anchors it to the start. ^-* matches any element not beginning with a hyphen.
      3. The (#m) flag captures the whole match in the parameter $MATCH.
      4. ${MATCH:a} transforms relative paths to absolute paths.
      Full context

      I use this as a wrapper around nvim --remote to make sure any non-options (i.e.: files) I pass have absolute paths rather than relative paths.