er? pwd is the wrong thing (as in point 2.) I don't want the current working directory, necessarily, since the value I need may be 4 or 5 directories up.
you can use realpath and basename to get the name of the current directory in its parent. If you need to enumerate everything under a path, you can do 'find path'. If you want just the files, 'find path -type f' just the directories is 'find path -type d' and so on. Consider:
cd ~/src/api/branches for branch in *; do find $branch -type f | xargs wc -l | sort -n done
ETA: I'm not quite certain what it is you want. Tell me what your directory structure is like and the commands that you want run on what parts of those directories (an example or two, maybe) and I'll be glad to point you in an actually-useful direction :)
Okay. The directories in question look like this: /home/alacensk/src/api/branches/API-1033 ~/src/api/branches/API-1035 ~/src/api/branches/RMX-3043
and so on (each branch corresponds to a ticket in a ticketing system. inefficient? maybe.)
Assuming I am working in API-1033, say my current $PWD is /home/alacensk/src/api/branches/API-1033/tools/templates. I would like to be able to type glimpse "something" and have glimpse consult an index built just for /API-1033. Since I add new working copy directories frequently, I do not want to have to manually add each new path within /branches as a glimpse path. I was just getting tired of having to remember find syntax (since it's mostly full text searching) and my boss suggested glimpse.
I'm a little slow today so I'm may be misunderstanding exactly what you're looking for.
Based on the latter portion of 2) it sounds like you want to have a "current reference path", say, ~/src/api/branches/CURRENT and you'll be working in a subdirectory of that, say, ~/src/api/branches/CURRENT/foo/tools/templates/, and you want to know what top-level subdirectory under the reference path you're currently in. Is this correct?
well, in my example, I meant that "foo" as a directory would be one possible location for CURRENT, and "bar" would be another, and I guess that means that the "current reference path" would in fact be /branches, but yes.
The reason for this is that I want to auto-generate glimpse indices for everything in the reference path. Separate ones. /foo/ and /bar/, being two different svn checkouts of the same repository, are going to have very similar files, and I want to be able to search only the index for the branch that covers my current location.
So you need to do two things, sounds like. The first is to enumerate the directories under ~/src/api/branches (such as CURRENT, MY_BRANCH, etc) and invoke glimpse on each of them.
Something like the following would make a separate glimpse index for each entry under ~/src/api/branches
for x in ~/src/api/branches/*; do glimpseindex -other-options -H "$x" "$x" end
That will store the glimpse index of ~/src/api/branches/CURRENT in ~/src/api/branches/CURRENT/.glipmse_etc
The second part is to have some way of pointing glimpse automatically to the .glimpse files corresponding to the branch you're currently somewhere inside.
No promises as to whether this works, but this is supposed to walk up the directory tree until it finds a file matching .glimpse, then runs glimpse with whatever args you pass to it:
glimpsethis.sh: #!/bin/sh
pushd . >& /dev/null while [ ! -e .glimpse* -a "$PWD" != / ]; do cd ..; done GLIMPSEDIR=$PWD popd >& /dev/null echo glimpse -H "$GLIMPSEDIR" "$@"
Comments 19
Reply
Reply
Reply
Reply
cd ~/src/api/branches
for branch in *; do
find $branch -type f | xargs wc -l | sort -n
done
ETA: I'm not quite certain what it is you want. Tell me what your directory structure is like and the commands that you want run on what parts of those directories (an example or two, maybe) and I'll be glad to point you in an actually-useful direction :)
Reply
/home/alacensk/src/api/branches/API-1033
~/src/api/branches/API-1035
~/src/api/branches/RMX-3043
and so on (each branch corresponds to a ticket in a ticketing system. inefficient? maybe.)
Assuming I am working in API-1033, say my current $PWD is /home/alacensk/src/api/branches/API-1033/tools/templates. I would like to be able to type glimpse "something" and have glimpse consult an index built just for /API-1033. Since I add new working copy directories frequently, I do not want to have to manually add each new path within /branches as a glimpse path. I was just getting tired of having to remember find syntax (since it's mostly full text searching) and my boss suggested glimpse.
Reply
ETA: qijim has beaten me to remembering how glimpse works, and sounds correct based on what I've read just now.
Reply
Reply
Based on the latter portion of 2) it sounds like you want to have a "current reference path", say, ~/src/api/branches/CURRENT and you'll be working in a subdirectory of that, say, ~/src/api/branches/CURRENT/foo/tools/templates/, and you want to know what top-level subdirectory under the reference path you're currently in. Is this correct?
Reply
The reason for this is that I want to auto-generate glimpse indices for everything in the reference path. Separate ones. /foo/ and /bar/, being two different svn checkouts of the same repository, are going to have very similar files, and I want to be able to search only the index for the branch that covers my current location.
Reply
Something like the following would make a separate glimpse index for each entry under ~/src/api/branches
for x in ~/src/api/branches/*; do
glimpseindex -other-options -H "$x" "$x"
end
That will store the glimpse index of ~/src/api/branches/CURRENT in ~/src/api/branches/CURRENT/.glipmse_etc
Reply
No promises as to whether this works, but this is supposed to walk up the directory tree until it finds a file matching .glimpse, then runs glimpse with whatever args you pass to it:
glimpsethis.sh:
#!/bin/sh
pushd . >& /dev/null
while [ ! -e .glimpse* -a "$PWD" != / ]; do cd ..; done
GLIMPSEDIR=$PWD
popd >& /dev/null
echo glimpse -H "$GLIMPSEDIR" "$@"
Reply
Reply
Leave a comment