Simplified cd history implementation.

This commit is contained in:
k1574 2021-12-16 17:33:16 +05:00
parent 00da83a751
commit 2c873ec77a

29
profile
View file

@ -117,42 +117,39 @@ fn ll {
} }
maxcds = 50
cdfile = $tmp/cdfile cdfile = $tmp/cdfile
if(! test -d `{dirname $cdfile}) mkdir `{dirname $cdfile} if(! test -d `{dirname $cdfile}) mkdir `{dirname $cdfile}
if(! test -r $cdfile) touch $cdfile if(! test -r $cdfile) touch $cdfile
fn ucds { tmpcdfile = `{mktemp}
# Update history.
ifs = '
'
cds = `{tac $cdfile | goblin uniq -U}
ifs = $oldifs
echo > $cdfile
{for(i in $cds) echo $i} | tac >> $cdfile
}
ucds
fn cd { fn c {
# History implementation. # History implementation.
if(builtin cd $1 && test -n $1){ if(builtin cd $1 && test -n $1){
pwd = `{pwd} pwd = `{pwd}
echo $pwd >> $cdfile cat $cdfile > $tmpcdfile
cds = ($pwd $cds) {echo $pwd ; cat $tmpcdfile } | \
sed $maxcds^q | goblin uniq -U > $cdfile
} }
} }
fn cd {
c $*
}
fn - { fn - {
# Move back in history for $1 notes. # Move back in history for $1 notes.
num = $1 num = $1
if(~ $#* 0) if(~ $#* 0)
num = 1 num = 1
builtin cd $cds($num) backcd = `{sed -n $num^p $"cdfile}
builtin cd $backcd
} }
fn cds { fn cds {
# Print history. # Print history.
goblin echo -d ' cat $cdfile | nl >[2]/dev/null
' $cds | nl >[2]/dev/null
} }
fn hcds { fn hcds {