⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 globash.rc

📁 代码检索工具GLOBAL源码。可用来浏览分析LINUX源码。
💻 RC
📖 第 1 页 / 共 2 页
字号:
## GloBash --- Global facility for Bash## Copyright (c) 2001, 2002, 2004 Tama Communications Corporation## This file is part of GNU GLOBAL.## GNU GLOBAL 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.## GNU GLOBAL 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 this program; if not, write to the Free Software# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.## GLOBAL home page is at: http://www.gnu.org/software/global/# Author: Tama Communications Corporation  version=0.1# Usage:# $ bash --rcfile <this file># [/usr/src/sys] ghelp<RET>#bash_minorversion=$(echo ${BASH_VERSINFO[1]} | sed 's/[^0-9]//')if !(( BASH_VERSINFO[0] > 2 || BASH_VERSINFO[0] == 2 && 10#${bash_minorversion} >= 4 )); then	echo "GLOBASH ERROR: GloBash needs Bash version 2.04 or later."	exit 1fiunset bash_minorversion############################################################################ Global variables and utilities.############################################################################## Working directory## The HOME_ETC environment variable is used by home-etc facility# in PLD Linux/GNU. Globash obey this method if the variable defined.#if [ -n "$HOME_ETC" ]; then        GHOME=$HOME_ETC/.globashelse        GHOME=$HOME/.globashfiif [ ! -d $GHOME ]; then	echo	echo "GloBash --- Global facility for Bash"	echo	echo "GloBash needs working directory."	echo	echo -n "Create '$GHOME'? ([y]/n) "	while read ans; do		case $ans in		Y|y|"")			if mkdir $GHOME; then				break			else				echo "GLOBASH ERROR: Cannot make '$GHOME' directory."				exit 1			fi			;;		N|n)	echo "Bye ..."; exit 1;;		esac	done	echo	echo "Created."	echo	echo "Welcome to Globash! When you need help, please type 'ghelp'."	echoelse	echo "When you need help, please type 'ghelp'."fi## Temporary file definitions:## When exiting shell, temporary files are removed.# We should be careful not to remove other files.#declare -r XREF=$GHOME/xref-$$			# global's outputdeclare -r STACK=$GHOME/stack-$$		# stack for tags commanddeclare -r MARKER=$GHOME/marker-$$		# markerdeclare -r TMP1=$GHOME/tmp1-$$			# temporary file__gtags_clean() {	if [ -n "$HOME_ETC" ]; then		home=$HOME_ETC	else		home=$HOME	fi	for d in $XREF $STACK $MARKER $TMP1; do		case $d in		$home/.globash/*-$$) rm -f $d;;		esac	done}builtin trap 'status=$?; __gtags_clean; exit $status' 0cp /dev/null $XREFcp /dev/null $STACKcp /dev/null $MARKERcp /dev/null $TMP1__gtags_stack=()			# tag stack__gtags_lasttag=			# last tag__gtags_lastcom=			# last command__gtags_current=			# current tag number__gtags_prev_file=__gtags_prev_root=### Cookie managementdeclare -r COOKIE=$GHOME/cookie		# cookie in file#cp /dev/null $COOKIE # Cookie file is used over sessions. Don't clean.__gtags_cookie=()			# cookie in memory### Utilities# true: is number, false: is not number__gtags_is_num() {	echo $1 | grep '^[-]*[0-9][0-9]*$' >/dev/null}############################################################################ Tag stack manager###########################################################################__gtags_init_stack(){	cp /dev/null $XREF	cp /dev/null $STACK	__gtags_stack=()			# tag stack	__gtags_lasttag=	__gtags_lastcom=	__gtags_current=	__gtags_prev_file=}__gtags_resume(){	local IFS=','	if [ "$1" != "" ]; then		set $1		__gtags_lastcom=$1		__gtags_lasttag=$2		__gtags_current=$3	fi}__gtags_push_stack(){	if (( __gtags_current > 0 )); then		if [ -s $XREF ]; then			cat $XREF | sed -n "${__gtags_current}p" | cat - $STACK >$TMP1		else			echo | cat - $STACK >$TMP1		fi		cp $TMP1 $STACK		__gtags_stack=( "$__gtags_lastcom,$__gtags_lasttag,$__gtags_current" ${__gtags_stack[@]} )	fi	return 0}__gtags_pop_stack(){	local size=${#__gtags_stack[@]}	local count pop	if __gtags_is_num $1 && [ $1 -gt 0 ]; then		count=$1	else		count=1	fi	if [ $size -eq 0 ] && [ "$__gtags_lastcom" != "" ]; then		__gtags_init_stack		return 0	fi	if [ $size -eq 0 ]; then		return 1;	fi	if (( size + 1 - count < 0 )); then		return 1	fi	if (( size + 1 - count == 0 )); then		__gtags_init_stack		return 0		fi	(( pop = count - 1 ))	__gtags_resume ${__gtags_stack[$pop]}	__gtags_stack=( ${__gtags_stack[@]:$count} )	if [ -s $STACK ]; then		(( size -= count ))		if (( size > 0 )); then			tail -$size $STACK >$TMP1			cp $TMP1 $STACK		elif (( size == 0 )); then			cp /dev/null $STACK		fi	fi	return 0}dump(){	echo "*** Current"	echo "__gtags_lasttag	= $__gtags_lasttag"	echo "__gtags_lastcom	= $__gtags_lastcom"	echo "__gtags_current	= $__gtags_current"	echo "*** Stack"	local __gtags_lastcom __gtags_lasttag __gtags_current	for (( i=0; i < ${#__gtags_stack[@]}; i++ )); do		__gtags_resume ${__gtags_stack[i]}		echo "$i	__gtags_lastcom=$__gtags_lastcom, __gtags_lasttag=$__gtags_lasttag, __gtags_current=$__gtags_current"	done}############################################################################ Directory manager############################################################################## Customized cd__gtags_pwd() {	# always use /bin/pwd to ignore symbolic links.	/bin/pwd}__gtags_prompt() {	local cwd=`__gtags_pwd`	local root=`global -pr 2>/dev/null`	local ps	if [ "$root" ] && echo $cwd | grep "^$root" >/dev/null; then		local path=`echo $cwd | sed "s!^$root!!"`		ps="[$root]$path"	elif [ "$root" ]; then		ps="[$root]!$cwd"	else		ps=$cwd	fi	# We cannot keep context (except for cookies) across projects.	if [ "$__gtags_prev_root" ] && [ "$__gtags_prev_root" != "$root" ]; then		msg="You are going to get out of current project."		yesno="Tag stack and marker will be removed. Sure? ([y]/n) "		echo $msg		echo -n $yesno		while read ans; do			case $ans in			""|Y|y)				break;;			N|n)				builtin cd -				return;;			*)	echo $msg				echo -n $yesno;;			esac		done		__gtags_init_stack		cp /dev/null $MARKER	fi	PS1="$ps "	__gtags_prev_root=$root}cd() {	builtin cd $*	__gtags_prompt}pushd() {	builtin pushd $*	__gtags_prompt}popd() {	builtin popd $*	__gtags_prompt}__gtags_promptif [ "$__gtags_prev_root" = "" ]; then	# we cannot find tag files (GTAGS).	echo "Warning: Out of project."fi### Cookie__gtags_load_cookie(){	if [ -s $COOKIE ]; then		__gtags_cookie=( $(cat $COOKIE) )	else		__gtags_cookie=()	fi}__gtags_save_cookie(){	for dir in ${__gtags_cookie[@]}; do		echo $dir	done > $COOKIE}__gtags_add_cookie(){	__gtags_load_cookie	for a in ${__gtags_cookie[@]}; do		if [ "$a" = "$1" ]; then			return 1		fi	done	__gtags_cookie=( $1 ${__gtags_cookie[@]} )	__gtags_save_cookie}__gtags_select_cookie() {	local selection	if [ ! -s $COOKIE ]; then		echo "Cookie not found."		return 1	fi	select selection in `cat $COOKIE`; do		if [ $selection ]; then			break		else			echo "Invalid selection."			return 1		fi	done	cd $selection	return 0}__gtags_warp_cookie() {	__gtags_load_cookie	local size=${#__gtags_cookie[@]}	local n	if __gtags_is_num $1; then		if [ $1 -gt 0 -a $1 -le $size ]; then			n=$1		else			echo "Out of range."			return 1		fi	else		case $1 in		first|f)			n=1;;		last|l)			n=$size;;		'')	n=1;;		*)	echo "Such cookie not found."			return 1			;;		esac	fi	(( --n ))	cd ${__gtags_cookie[$n]}	return 0}cookie() {	case $1 in	-list|-lis|-li|-l)		if [ -s $COOKIE ]; then			cat -n $COOKIE		fi;;	-edit|-edi|-ed|-e)		${EDITOR-vi} $COOKIE		case `cat $COOKIE` in		'')	cp /dev/null $COOKIE;;		esac		;;	-menu|-men|-me|-m)		__gtags_select_cookie;;	-warp|-war|-wa|-w)		__gtags_warp_cookie $2;;	"")	# Drop cookie.		__gtags_add_cookie `__gtags_pwd`;;	*)	# Jump to the place where you dropped cookie.		__gtags_warp_cookie $1;;	esac}warp() {	__gtags_warp_cookie $1}############################################################################ Tag marker###########################################################################__gtags_edit_marked_file(){	if [ -s $MARKER ] && __gtags_is_num $1; then		local com filter		filter=`global --filter -x`		case $filter in		'')	echo "Cannot get internal filter."			return 1;;		esac		com="cat $MARKER | $filter | sed -n '${1}p'"		line=$( eval $com )		if [ "$line" != "" ]; then			set $line			${EDITOR-vi} +$2 $3		fi	fi	return 0}__gtags_add_maker(){	if [ "$__gtags_current" = "" ]; then		echo "No current tag."		return 1	fi	if [ -s $XREF ]; then		cat $XREF | sed -n "${__gtags_current}p" >> $MARKER	fi	return 0}mark(){	case $1 in	-list|-lis|-li|-l)		if [ -s $MARKER ]; then			local com filter			filter=`global --filter -x`			case $filter in			'')	echo "Cannot get internal filter."				return 1;;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -