Wednesday, June 22, 2005

A text browser with links --dump

This browser implemets quit (q) , back (b) and url.And a hidden command called 'd' which dumps history.More importantly i use the bash arrays.On L.H.S its HISTORY[$i] where as on R.H.S its ${HISTORY[$i]} and the length of array is ${#HISTORY[@]}...

#!/bin/bash
HISTORY=()
BACKINDEX=0

function updatehistory() {
numvalues=${#HISTORY[@]}
if (( $numvalues < 3 ))
then
HISTORY[$numvalues]=$1
else
index=$(( numvalues -1))
for (( i=0;i<$index;i++))
do
j=$(( i+1))
HISTORY[$i]=${HISTORY[$j]}
done
i=$(( i++))
HISTORY[$i]=$1
fi
}



function dump_history(){

numvalues=${#HISTORY[@]}

for (( i=0; i < $numvalues; i++))
do
echo ${HISTORY[$i]}
done
}

while true
do
echo "Enter a url.q for quit and b for back"
read choice

case $choice in

q) exit ;;

b) BACKINDEX=$(( BACKINDEX+1))
numvalues=${#HISTORY[@]}
INDEX=$(( numvalues - BACKINDEX -1 ))
links -http-proxy proxyserver:8088 -dump ${HISTORY[$INDEX]}
;;

d) dump_history;;

*) links -http-proxy proxyserver:8088 -dump $choice
if (( $? == 0 ))
then
updatehistory $choice
fi
BACKINDEX=0
;;
esac

done

0 Comments:

Post a Comment

<< Home