foo as in "pity da"

Dec 30, 2008 16:20

Yargh. Anyone know how to express "this path and everything inside it" as a variable in bash ( Read more... )

Leave a comment

Comments 19

teferi December 30 2008, 21:36:35 UTC
Well, bash(1) says that $PWD always holds the current working directory.

Reply

adularia December 30 2008, 21:38:27 UTC
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.

Reply

teferi December 30 2008, 21:38:59 UTC
gah, yeah, realized that about two minutes after hitting post.

Reply

teferi December 30 2008, 21:40:22 UTC
Oh gah finding the truename of a path is a pain. Thank you so much, unix, for giving us hard links.

Reply


caladri December 30 2008, 21:46:25 UTC
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 :)

Reply

adularia December 30 2008, 22:16:05 UTC
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.

Reply

caladri December 30 2008, 22:22:43 UTC
Is the base path always ~/src/api/branches followed by a directory corresponding to the branch name?

ETA: qijim has beaten me to remembering how glimpse works, and sounds correct based on what I've read just now.

Reply

adularia December 30 2008, 22:27:35 UTC
Yes, and I'm always glad when two people can corroborate each other on anything to do with shell scripting, 'cause I can't.

Reply


qijm December 30 2008, 22:03:53 UTC
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?

Reply

adularia December 30 2008, 22:05:56 UTC
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.

Reply

qijm December 30 2008, 22:15:15 UTC
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

Reply

qijm December 30 2008, 22:29:47 UTC
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" "$@"

Reply


semi sort of related irgth December 31 2008, 00:57:01 UTC
I've never used glimpse, so I can't compare, but I highly recommend ack for text searches of code trees.

Reply


Leave a comment

Up