📄 globash.rc
字号:
esac com="cat $MARKER | $filter | cat -n" eval $com fi ;; -edit|-edi|-ed|-e) ${EDITOR-vi} $MARKER;; "") __gtags_add_maker;; *) __gtags_edit_marked_file $1;; esac}############################################################################ Completion manager###########################################################################__gtags_completion(){ local cur fflag sflag xflag cur=${COMP_WORDS[COMP_CWORD]} fflag=0 sflag=0 case $1 in f) fflag=1;; s) sflag=1;; global) for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do case ${COMP_WORDS[i]} in --file) fflag=1;; --symbol) sflag=1;; --*) ;; -*s*) sflag=1;; -*f*) fflag=1;; esac done ;; esac COMPREPLY=() if [ $sflag = 1 ]; then COMPREPLY=(`global -cs $cur 2>/dev/null`) elif [ $fflag = 1 ]; then COMPREPLY=( $(compgen -f $cur) ) else COMPREPLY=(`global -c $cur 2>/dev/null`) fi return 0}complete -F __gtags_completion globalcomplete -F __gtags_completion xcomplete -F __gtags_completion rcomplete -F __gtags_completion scomplete -F __gtags_completion f############################################################################ Main###########################################################################__gtags_gen_xref(){ # # Globash doesn't refer GTAGSLIBPATH environment variable. # local GTAGSLIBPATH= if [ "$1" != "" ]; then __gtags_lastcom=$1 if [ "$2" != "" ]; then __gtags_lasttag=$2 fi if [ "$__gtags_lasttag" != "" ]; then case $__gtags_lastcom in f) sortfilter=cat;; *) sortfilter='gnusort -k 1,1 -k 3,3 -k 2,2n';; esac com="global -xn$__gtags_lastcom $__gtags_lasttag | $sortfilter >$XREF" eval $com __gtags_count=`wc -l < $XREF | sed 's/ //g'` else echo "tag not specified." return 1 fi elif [ "$__gtags_count" = "" ]; then __gtags_count=1 fi}__gtags_list_xref(){ local com filter if [ ! -s $XREF ]; then return 1 fi case $__gtags_lastcom in f) filter=`global --filter -f`;; *) filter=`global --filter -x`;; esac case $filter in '') echo "Cannot get internal filter." return 1;; esac com="cat $XREF | $filter | cat -n | sed '${__gtags_current}s/^ />/'" if (( __gtags_count > LINES - 1 )); then local pager=${PAGER-more} case $pager in '') pager=more;; less*) pager="$pager +$__gtags_current";; esac com="$com | $pager" fi eval $com return 0}__gtags_locate_tag() { case "$2$__gtags_lasttag" in '') echo "tag not specified." return 1;; esac __gtags_push_stack __gtags_current=1 __gtags_gen_xref $1 $2 __gtags_list_xref}x() { __gtags_locate_tag x $1; }r() { __gtags_locate_tag r $1; }s() { __gtags_locate_tag s $1; }g() { __gtags_locate_tag g $1; }I() { __gtags_locate_tag I $1; }P() { __gtags_locate_tag P $1; }f() { local absolute if [ "$1" = "" ]; then if [ "$__gtags_prev_file" = "" ]; then echo "file not specified." return 1 fi absolute=$__gtags_prev_file else absolute=`__gtags_pwd`/$1 fi if [ ! -f $absolute ]; then echo "file not found." return 1 fi __gtags_prev_file=$absolute __gtags_push_stack __gtags_current=1 __gtags_gen_xref f $absolute __gtags_list_xref}list() { __gtags_list_xref}tags() { if [ -s $XREF ]; then cat <( cat $XREF | sed -n "${__gtags_current}p" ) $STACK | cat -n | sed '1s/^ />/' elif [ -s $STACK ]; then echo | cat - $STACK | cat -n | sed '1s/^ />/' fi}pop(){ if __gtags_pop_stack $1; then __gtags_gen_xref $__gtags_lastcom $__gtags_lasttag __gtags_list_xref elif (( ${#__gtags_stack[@]} == 0 )); then echo "The tags stack is empty." return 1 else echo "Too many pop count." return 1 fi return 0}__gtags_view_tag() { if [ ! -s $XREF ]; then echo "The tags stack is empty." return 1 fi if __gtags_is_num $1; then if (( $1 >= 1 && $1 <= __gtags_count )); then __gtags_current=$1 elif (( $1 < 0 )); then (( __gtags_current = $__gtags_count + 1 )) (( __gtags_current += $1 )) if (( __gtags_current < 1 )); then __gtags_current=1 fi else echo "Tag entry not found in this group." return 1 fi else case $1 in first) __gtags_current=1;; last) __gtags_current=$__gtags_count;; next) if (( __gtags_current == __gtags_count )); then echo "Already at the last tag of this group." return 1 fi if __gtags_is_num $2; then (( __gtags_current += $2 )) else (( __gtags_current += 1 )) fi if (( __gtags_current > __gtags_count )); then __gtags_current=$__gtags_count fi ;; prev) if (( __gtags_current == 1 )); then echo "Already at the first tag of this group." return 1 fi if __gtags_is_num $2; then (( __gtags_current -= $2 )) else (( __gtags_current -= 1 )) fi if (( __gtags_current < 1 )); then __gtags_current=1 fi ;; '') ;; *) echo "Please type 'ghelp'." return 1 ;; esac fi # 'show -n 1' doesn't invoke any editor. if [ "${EDITOR}" = "noedit" ]; then return 0 fi local filter=`global --filter -x` if [ "$filter" != "" ]; then local com="sed -n '${__gtags_current}p' $XREF | $filter" local line=$( eval $com ) set $line ${EDITOR-vi} +$2 $3 fi return 0}first() { case $1 in -*) show $1 first;; *) show first;; esac}last() { case $1 in -*) show $1 last;; *) show last;; esac}next() { case $1 in -*) show $1 next $2;; *) show next $2;; esac}prev() { case $1 in -*) show $1 prev $2;; *) show prev $2;; esac}show() { case $1 in -*) case $1 in -v|-vi) local EDITOR=vi; shift;; -l|-less) local EDITOR=less; shift;; -e|-emacs) local EDITOR='emacsclient --no-wait'; shift;; -g|-gozilla) local EDITOR=gozilla; shift;; -n|-noedit) local EDITOR=noedit; shift;; *) echo "invalid option $1." return 1;; esac ;; esac case $1 in next|prev) __gtags_view_tag $1 $2;; *) __gtags_view_tag $1;; esac}############################################################################ Help###########################################################################ghelp() { echo echo "GloBash --- Global facility for Bash" echo echo "Copyright (c) 2001, 2002 Tama Communications Corporation" echo "GLOBAL WWW: http://www.gnu.org/software/global/" echo echo "Prompt:" echo echo "[/usr/src/sys]/kern _" echo "means \"/usr/src/sys/kern\" is current directory and" echo "\"/usr/src/sys\" is GTAGSROOT." echo echo "[/usr/src/sys]!/tmp _" echo "means environment variable GTAGSROOT is set to \"/usr/src/sys\"" echo "and \"/tmp\" is current directory." echo echo "Commands:" echo echo " - Tag search command:" echo " x [pattern] - locate function definitions." echo " r [pattern] - locate function references." echo " s [pattern] - locate other symbols." echo " g [pattern] - locate pattern using grep(1)." echo " P [pattern] - locate file include pattern." echo " I [pattern] - locate pattern using id-utils(1)." echo " f [file] - locate function definitions in a file." echo " (By default, the previous value is used for pattern and file.)" echo " list - print tag list." echo " tags - print tag stack." echo echo " * The x, r and s command doesn't refer to GTAGSLIBPATH." echo " Use global -x, -r or -s, instead." echo echo " - Tag selection command:" echo " You can specify a editor statically by EDITOR environment" echo " variable or temporarily by option." echo " (-l: less, -v: vi, -e: emacs, -g:gozilla, -n: no editor)" echo " show [-l|-v|-e|-g|-n][<no>|first|last]" echo " - view specified (default=current) tag." echo " first [-l|-v|-e|-g|-n]" echo " - view the first tag." echo " last [-l|-v|-e|-g|-n]" echo " - view the last tag." echo " next [-l|-v|-e|-g|-n][<no>]" echo " - view nth (default=1) next tag." echo " prev [-l|-v|-e|-g|-n][<no>]" echo " - view nth (default=1) previous tag." echo echo " - Tag marker command:" echo " You can move to the marked tag even if there is no stack." echo " mark - mark current tag." echo " mark -l - print marker list." echo " mark -e - edit marker list." echo " mark <no> - edit marked file." echo echo " - Cookie command:" echo " Once you drop cookie, you can warp to the place at any time." echo " cookie - drop cookie." echo " cookie -l - print cookie list." echo " cookie -e - edit cookie list." echo " cookie <no> - warp to the specified cookie." echo " warp [<no>] - warp to the specified (default=1) cookie." echo echo " - Other commands:" echo " ghelp - you are seeing now." echo echo " - Standard aliases:" echo " <n> (n=1-999) - show <n>" echo " .., ../.., ... - cd .., cd ../.., ..." echo " ..<n> (n=1-5) - cd .. (* <n> times)" echo " l,t,n,p,.,c,m - list,tags,next,prev,show,cookie,mark" echo " '\C-t' - pop" echo echo "For the details, read the script." }## Run private command script.#gtags_aliases=1if [ -n "$HOME_ETC" ]; then home=$HOME_ETCelse home=$HOMEfiif [ -f $home/.globashrc ]; then source $home/.globashrcfi## Aliases#if [ "$gtags_aliases" = "1" ]; then n=1 while (( n < 1000 )); do alias $n="show $n" (( n++ )) done alias ..='cd ..' alias ../..='cd ../..' alias ../../..='cd ../../..' alias ../../../..='cd ../../../..' alias ../../../../..='cd ../../../../..' alias ..1='cd ..' alias ..2='cd ../..' alias ..3='cd ../../..' alias ..4='cd ../../../..' alias ..5='cd ../../../../..' alias l=list alias t=tags alias n=next alias p=prev alias .=show alias c=cookie alias m=mark bind '\C-t": "pop\n"'fi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -