# -*- shell-script -*- # hist.sh - history routines # # Copyright (C) 2002, 2003, 2006, 2007, 2008, 2009, 2011 Rocky Bernstein # # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License along # with bashdb; see the file COPYING. If not, write to the Free Software # Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. _Dbg_help_add history \ "history [N] Rerun a debugger command from the debugger history. See also H to list the history. If N is negative you are you going back that many items from the end rather specifying an absolute history number." proc _Dbg_do_history { typeset -i history_num = '' _Dbg_history_parse $ifsjoin(Argv) _Dbg_history_remove_item if sh-expr ' history_num >= 0 ' { if sh-expr ' history_num < ${#_Dbg_history[@]} ' { set $(_Dbg_history[$history_num]) setglobal _Dbg_cmd = $1 shift setglobal _Dbg_args = @Argv setglobal _Dbg_redo = '1'; } else { _Dbg_errmsg \ "Number $1 ($history_num) should be less than $(#_Dbg_history[@])" return 1 } } return 0 } # Print debugger history $1 is where to start or highest number if not given. # If $1 is negative, it is how many history items. # $2 is where to stop or 0 if not given. proc _Dbg_do_history_list { eval $_seteglob if [[ $1 != $int_pat ]] && [[ $1 != -$int_pat ]] && [[ -n $1 ]] { _Dbg_msg "Invalid history number: $1" eval $_resteglob return 1 } eval $_resteglob setglobal _Dbg_hi = $(#_Dbg_history[@]) var -i n = $(1:-$_Dbg_hi-1) var -i stop = $(2:0) var -i i = '' # Were we given a count rather than a starting history number? if sh-expr ' n<0 ' { sh-expr 'stop=_Dbg_hi+n' sh-expr 'n=_Dbg_hi-1' } elif sh-expr ' n > _Dbg_hi-1 ' { sh-expr 'n=_Dbg_hi-1' } for (( i=n ; i >= stop && i >= 0; i-- )) ; do _Dbg_msg "${i}: ${_Dbg_history[$i]}" done return 0 } _Dbg_alias_add '!' 'history'