Thread View: comp.unix.shell
1 messages
1 total messages
Started by J. William Claypool
Thu, 27 Sep 1990 19:51
Re: Pushd, popd, dirs for stock SysV.3 Bourne shell
Author: J. William Claypool
Date: Thu, 27 Sep 1990 19:51
Date: Thu, 27 Sep 1990 19:51
133 lines
3347 bytes
3347 bytes
In article <PCG.90Sep26164749@odin.cs.aber.ac.uk> pcg@cs.aber.ac.uk (Piercarlo Grandi) writes:
>
>You wwill find appended a small shell script that defines under a stock
>System V Bourne shell the pushd, popd, dirs commands of csh(1). They are
>trivially adapted to the Korn shell. I have taken care to make them as
>robust as possible.
Well... since you mentioned it... Here is an implementation of directory
stack for SysV Bourne shell which I've had floating around for a while.
I took a similar approach. I didn't make any attempt to handle space in a
directory name. I believe that it duplicates the full functionality of csh.
It also initializes the directory stack from $HOME/.dirstk if that file is
present.
-------------------- cut here --------------------
dirs(){
case $# in
0) echo `pwd` $dirstk |
sed -e "s;$HOME;~;g" -e 'y/\ /\\n/' |
nl -v0 ;;
1) case $1 in
-l) echo `pwd` $dirstk ;;
*) echo "usage: dirs [ -l ]" ;;
esac ;;
*) echo "usage: dirs [ -l ]" ;;
esac
}
popd(){
case $# in
0) set $dirstk
case $# in
0) echo "popd: Directory stack is empty." ;;
*) if eval cd $1 ; then
shift
dirstk="$*"
dirs
fi
esac ;;
1) case $1 in
+[0-9]|+[0-9][0-9])
cnt=`echo $1 | sed -e 's;+;;'`
set $dirstk
case $cnt in
0|00)
if eval cd $1 ; then
shift
dirstk="$*"
dirs
fi ;;
*) if [ $# -ge $cnt ] ; then
svdirs=
while [ $cnt -gt 1 ] ; do
svdirs="$svdirs $1"
shift
cnt=`expr $cnt - 1`
done
shift
dirstk="$svdirs $*"
dirs
else
echo "popd: Directory stack not that deep."
fi ;;
esac ;;
*) echo "usage: popd [ +n ]" ;;
esac ;;
*) echo "usage: popd [ +n ]" ;;
esac
}
pushd(){
case $# in
0) set $dirstk
case $# in
0) ;;
*) d1=`pwd`
if eval cd $1 ; then
shift
dirstk="$d1 $*"
dirs
fi ;;
esac ;;
1) case $1 in
+[0-9]|+[0-9][0-9])
cnt=`echo $1 | sed -e 's;+;;'`
set $dirstk
if [ $# -ge $cnt ] ; then
svdirs=`pwd`
while [ $cnt -gt 1 ] ; do
svdirs="$svdirs $1"
shift
cnt=`expr $cnt - 1`
done
if eval cd $1 ; then
shift
dirstk="$* $svdirs"
dirs
fi
else
echo "pushd: Directory stack not that deep."
fi
;;
+*) echo "usage: pushd [ +n | <dir> ]" ;;
*) dirstk="`pwd` $dirstk"
if eval cd `echo $1 | sed -e "s;~;$HOME;"` ; then
dirs
else
set $dirstk
shift
$dirstk="$*"
fi ;;
esac ;;
*) echo "usage: pushd [ +n | <dir> ]" ;;
esac
}
svds(){
dirs -l > $HOME/.dirstk
}
if [ -s $HOME/.dirstk ] ; then
dirstk=`cat $HOME/.dirstk`
popd
else
dirstk=
fi
-------------------- cut here --------------------
--
Bill Claypool +1 916 920 1830 x341| I know what I know if you know what I mean
jwc@Unify.Com |--------------------------------------------
...!{csusac,pyramid}!unify!jwc | SCCA SFR Solo II 74 es 1984 CRX 1.5
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads