[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pushd, popd and dirs of different bash processes communicate by an e
From: |
Steven W. Orr |
Subject: |
Re: pushd, popd and dirs of different bash processes communicate by an external file |
Date: |
Fri, 10 Jun 2011 11:46:21 -0400 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 |
On 6/9/2011 11:42 PM, Peng Yu wrote:
Hi,
I'm wondering if there is a way that different bash processes share
the same stack. One way of doing so is to use a file to save the
stack. It is not difficult to implement this function myself, but I'm
just wondering if there is any simpler solution or anybody has done it
already. Thanks!
.dirstack_fns:
#################################################
# directory stack aliases and functions
#
# pd is just pushd and pd[2-9] do pushd's with the numeric value
# ds is dirs, the short dir stack listing
# dl is the long dirstack listing with directory numbers
# sd saves the dirstack in ~/.dirstack for use in another shell or a login
# gd gets the saved directory stack
# dset assigns the current directory to its argument (variable name)
#
# future versions of pushd will label the window with the current
# directory
make_aliases()
{
typeset -i ii=1
alias pd=pushd
for ((ii=1; ii < 20; ii++))
do
alias pd${ii}="pushd +${ii}"
done
alias ds=dirs
alias dl='dirs -v'
alias sd="dirs -l > ~/.bash_dirs"
}
make_aliases
unset -f make_aliases
function dset() {
eval $1=$PWD
}
function gd() {
local readlist
declare -a dir_list
declare -i dir_cnt
declare -i ii
local dir
if [ ! -e ~/.bash_dirs ]
then
echo "~/.bash_dirs does not exist"
return
fi
read readlist < ~/.bash_dirs
set ${readlist}
let dir_cnt=$#-1
let ii=0
while [ ${ii} -le ${dir_cnt} ]
do
dir_list[${ii}]=$1
shift
let ii+=1
done
dir=${dir_list[${dir_cnt}]}
if [ -d "${dir}" ]
then
dirs -c # Clear the stack before reassigning.
builtin cd ${dir}
fi
let dir_cnt-=1
while [ ${dir_cnt} -ge 0 ]
do
dir=${dir_list[${dir_cnt}]}
if [ -d "${dir}" ]
then
builtin pushd ${dir} >/dev/null
fi
let dir_cnt-=1
done
}
--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net