* [gentoo-user] locate
@ 2007-05-11 12:34 Martin S
2007-05-11 12:48 ` Neil Bothwick
2007-05-11 13:18 ` Etaoin Shrdlu
0 siblings, 2 replies; 12+ messages in thread
From: Martin S @ 2007-05-11 12:34 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 452 bytes --]
Just recently tried using
locate foo.conf | cd
to automagically move to the directory in which I've saved foo.conf
Of course it didn't work as you can't cd to /bar/foo.conf
I didn't find a way to dropping the actual file name from the result of
locate.
I did a brief google on locate, but didn't find a switch to drop the actual
file name from the result.
Can it be done, or if not what should I use to get the desired result?
Regards,
Martin S
[-- Attachment #2: Type: text/html, Size: 531 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] locate
2007-05-11 12:34 [gentoo-user] locate Martin S
@ 2007-05-11 12:48 ` Neil Bothwick
2007-05-11 13:29 ` Martin S
2007-05-11 13:18 ` Etaoin Shrdlu
1 sibling, 1 reply; 12+ messages in thread
From: Neil Bothwick @ 2007-05-11 12:48 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 458 bytes --]
On Fri, 11 May 2007 14:34:44 +0200, Martin S wrote:
> Just recently tried using
>
> locate foo.conf | cd
>
> to automagically move to the directory in which I've saved foo.conf
> Of course it didn't work as you can't cd to /bar/foo.conf
>
> I didn't find a way to dropping the actual file name from the result of
> locate.
cd $(dirname $(locate foo.conf))
--
Neil Bothwick
WinErr 010: Reserved for future mistakes by our developers
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] locate
2007-05-11 12:34 [gentoo-user] locate Martin S
2007-05-11 12:48 ` Neil Bothwick
@ 2007-05-11 13:18 ` Etaoin Shrdlu
1 sibling, 0 replies; 12+ messages in thread
From: Etaoin Shrdlu @ 2007-05-11 13:18 UTC (permalink / raw
To: gentoo-user
On Friday 11 May 2007 14:34, Martin S wrote:
> Just recently tried using
>
> locate foo.conf | cd
>
> to automagically move to the directory in which I've saved foo.conf
> Of course it didn't work as you can't cd to /bar/foo.conf
It would not have worked anyway, since cd does not read its input from
stdin. Try:
[/]$ echo "etc" | cd
-bash: echo: write error: Broken pipe
[/]$
> I didn't find a way to dropping the actual file name from the result
> of locate.
> I did a brief google on locate, but didn't find a switch to drop the
> actual file name from the result.
It's not a locate problem. Use the "dirname" command.
$ dirname /bar/foo.conf
/bar
$
and do something like
cd $(dirname "$(locate foo.conf)")
of course, make sure that the locate command returns just a single entry.
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] locate
2007-05-11 12:48 ` Neil Bothwick
@ 2007-05-11 13:29 ` Martin S
2007-05-11 13:43 ` Neil Bothwick
2007-05-11 16:35 ` Uwe Thiem
0 siblings, 2 replies; 12+ messages in thread
From: Martin S @ 2007-05-11 13:29 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 709 bytes --]
That works yes.
A bit much to typw though. Don't know if I'd save much time from first doing
a locate and the manually typing the cd [result] string :)
Martin S
2007/5/11, Neil Bothwick <neil@digimed.co.uk>:
>
> On Fri, 11 May 2007 14:34:44 +0200, Martin S wrote:
>
> > Just recently tried using
> >
> > locate foo.conf | cd
> >
> > to automagically move to the directory in which I've saved foo.conf
> > Of course it didn't work as you can't cd to /bar/foo.conf
> >
> > I didn't find a way to dropping the actual file name from the result of
> > locate.
>
> cd $(dirname $(locate foo.conf))
>
> --
> Neil Bothwick
>
> WinErr 010: Reserved for future mistakes by our developers
>
>
--
Regards,
Martin S
[-- Attachment #2: Type: text/html, Size: 1061 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] locate
2007-05-11 13:29 ` Martin S
@ 2007-05-11 13:43 ` Neil Bothwick
2007-05-11 13:53 ` Martin S
2007-05-11 16:35 ` Uwe Thiem
1 sibling, 1 reply; 12+ messages in thread
From: Neil Bothwick @ 2007-05-11 13:43 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 358 bytes --]
On Fri, 11 May 2007 15:29:03 +0200, Martin S wrote:
> A bit much to typw though. Don't know if I'd save much time from first
> doing a locate and the manually typing the cd [result] string :)
Or type "cd <double-click> <middle-click>"
PS - please don't top-post.
--
Neil Bothwick
Two is not equal to three, even for large values of two.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] locate
2007-05-11 13:43 ` Neil Bothwick
@ 2007-05-11 13:53 ` Martin S
2007-05-11 14:09 ` Neil Bothwick
2007-05-11 14:36 ` Alex Schuster
0 siblings, 2 replies; 12+ messages in thread
From: Martin S @ 2007-05-11 13:53 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 453 bytes --]
2007/5/11, Neil Bothwick <neil@digimed.co.uk>:
>
> On Fri, 11 May 2007 15:29:03 +0200, Martin S wrote:
>
> > A bit much to typw though. Don't know if I'd save much time from first
> > doing a locate and the manually typing the cd [result] string :)
>
> Or type "cd <double-click> <middle-click>"
>
Forgot you're still toppost sensitive in this group.
Anyway I don't have a mouse on that system, so I'll have to use Alan
suggestion.
Regards,
Martin S
[-- Attachment #2: Type: text/html, Size: 765 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] locate
2007-05-11 13:53 ` Martin S
@ 2007-05-11 14:09 ` Neil Bothwick
2007-05-12 16:05 ` Bo Ørsted Andresen
2007-05-11 14:36 ` Alex Schuster
1 sibling, 1 reply; 12+ messages in thread
From: Neil Bothwick @ 2007-05-11 14:09 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 724 bytes --]
On Fri, 11 May 2007 15:53:42 +0200, Martin S wrote:
> Forgot you're still toppost sensitive in this group.
And always will be, once oyu've seen the one true way you don't change :)
> Anyway I don't have a mouse on that system, so I'll have to use Alan
> suggestion.
You could use a script. e.g.
#!/bin/sh
# cdlocate.sh
cd $(dirname $(locate $1 | head -n 1))
The head -n 1 will avoid it falling over when locate returns more than
one hit, although it will still break if there are no hits. Maybe,
although I haven't tested it, something like
FILE=$(locate "$*" | head -n 1))
[[ "${FILE}" ]] && cd $(dirname "${FILE}")
--
Neil Bothwick
Error reading FAT record: Try the SKINNY one? (Y/N)
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] locate
2007-05-11 13:53 ` Martin S
2007-05-11 14:09 ` Neil Bothwick
@ 2007-05-11 14:36 ` Alex Schuster
1 sibling, 0 replies; 12+ messages in thread
From: Alex Schuster @ 2007-05-11 14:36 UTC (permalink / raw
To: gentoo-user
Martin S writes:
> Anyway I don't have a mouse on that system, so I'll have to use Alan
> suggestion.
You could use a little shell function like this one. Add it to your
~/.bashrc or somewhere like that.
locatecd()
{
oldIFS=$IFS
IFS=$'\n'
results=( $( locate "$1" ) )
ret=$?
IFS=$oldIFS
if (( ret ))
then
echo "Sorry, '$1' was not found."
return $ret
fi
if (( ${#results[@]} > 1 ))
then
echo "More than one file found, using the first one."
fi
cd "$( dirname "${results[@]}" )"
}
Alex
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] locate
2007-05-11 13:29 ` Martin S
2007-05-11 13:43 ` Neil Bothwick
@ 2007-05-11 16:35 ` Uwe Thiem
1 sibling, 0 replies; 12+ messages in thread
From: Uwe Thiem @ 2007-05-11 16:35 UTC (permalink / raw
To: gentoo-user
On 11 May 2007, Martin S wrote:
> That works yes.
> A bit much to typw though. Don't know if I'd save much time from first
> doing a locate and the manually typing the cd [result] string :)
Make it a shell function if you need it often.
Uwe
--
The Informal Linux Group Namibia:
http://www.linux.org.na
SysEx (Pty) Ltd.:
http://www.SysEx.com.na
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] locate
2007-05-11 14:09 ` Neil Bothwick
@ 2007-05-12 16:05 ` Bo Ørsted Andresen
2007-05-12 17:04 ` [gentoo-user] locate Alexander Skwar
2007-05-12 19:38 ` [gentoo-user] locate Neil Bothwick
0 siblings, 2 replies; 12+ messages in thread
From: Bo Ørsted Andresen @ 2007-05-12 16:05 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 316 bytes --]
On Friday 11 May 2007 16:09:40 Neil Bothwick wrote:
> > Anyway I don't have a mouse on that system, so I'll have to use Alan
> > suggestion.
>
> You could use a script. e.g.
A script won't help as it will only change the path in the context of the
script. A shell function is required.
--
Bo Andresen
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* [gentoo-user] Re: locate
2007-05-12 16:05 ` Bo Ørsted Andresen
@ 2007-05-12 17:04 ` Alexander Skwar
2007-05-12 19:38 ` [gentoo-user] locate Neil Bothwick
1 sibling, 0 replies; 12+ messages in thread
From: Alexander Skwar @ 2007-05-12 17:04 UTC (permalink / raw
To: gentoo-user
Bo Ørsted Andresen <bo.andresen@zlin.dk> wrote:
> On Friday 11 May 2007 16:09:40 Neil Bothwick wrote:
>> > Anyway I don't have a mouse on that system, so I'll have to use Alan
>> > suggestion.
>>
>> You could use a script. e.g.
>
> A script won't help as it will only change the path in the context of the
> script.
Depends on how you call the script. If you do:
script
then you're right.
You could however source the script; ie. call:
. script
Alexander Skwar
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] locate
2007-05-12 16:05 ` Bo Ørsted Andresen
2007-05-12 17:04 ` [gentoo-user] locate Alexander Skwar
@ 2007-05-12 19:38 ` Neil Bothwick
1 sibling, 0 replies; 12+ messages in thread
From: Neil Bothwick @ 2007-05-12 19:38 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 322 bytes --]
Hello Bo Ørsted Andresen,
> A script won't help as it will only change the path in the context of
> the script. A shell function is required.
It would work if you sourced it, but a shell function would be better.
--
Neil Bothwick
WinErr 020: Error recording error codes - Additional errors will be lost.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2007-05-12 19:46 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-11 12:34 [gentoo-user] locate Martin S
2007-05-11 12:48 ` Neil Bothwick
2007-05-11 13:29 ` Martin S
2007-05-11 13:43 ` Neil Bothwick
2007-05-11 13:53 ` Martin S
2007-05-11 14:09 ` Neil Bothwick
2007-05-12 16:05 ` Bo Ørsted Andresen
2007-05-12 17:04 ` [gentoo-user] locate Alexander Skwar
2007-05-12 19:38 ` [gentoo-user] locate Neil Bothwick
2007-05-11 14:36 ` Alex Schuster
2007-05-11 16:35 ` Uwe Thiem
2007-05-11 13:18 ` Etaoin Shrdlu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox