File: echo

package info (click to toggle)
yash 2.50-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,036 kB
  • sloc: ansic: 33,211; makefile: 839; sh: 477; sed: 16
file content (101 lines) | stat: -rw-r--r-- 1,779 bytes parent folder | download | duplicates (6)
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
# (C) 2010 magicant

# Completion script for the "echo" built-in command.

function completion/echo {
	command -f completion/echo::option ||
	command -f completion/echo::operand
}

function completion/echo::option {

	case ${ECHO_STYLE-} in
	([BbDd]*)
		typeset options=n
		;;
	([GgZz]*)
		typeset options=neE
		;;
	(*)
		return 1
		;;
	esac

	typeset word
	for word in "${WORDS[2,-1]}"; do
		case $word in
		(-?*)
			case ${word#-} in (*[!$options]*)
				return 1
			esac
			;;
		(*)
			return 1
			;;
		esac
	done
	case $TARGETWORD in (-*)
		case ${TARGETWORD#-} in (*[!$options]*)
			return 1
		esac

		# option completion
		case $options in (*n*) #>>#
			complete -P "$TARGETWORD" -D "don't print the last newline" -O n
		esac #<<#
		case $options in (*e*) #>>#
			complete -P "$TARGETWORD" -D "enable escape sequences" -O e
		esac #<<#
		case $options in (*E*) #>>#
			complete -P "$TARGETWORD" -D "disable escape sequences" -O E
		esac #<<#
		return 0
	esac

	return 1

}

function completion/echo::operand {

	typeset options escape
	case ${ECHO_STYLE-} in
		([Bb]*) options=n   escape=false ;;
		([Dd]*) options=n   escape=true  ;;
		([Gg]*) options=neE escape=false ;;
		([Zz]*) options=neE escape=true  ;;
		([Rr]*) options=    escape=false ;;
		(*)     options=    escape=true  ;;
	esac

	typeset word
	for word in "${WORDS[2,-1]}"; do
		case $word in
		(-?*)
			case ${word#-} in (*[!$options]*)
				break
			esac
			case ${word//n} in
				(*E) escape=false ;;
				(*e) escape=true  ;;
			esac
			;;
		(*)
			break
			;;
		esac
	done

	if $escape; then
		if command -vf completion/printf::backslash >/dev/null 2>&1 ||
				. -AL completion/printf; then
			command -f completion/printf::backslash echo
		fi
	fi

	complete -f

}


# vim: set ft=sh ts=8 sts=8 sw=8 noet: