git locate

14 messages, 8 authors, 2016-06-15 · open the first message on its own page

git locate

From: John Tapsell <hidden>
Date: 2016-06-15 22:48:03

Hey all,

  Could we add a:  git locate <filename>       or git find <filename>
 that is just an alias to "git ls-files | grep filename" ?

Reasons:

1) git ls-files   does not autocomplete, since it's an low-level
plumbing command
2) It's nice having shell equivalents - e.g.  git grep etc

John

Re: git locate

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:48:04

Hi,

On Wed, 20 Jan 2010, John Tapsell wrote:
  Could we add a:  git locate <filename>       or git find <filename>
How about "git ls-files \*<filename>"?

Ciao,
Dscho

Re: git locate

From: Jakub Narebski <hidden>
Date: 2016-06-15 22:48:04

Johannes Schindelin [off-list ref] writes:
On Wed, 20 Jan 2010, John Tapsell wrote:
quoted
  Could we add a:  git locate <filename>       or git find <filename>
How about "git ls-files \*<filename>"?
Or "git ls-files '*filename'...

... but how to make an (git) alias for this?

-- 
Jakub Narebski
Poland
ShadeHawk on #git

Re: git locate

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:48:04

Hi,

On Tue, 19 Jan 2010, Jakub Narebski wrote:
Johannes Schindelin [off-list ref] writes:
quoted
On Wed, 20 Jan 2010, John Tapsell wrote:
quoted
  Could we add a:  git locate <filename>       or git find <filename>
How about "git ls-files \*<filename>"?
Or "git ls-files '*filename'...

... but how to make an (git) alias for this?
Add something like this to your $HOME/.gitconfig:

[alias]
        locate = !sh -c 'git ls-files "\\*$1"' -

Ciao,
Dscho

Re: git locate

From: Jakub Narebski <hidden>
Date: 2016-06-15 22:48:04

On Wed, 20 Jan 2010, Johannes Schindelin wrote:
On Tue, 19 Jan 2010, Jakub Narebski wrote:
quoted
Johannes Schindelin [off-list ref] writes:
quoted
On Wed, 20 Jan 2010, John Tapsell wrote:
quoted
  Could we add a:  git locate <filename>       or git find <filename>
How about "git ls-files \*<filename>"?
Or "git ls-files '*filename'...

... but how to make an (git) alias for this?
Add something like this to your $HOME/.gitconfig:

[alias]
        locate = !sh -c 'git ls-files "\\*$1"' -
Thanks a lot, Dscho!


I think it would be nice to have this trick 

  alias.<cmd> = !sh -c '<commands with $1, $@, $#>' -

described in git-config (alias) documentation.  Unfortunately I don't
understand this trick well enough to do it myself...

-- 
Jakub Narebski
Poland

Re: git locate

From: John Tapsell <hidden>
Date: 2016-06-15 22:48:04

2010/1/20 Jakub Narebski [off-list ref]:
On Wed, 20 Jan 2010, Johannes Schindelin wrote:
quoted
On Tue, 19 Jan 2010, Jakub Narebski wrote:
quoted
Johannes Schindelin [off-list ref] writes:
quoted
On Wed, 20 Jan 2010, John Tapsell wrote:
quoted
  Could we add a:  git locate <filename>       or git find <filename>
How about "git ls-files \*<filename>"?
Or "git ls-files '*filename'...

... but how to make an (git) alias for this?
Add something like this to your $HOME/.gitconfig:

[alias]
        locate = !sh -c 'git ls-files "\\*$1"' -
I think having this alias by default would be very nice though - it's
pretty common to locate/find files, and it's nice to have unixy
equivalents in git.

If this really isn't wanted, then perhaps the ls-files command should
be bash auto-completed?

Thanks!

John

Re: git locate

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:48:04

Hi,

On Wed, 20 Jan 2010, Jakub Narebski wrote:
On Wed, 20 Jan 2010, Johannes Schindelin wrote:
quoted
On Tue, 19 Jan 2010, Jakub Narebski wrote:
quoted
Johannes Schindelin [off-list ref] writes:
quoted
On Wed, 20 Jan 2010, John Tapsell wrote:
quoted
  Could we add a:  git locate <filename>       or git find <filename>
How about "git ls-files \*<filename>"?
Or "git ls-files '*filename'...

... but how to make an (git) alias for this?
Add something like this to your $HOME/.gitconfig:

[alias]
        locate = !sh -c 'git ls-files "\\*$1"' -
Thanks a lot, Dscho!


I think it would be nice to have this trick 

  alias.<cmd> = !sh -c '<commands with $1, $@, $#>' -
Heh.  I initially read @$^&*#^&*@#$.
described in git-config (alias) documentation.  Unfortunately I don't 
understand this trick well enough to do it myself...
I tried to explain things properly in

http://git.wiki.kernel.org/index.php/Aliases#Advanced_aliases_with_arguments

Ciao,
Dscho

Re: git locate

From: SungHyun Nam <hidden>
Date: 2016-06-15 22:48:04

Hello,

Johannes Schindelin wrote:
On Tue, 19 Jan 2010, Jakub Narebski wrote:
quoted
Johannes Schindelin[off-list ref]  writes:
quoted
On Wed, 20 Jan 2010, John Tapsell wrote:
quoted
   Could we add a:  git locate<filename>        or git find<filename>
How about "git ls-files \*<filename>"?
Or "git ls-files '*filename'...

... but how to make an (git) alias for this?
Add something like this to your $HOME/.gitconfig:

[alias]
         locate = !sh -c 'git ls-files "\\*$1"' -
The alias 'git locate' and the command 'git ls-files' runs
differently if I run them in a subdirectory.
Is it expected?

[master] ~/srcs/git[299]$ git locate urls.txt
Documentation/urls.txt
[master] ~/srcs/git[300]$ git ls-files '*urls.txt'
Documentation/urls.txt
[master] ~/srcs/git[301]$ cd t
[master] ~/srcs/git/t[302]$ git locate urls.txt
Documentation/urls.txt
[master] ~/srcs/git/t[303]$ git ls-files '*urls.txt'
[master] ~/srcs/git/t[304]$

Thanks,
namsh

Re: git locate

From: Michael J Gruber <hidden>
Date: 2016-06-15 22:48:04

SungHyun Nam venit, vidit, dixit 21.01.2010 01:11:
Hello,

Johannes Schindelin wrote:
quoted
On Tue, 19 Jan 2010, Jakub Narebski wrote:
quoted
Johannes Schindelin[off-list ref]  writes:
quoted
On Wed, 20 Jan 2010, John Tapsell wrote:
quoted
   Could we add a:  git locate<filename>        or git find<filename>
How about "git ls-files \*<filename>"?
Or "git ls-files '*filename'...

... but how to make an (git) alias for this?
Add something like this to your $HOME/.gitconfig:

[alias]
         locate = !sh -c 'git ls-files "\\*$1"' -
The alias 'git locate' and the command 'git ls-files' runs
differently if I run them in a subdirectory.
Is it expected?

[master] ~/srcs/git[299]$ git locate urls.txt
Documentation/urls.txt
[master] ~/srcs/git[300]$ git ls-files '*urls.txt'
Documentation/urls.txt
[master] ~/srcs/git[301]$ cd t
[master] ~/srcs/git/t[302]$ git locate urls.txt
Documentation/urls.txt
[master] ~/srcs/git/t[303]$ git ls-files '*urls.txt'
[master] ~/srcs/git/t[304]$
Yes, aliases with "!" are executed from the root of the worktree,
ls-files from the current wd.

Michael

Re: git locate

From: Štěpán Němec <hidden>
Date: 2016-06-15 22:48:04

On Thu, Jan 21, 2010 at 09:11:20AM +0900, SungHyun Nam wrote:
Hello,

Johannes Schindelin wrote:
quoted
On Tue, 19 Jan 2010, Jakub Narebski wrote:
quoted
Johannes Schindelin[off-list ref]  writes:
quoted
On Wed, 20 Jan 2010, John Tapsell wrote:
quoted
  Could we add a:  git locate<filename>        or git find<filename>
How about "git ls-files \*<filename>"?
Or "git ls-files '*filename'...

... but how to make an (git) alias for this?
Add something like this to your $HOME/.gitconfig:

[alias]
        locate = !sh -c 'git ls-files "\\*$1"' -
The alias 'git locate' and the command 'git ls-files' runs
differently if I run them in a subdirectory.
Is it expected?

[master] ~/srcs/git[299]$ git locate urls.txt
Documentation/urls.txt
[master] ~/srcs/git[300]$ git ls-files '*urls.txt'
Documentation/urls.txt
[master] ~/srcs/git[301]$ cd t
[master] ~/srcs/git/t[302]$ git locate urls.txt
Documentation/urls.txt
[master] ~/srcs/git/t[303]$ git ls-files '*urls.txt'
[master] ~/srcs/git/t[304]$
Yeah, as stated in another part of the Wiki page Dscho referred to
(namely the "Serve repo on the spot" section):

"It makes use of the fact that (currently, as of git 1.5.6.1) non-git
alias are executed from the top-level dir of a repo."

("non-git" == those starting with "!", which is the case here)


    Štěpán

Re: git locate

From: Sverre Rabbelier <hidden>
Date: 2016-06-15 22:48:16

Heya,

On Thu, Jan 21, 2010 at 01:11, SungHyun Nam [off-list ref] wrote:
The alias 'git locate' and the command 'git ls-files' runs
differently if I run them in a subdirectory.
Is it expected?
I just ran into this (I wanted to alias 'git find' but to me the 'run
ls-files from cwd' is desirable. Also, I prefer to have a trailing
glob as well, so I added one :). An easy solution is to drop
'git-find' in your path somewhere:

sverre@laptop-sverre:~/bin$ cat git-find
#!/bin/bash

git ls-files "*$1*"

-- 
Cheers,

Sverre Rabbelier

Re: git locate

From: John Tapsell <hidden>
Date: 2016-06-15 22:48:53

On 15 February 2010 22:20, Sverre Rabbelier [off-list ref] wrote:
Heya,

On Thu, Jan 21, 2010 at 01:11, SungHyun Nam [off-list ref] wrote:
quoted
The alias 'git locate' and the command 'git ls-files' runs
differently if I run them in a subdirectory.
Is it expected?
I just ran into this (I wanted to alias 'git find' but to me the 'run
ls-files from cwd' is desirable. Also, I prefer to have a trailing
glob as well, so I added one :). An easy solution is to drop
'git-find' in your path somewhere:
I have finally settled on:

[alias]
    locate = !sh -c 'git ls-files | grep --color=auto "$1"' -

This acts as if there is a leading and trailing wildcard, and also
colors the output nicely.

Can we add this as default please?  There didn't seem to be any
resistance in this thread to making it default, just that nobody did
it :)

John

Re: git locate

From: John Tapsell <hidden>
Date: 2016-06-15 22:48:54

On 2 June 2010 14:00, John Tapsell [off-list ref] wrote:
On 15 February 2010 22:20, Sverre Rabbelier [off-list ref] wrote:
quoted
Heya,

On Thu, Jan 21, 2010 at 01:11, SungHyun Nam [off-list ref] wrote:
quoted
The alias 'git locate' and the command 'git ls-files' runs
differently if I run them in a subdirectory.
Is it expected?
I just ran into this (I wanted to alias 'git find' but to me the 'run
ls-files from cwd' is desirable. Also, I prefer to have a trailing
glob as well, so I added one :). An easy solution is to drop
'git-find' in your path somewhere:
I have finally settled on:

[alias]
   locate = !sh -c 'git ls-files | grep --color=auto "$1"' -

Actually could someone help me with this.. the trouble is that this
returns paths relative to the root.

Can I get it to find all the files, but relative to where I am now?

John

Re: git locate

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:48:54

On Wed, Jun 2, 2010 at 12:02 PM, John Tapsell [off-list ref] wrote:
On 2 June 2010 14:00, John Tapsell [off-list ref] wrote:
quoted
On 15 February 2010 22:20, Sverre Rabbelier [off-list ref] wrote:
quoted
Heya,

On Thu, Jan 21, 2010 at 01:11, SungHyun Nam [off-list ref] wrote:
quoted
The alias 'git locate' and the command 'git ls-files' runs
differently if I run them in a subdirectory.
Is it expected?
I just ran into this (I wanted to alias 'git find' but to me the 'run
ls-files from cwd' is desirable. Also, I prefer to have a trailing
glob as well, so I added one :). An easy solution is to drop
'git-find' in your path somewhere:
I have finally settled on:

[alias]
   locate = !sh -c 'git ls-files | grep --color=auto "$1"' -

Actually could someone help me with this.. the trouble is that this
returns paths relative to the root.

Can I get it to find all the files, but relative to where I am now?
Make it a git command, not an alias. You'll then be fine. put
git-locate somewhere in your $PATH

--<--
#!/bin/sh
git ls-files | grep --color=auto "$1"
--<--

Of course you need to chmod u+x for it.
-- 
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help