Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: cd $(locate zoo.txt|head -1)(:h)
- X-seq: zsh-users 21280
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: cd $(locate zoo.txt|head -1)(:h)
- Date: Fri, 12 Feb 2016 12:01:44 -0800
- 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==
- In-reply-to: <XnsA5ACBCB415Adavidrayninfocouk@80.91.229.13>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <XnsA5AC8D35FCD60davidrayninfocouk@80.91.229.13> <XnsA5ACBCB415Adavidrayninfocouk@80.91.229.13>
On Feb 12, 6:32pm, zzapper wrote:
} Subject: Re: cd $(locate zoo.txt|head -1)(:h)
}
} zzapper <david@xxxxxxxxxxxxxx> 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<TAB>
display a list of the directories that contain a zoo.txt file.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author