- 論壇徽章:
- 1
|
論壇上有朋友問過的問題,見原貼: http://72891.cn/viewthr ... &extra=page%3D2
我在我的redhat上寫了一個,比較粗糙點,望大家給個意見 
#!/bin/bash
#名稱:hist
#BSD風(fēng)格的history命令
#為避免和真正的history命令沖突,可以在/etc/inputrc
#中加入:Control-a:"/path/hist \C-m" //按ctrl+A啟動此history命令
#當(dāng)然,最好別和其他的ctrl組合沖突
#按鍵盤說明:^[[A和^[[B上下翻頁鍵,^[由ctrl+v+[得到
#redhat+bash測試通過 :=)
#得到r2007兄指點,特此感謝! ^_^
#BEGIN
#
echo -ne '\e[6n';read -sdR pos
pos=${pos#*[}
line=${pos%%;*}
col=${pos##*;}
hint='History command list>>'
file="$HOME/.bash_history"
cat $HOME/.bash_history
doo () {
while true;do
echo -ne "\\033[31m\\033[$line;${col}H$hint\\033[0m"
read -s -n3
case $REPLY in
^[[A) echo -en "\\033[A";((i--));echo -ne "\\033[$line;${#hint}H$i=>$(sed -n "$i"p $1)\\033[K"
;;
^[[B) echo -ne "\\033[B";((i++));echo -ne "\\033[$line;${#hint}H$i=>$(sed -n "$i"p $1)\\033[K"
;;
"" echo;eval $(sed -n "$i"p $1) 2>/dev/null;break
;;
esac
done
echo -e "\\033[0m"
}
read -s -n1 char
if [[ -n $char ]];then
sed -n "/^$char/p" $file|tee tmp$$
i=$(sed -n '$=' tmp$$)
doo tmp$$
rm tmp$$ 2>/dev/null
else
i=$(sed -n '$=' $file)
doo $file
fi
#END |
|