Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: optimal expansions?
- X-seq: zsh-users 29843
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: optimal expansions?
- Date: Sat, 20 Apr 2024 07:23:44 -0700
- Archived-at: <https://zsh.org/users/29843>
- In-reply-to:  <CAN=4vMqfcxt-C-g=4Sk13Qu28LFK46QCfXajhHfFMzLCcsXysg@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <53fab6be-26d7-4de5-844f-ffc295d9a494@eastlink.ca> <CAN=4vMqfcxt-C-g=4Sk13Qu28LFK46QCfXajhHfFMzLCcsXysg@mail.gmail.com>
  
  
    
    
    On 2024-04-20 00:42, Roman Perepelitsa
      wrote:
    
    
    Hafta start using lines like this all the time.  You guys never
    start a function without one of these 'emulate' instructions -- make
    sure that the func has the environment it needs.
        emulate zsh -o no_unset -o pipe_fail -o err_exit
      
    () {
      local last_pkg pkg file
    
    So you break it into words automatically here, and any spaced
    filenames end up in 'file' anyway!  
    
            apt-file search "$1" | while read -r pkg file; do
        if [[ $pkg != $last_pkg ]]; then
          [[ -n $last_pkg ]] && print
          last_pkg=$pkg
    
    ... this line is Basque to me.  It works but I have no idea how. 
    Anyway that's for me to research.  It baffles me that there's color
    codes in there.
    
                print -P "%B%2F${pkg//\%/%%}%f%b"
        fi
    
    Seems we want '-r' most of the time.  And the '--' should always be
    there.  Now that I know not to use newlines for splitting.  And of
    course that obviates most of my '(@f)'s too.
    
              print -r -- $file
      done
    } "$@"
This implementation fixes a couple of bugs in addition to those
mentioned by Lawrence: it gets rid of the empty line at start of the
output, and leaves whitespace in file names unchanged.
    
    To pick nits I want the leading empty line.  But I'm betting your
    code will be faster.  I'll keep Lawrence's edits until such times as
    I understand that 'print -P' tho.  
    
    
    
  
Messages sorted by:
Reverse Date,
Date,
Thread,
Author