File: geco.rc

package info (click to toggle)
global 6.6.4-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 18,308 kB
  • sloc: ansic: 39,547; javascript: 4,891; sh: 4,674; perl: 811; lisp: 696; makefile: 332; python: 213; yacc: 122
file content (159 lines) | stat: -rw-r--r-- 4,102 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#
# Geco --- A quick view tool for GLOBAL using bash, percol and less
#
# Copyright (c) 2014, 2016 Tama Communications Corporation
# 
# This file is part of GNU GLOBAL.
#
# 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 3 of the License, 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#
# GLOBAL home page is at: http://www.gnu.org/software/global/
# Author: Tama Communications Corporation
# 
# Geco is a quick view tool for GLOBAL using percol and less.
# It is useful as a launch pad for vi editor.
#
# Features:
# o Command line input completion using __geco_completion()
# o Tag selection using percol, peco or fzf
# o File viewing using less
#
# Required:
# o Bash
# o Percol, peco or fzf
# o Less
#
# Installation:
# $ source /usr/local/share/gtags/geco.rc
#
# usage:
# geco <options> <tag>
#
# $ geco mai[TAB] -> main		# input completion
# $ geco main [ENTER]
# QUERY> _				# tag selector
# main              360 global/global.c  main(int argc, char **argv)
# main              197 gozilla/gozilla.c main(int argc, char **argv)
# main              145 gtags-cscope/gtags-cscope.c main(int argc, char **argv)
# ...
# v
# +---------------------------------
# |main(int argc, char **argv)		# show a selected location
# |{
# |        const char *av = NULL;
# |        int db;
# ...
# |[global/global.c]
# +---------------------------------
# v
# Commands in less.
# 't': go to next tag
# 'T': goto previous tag
# 'v': load vi editor
# 'q': quit less
# ':t': => tag: <options> <tag>
#
# Geco's <options> is almost compatible with global(1).
#
# $ geco --help
#
# Just gecoless is also available.
#
# $ global -x main | gecoless
#
__gtags_global_command=${GTAGSGLOBAL-global}
__gtags_geco_viewer=less
__gtags_geco_selector=
export LESSGLOBALTAGS=$(gtags --conf=datadir)/gtags/script/less-global
export LESS=-TGTAGS
__gtags_geco_selectors_list='percol peco fzf'	# Default list
if [ "$GECO_SELECTORS" != "" ]; then
	__gtags_geco_selectors_list=$GECO_SELECTORS
fi
for name in $__gtags_geco_selectors_list; do
	path=$(type -p $name)
	case $path in
	'')	;;
	*)	__gtags_geco_selector=$path
		break;;
	esac
done
gecoless()
{
	local line IFS=
	case $__gtags_geco_selector in
	'')	echo "geco: percol, peco or fzf is required."
		return 1;;
	esac
	line=$(cat)
	if [ "$line" != "" ]; then
		echo $line | "$__gtags_geco_selector" | "$__gtags_geco_viewer" -T- 
	else
		echo "No such tag in tags file"
		return 1
	fi
}
geco()
{
	local arg GTAGSBLANKENCODE=
	for a in "$@"; do
		case $a in
		-*)	;;
		*)	arg=$a;;
		esac
	done
	case $arg in
	'')	"$__gtags_global_command" 2>&1 | sed -e '/global -p\[/d' -e '/global -u\[/d' -e 's/global/geco/'
		return 1;;
	esac
	export GTAGSBLANKENCODE
	"$__gtags_global_command" "$@" --result=ctags-x | gecoless
}
__geco_completion()
{
	local file flags i
	local prefix="${COMP_WORDS[COMP_CWORD]}"

	for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
		local opt=${COMP_WORDS[i]}
		case $opt in
		--definition)	flags="${flags}d";;
		--file)		file=1;;
		--idutils)	flags="${flags}I";;
		--ignore-case)	flags="${flags}i";;
		--only-other)	flags="${flags}O";;
		--other)	flags="${flags}o";;
		--path)		flags="${flags}P";;
		--reference)	flags="${flags}r";;
		--symbol)	flags="${flags}s";;
		--*)		;;
		-*)
			case $opt in
			-*f*)	file=1;;
			esac
			for c in d I i O o P r s; do
				case $opt in
				-*$c*)	flags="$flags$c";;
				esac
			done;;
		esac
	done
	if [ "$file" = 1 ]; then
		COMPREPLY=($(compgen -f $prefix 2>/dev/null))
	else
		COMPREPLY=($("$__gtags_global_command" -c$flags $prefix 2>/dev/null))
	fi
	return 0
}
complete -F __geco_completion geco global