Sample Header Ad - 728x90

why is zsh not expanding this glob defined inside a function '(:a)'

7 votes
2 answers
598 views
The second line of the script only works if I trigger glob expansion by executing echo. I can't understand why. Here's the command and it's execution to give some context. Function definition:
~/ cat ~/.zsh/includes/ascii2gif
ascii2gif () {
        setopt extendedglob
        input=$(echo ${1}(:a))
        _path=${input:h}
        input_f=${input:t}
        output_f=${${input_f}:r}.gif
        cd $_path
        nerdctl run --rm -v $_path:/data asciinema/asciicast2gif -s 2 -t solarized-dark $input_f $output_f
}
Activate function debugging for ascii2gif function..
~/ typeset -f -t ascii2gif
Debugged function execution:
~/ ascii2gif ./demo.cast
+ascii2gif:1> input=+ascii2gif:1> echo /Users/b/demo.cast
+ascii2gif:1> input=/Users/b/demo.cast
+ascii2gif:2> _path=/Users/b
+ascii2gif:3> input_f=demo.cast
+ascii2gif:4> output_f=demo.gif
+ascii2gif:5> cd /Users/b
+_direnv_hook:1> trap -- '' SIGINT
+_direnv_hook:2> /Users/b/homebrew/bin//direnv export zsh
+_direnv_hook:2> eval ''
+_direnv_hook:3> trap - SIGINT
+ascii2gif:6> nerdctl run --rm -v /Users/b:/data asciinema/asciicast2gif -s 2 -t solarized-dark demo.cast demo.gif
==> Loading demo.cast...
==> Spawning PhantomJS renderer...
==> Generating frame screenshots...
==> Combining 40 screenshots into GIF file...
==> Done.
I've tried numerous variations to try and force expansion such as input=${~1}(:a) etc, but to no avail. Any suggestions? Obviously the script works but seems sub-optimal.
Asked by bryan hunt (73 rep)
Mar 30, 2022, 11:48 AM
Last activity: Mar 30, 2022, 08:51 PM