[Discuss] efficiently changing directories?
noel at natnix.com
noel at natnix.com
Wed Aug 8 13:59:21 PDT 2007
Hi Daniel,
My favourite kind of question! How about a script like this?
~Noel
---------------------------- snip -----------------------
#! /bin/sh
# NAME
#
# pcd.sh - look for a directory by prepending paths in CD_PATH
#
# SYNOPSYS
#
# # in your ~/.profile
# # set a list of commonly-used directories to search
# export CD_PATH=~/my_projects:my_other_directory
# # make a function to use pcd.sh to find a directory to cd to using pcd.sh
# pcd() { cd $(pcd.sh "$1"); }
#
# # on the command-line
# $ pcd mydirectory
#
#
# DESCRIPTION
#
# This echoes the first path that is a directory by checking:
#
# 1. its first argument itself
#
# 2. its first argument with a directory from the CD_PATH environment
# variable prepended
#
# The idea is to make a shell utility that you can use to jump to
# subdirectories in commonly-used directories.
#
# AUTHOR
#
# Noel Burton-Krahn <noel at burton-krahn.com>
# Aug 8, 2007
#
#
dir="$1"
IFS=":;"
for p in "" $CD_PATH; do
if [ "$p" ]; then
t="$p/$dir"
else
t="$dir"
fi
if [ -d "$t" ]; then
echo "$t"
exit 0
fi
done
echo "$dir"
---------------------------- snip -----------------------
On Thu, Aug 02, 2007 at 09:54:39PM -0700, Daniel M German wrote:
>
> Hi everybody,
>
> as time passes by my directory structures grow bigger and bigger.
> Does anybody know of a utility or method to change directories easily?
>
> I used to use tcsh and it had a nice feature (which I have totally
> forgotten what its name was) to specify a set of directories where cd will
> try to find a directory if it did not exist in the current path.
>
> While I was writing this I found that it also exists in bash, and
> enabled it (CDPATH). I should have read this part of the man page long
> time ago!
>
> Yet, I am curious to know, are there any utilities that people use to
> quickly move to directories (other than writing aliases)?
>
>
>
> --
> Daniel M. German
> http://turingmachine.org/
> http://silvernegative.com/
> dmg (at) uvic (dot) ca
> replace (at) with @ and (dot) with .
> _______________________________________________
> Discuss mailing list
> Discuss at vlug.org
> http://ladybug.vlug.org/cgi-bin/mailman/listinfo/discuss
More information about the Discuss
mailing list