From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9953 invoked by alias); 12 Feb 2016 20:01:33 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21280 Received: (qmail 27628 invoked from network); 12 Feb 2016 20:01:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=N7w3rKfVrwtaQPzEAyJyeNifrHjnEuerGvovHe+ZjgU=; b=KvgFN8HnbFFpoaICyYDDXnglnskd0wFS1iHbida3ExDLxTqguNMyQKP9Scej2/o0mb lS1Y+Wn1Ked4vVYZ+ZyCiGLN12ybKr7vPaNoErtxStCBE3JlSckw2WlUaZK/NuIYgKHR lAT9AwMkKQkzEQ7DWz202h/V9PWq4eN8JorG/RVA0NQvjdrWO38LVPIM46XItRPmYgfZ fW9lkKEyz5iK4NF5P48fVbHH9di+Qnyrsc2dEfL1bX8OFHyiOGezUXedl7lONIAswHZW Sj/IOjwPhZNc6qrwED0pogvIwV3Cybzln6DeHSeLZCD7jV5dZHVtw1WmJbPRKGxJCgZ4 bDJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=N7w3rKfVrwtaQPzEAyJyeNifrHjnEuerGvovHe+ZjgU=; b=KND9WRZunVcyKYPNzTPhQLKSSNykFbVK2YkO/yAgIphY7nAnAaxfhEqHibouzTAZJ+ vfndHdJlMVucdQ5AjS9x/yUmLSAlNAmVvneLk5283oCKJMEF09F2jpIDcUuswaOskktH AQfHl8dXTgA/NOp8ylPD8UvMsXGslurGpW7nko7gVUASvR70LwfH3MTvbq/Qy/AebLVd c8F9aVMGRGdxYDwV0Rum7KYpVXAPwezAyMmtjRxXiPSjwD2Ycv/OdkkRDaLQWoxCHTQU jGndBbP2a3BrN9mGUEW+1XugI46g77Sty/9tmJil2aP/1SiTq6crs+avueRG5pafJ5ZM xOUg== X-Gm-Message-State: AG10YOTDPnbJPqEm2jXPPpFxyX3gi8izJ7P5jh4ZdmsWRd+Xh70S3aB340+AsdQ2PV3kkg== X-Received: by 10.66.255.9 with SMTP id am9mr4819711pad.86.1455307290287; Fri, 12 Feb 2016 12:01:30 -0800 (PST) From: Bart Schaefer Message-Id: <160212120144.ZM15028@torch.brasslantern.com> Date: Fri, 12 Feb 2016 12:01:44 -0800 In-Reply-To: Comments: In reply to zzapper "Re: cd $(locate zoo.txt|head -1)(:h)" (Feb 12, 6:32pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: cd $(locate zoo.txt|head -1)(:h) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Feb 12, 6:32pm, zzapper wrote: } Subject: Re: cd $(locate zoo.txt|head -1)(:h) } } zzapper wrote in } news:XnsA5AC8D35FCD60davidrayninfocouk@80.91.229.13: } } > cd $(locate zoo.txt|head -1)(:h) } > } > I'd like to make this a bit more versatile, i.e detect more than one } > result and may be offer a list? } } cd $(locate -r -l1 "/zoo.txt$")(:h) Are you answering yourself or changing the question? (By the way, that doesn't work for me; on my system the -r option has to be immediately followed by the regular expression, so this searches for files whose names contain "-l1".) Obviously if you just execute that command as typed and the locate finds more than one file, "cd" is going to choke on it. So are you asking for a "cd" function that does something clever when handed a bunch of contradictory arguments? Conversely if you press TAB the default thing is going to expand all the names on the command line, which probably also isn't what you are looking for. So maybe you're looking for a completer that runs "locate" to get the list of matches? _locate () { local -a expl files [[ -o magicequalsubst ]] && compset -P '*=' files=($(_call_program locate locate -l1 -r "/$words[CURRENT]\$")) 2>/dev/null if (( $#files )) then local -au dirs=(${(D)${(b)files:h}}) compstate[pattern_match]='*' _wanted directories expl "directories containing $words[CURRENT]" \ compadd -QU -f -a dirs else return 1 fi } That could obviously use some work, e.g., you might want more regex decoration around $words[CURRENT], which ought to be controlled by a zstyle, etc. However adding this completer should make % cd zoo.txt display a list of the directories that contain a zoo.txt file.