A shell for fast switching directories under UNIX operating systems

Source: Internet
Author: User

If your directory level is very deep, this shell will be very convenient to switch directly to the destination directory, such as

Current directory/usr/home, and directory Desdir in/usr/home/app/local/opp/william/desdir

Direct penetration

$ CD Desdir, you can switch directly from the current directory/use/home to/usr/home/app/local/opp/william/desdir

Configure. Profile, add two lines

. ./bin/chdir

Alias cd= ' ChDir '

File:chdir

# Auto Find your directory

# Writer:william 2006 Beijing

# Add the following two line in $HOME/.profile

# . ./bin/chdir

# alias cd= ' ChDir '

ChDir ()
{
If [-Z "$"]; Then
Cd
Ps1= "[$PWD]"
Export PS1;
Return
elif ["$" =-]; Then
CD-
Ps1= "[$PWD]"
Export PS1;
Return
Else
If [-D "./$1"]; Then
CD./$1
Ps1= "[$PWD]"
Export PS1;
Return
Fi
Fi

$HOME-type D-print | Grep-c \/$1$ '
Todo
If [$LINE-eq 0]; Then
echo "Your directory is not exsit ($LINE)!"
Return
Fi
Done

For Dir in ' Find $HOME-type d-print | grep \/$1$ '
Todo
If [$LINE-gt 1]; Then
if [!-D "$Dir"]; Then
echo "$Dir is not a directory"
Return
Fi

printf "$Dir \t\t...do you want to go? Default (Y)
Read Yesno
# echo "(y/n) =" $YESNO

If [-Z "$YESNO"]; Then
Yesno=y
Fi

Case "$YESNO" in
[yy]| [YY] [EE] [SS])
Yesno=y;;
[nn]| [NN] [OO])
Yesno=n;;
*)
Yesno= "";;
Esac

If ["$YESNO" = y]; Then
CD $Dir
Ps1= "[$PWD]"
Export PS1;

Return
Else
Continue
Fi
Else
CD $Dir
Ps1= "[$PWD]"
Export PS1;
Return
Fi
Done
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.