[Home] Zsh logo

tele

Zsh Wizard

Download tele Return to Examples
  1. #!/bin/zsh
  2. # (c) Dominik Vogt, 12-Jul-1998, domimink.vogt@gmx.de
  3. #
  4. # tele - a (phone) database implemented as a zsh script for zsh 3.0.5. The
  5. # data is part of the script.
  6. #
  7. #
  8. # NOTE: For performance reasons you will find the documentation at the end of
  9. # this script.
  10. #
  11. #
  12. # COPYRIGHT NOTICE:
  13. #
  14. # This program is free software; you can redistribute it and/or modify
  15. # it under the terms of the GNU General Public License as published by
  16. # the Free Software Foundation; either version 2 of the License, or
  17. # (at your option) any later version.
  18. #
  19. # This program is distributed in the hope that it will be useful,
  20. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. # GNU General Public License for more details.
  23. #
  24. # You should have received a copy of the GNU General Public License
  25. # along with this program; if not, write to the Free Software
  26. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. #
  28. ###############################################################################
  29. # customizing section #
  30. ###############################################################################
  31. # reserved words: all, com, nl, lots of variable names in UPPERCASE
  32. ##### default options #####
  33. # Change these if you like.
  34. #DEFAULT_OPTIONS=(-s -f +o)
  35. # zsh 3.0.5 getopts bug patch
  36. DEFAULT_OPTIONS=(-s -f -O)
  37. ##### list of all defined keys #####
  38. # 'nl' must be the first entry and can be used to insert a newline character.
  39. # The value of this key is printed on the new line.
  40. KEYS=(nl tit nam fn sn nn occ cmp add po zip cit pho fax ema web hou bir ban bcn acc cus mis)
  41. ##### long form of the keys #####
  42. # The first entry is a mask for the field length. All entries should be exactly
  43. # the same length, end with a space and must be in the same order as in the
  44. # KEYS array.
  45. KEYNAMES=(\
  46. " " \
  47. "title: " \
  48. "name: " \
  49. "first name: " \
  50. "surname: " \
  51. "nickname: " \
  52. "occupation: " \
  53. "company: " \
  54. "address: " \
  55. "PO box: " \
  56. "zip: " \
  57. "city: " \
  58. "phone: " \
  59. "fax: " \
  60. "email: " \
  61. "website: " \
  62. "hours/busi.: " \
  63. "birthday: " \
  64. "bank: " \
  65. "bank code #: " \
  66. "account: " \
  67. "customer #: " \
  68. "misc.: "
  69. )
  70. ##### group definitions #####
  71. # Logical groups of keys. Groups are arrays of keynames as defined above in the
  72. # array KEYS. The 'all' group must be defined and must contain all of the keys
  73. # except 'nl' and 'com' which are reserved words. The order of the keys does
  74. # not matter, however. A '\\' prefix to the key names has a special meaning if
  75. # short output format is used (-s option):
  76. #
  77. # (substitute 'current key' for c, 'previous key' for p, 'current group' for g)
  78. #
  79. # IF c is in g
  80. # AND p ('com' and 'nl' do not count) has been printed also
  81. # AND key name of c begins with '\\'
  82. # AND p is the same as c or occurs before c in g
  83. # AND all keys between p and c begin with '\\' (in g)
  84. # THEN print current key on the same line as the last one printed.
  85. #
  86. # Note that the '\\' only occurs in the group arrays, not in the database.
  87. # The characters ',;.:' work exactly the same with the exception that they
  88. # will be printed before the space if all above conditions are met.
  89. #
  90. all=(nam tit \\fn \\sn \\nn occ cmp add po zip \\cit pho fax hou ema web bir ban bcn acc cus mis)
  91. add=(add po zip \\cit)
  92. pho=(pho fax hou)
  93. nam=(nam tit \\fn \\sn \\nn)
  94. job=(occ cmp)
  95. per=(bir)
  96. web=(ema web)
  97. acc=(ban bcn acc cus mis)
  98. # Special groups for printable output.
  99. padd=(,add \\po ,zip \\cit)
  100. ppho=(,pho ,fax ,hou)
  101. psn=(nam \\sn)
  102. pfn=(,fn ,tit)
  103. ##### list of all defined groups #####
  104. GROUPS=(all nam pho add job per web acc prt)
  105. ##### separator symbol #####
  106. # The character in the database used to separate the key names and values.
  107. # You must change it in the function 'break_stanza_lines' manually:
  108. # Replace 's:x:' with 's:y:' where x is the old separator and y the new one.
  109. KEY_SEPARATOR="|"
  110. ##### default query #####
  111. # The groups you want to see by default (e.g. name and telephone number).
  112. DEFAULT_QUERY=(nam add pho)
  113. ##### default print query #####
  114. # Special default query for the -p option. This is useful if you want to print
  115. # your the whole database (or selected keys) in a compressed format.
  116. PRINT_QUERY=(psn pfn padd ppho)
  117. ##### comment setup #####
  118. # The default strings printed before and after a comment.
  119. COM_PREFIX=""
  120. COM_SUFFIX=""
  121. ###############################################################################
  122. # do not edit below here #
  123. ###############################################################################
  124. #-------------------------
  125. # zsh configuration
  126. #-------------------------
  127. # reset options
  128. setopt LOCALOPTIONS
  129. emulate -R zsh
  130. setopt EXTENDEDGLOB
  131. setopt SHWORDSPLIT
  132. unsetopt KSHARRAYS
  133. unsetopt FUNCTIONARGZERO
  134. unsetopt ALLEXPORT
  135. # just to make sure
  136. alias echo='builtin echo'
  137. alias read='builtin read'
  138. #-------------------------
  139. # global variables
  140. #-------------------------
  141. local G_CUST=""
  142. # options
  143. local O_ARRAY=""
  144. local O_FAST=""
  145. local O_FORMAT=""
  146. local O_GSEPARATE=""
  147. local O_QTYPE=""
  148. local O_QUERY=""
  149. local G_SEP=""
  150. #-------------------------
  151. # functions
  152. #-------------------------
  153. #-------------------------
  154. # error handling functions
  155. #-------------------------
  156. function usage ()
  157. {
  158. echo "usage: ${0##*/} [ options ] [ regexp ]"
  159. if [[ -z "$1" ]] ; then
  160. echo " ${0##*/} -h for help"
  161. exit 2
  162. else
  163. echo "options:"
  164. echo " -a Select all keys in the order they appear in KEYS."
  165. echo " -c,+f Complex search. Search keys as well as record labels."
  166. echo " -C,-D string"
  167. echo " Specify the string printed before (-C) and after (-D) a comment."
  168. echo " -f,+c Fast search. Only the record labels are searched."
  169. echo " -g list|group[,group]..."
  170. echo " 'tele -g list' for a list of groups. No spaces must occur"
  171. echo " between the commas and the groups."
  172. echo " -h Print this help text."
  173. echo " -k list|key[,key]..."
  174. echo " 'tele -k list' for a list of keys. Keys with a \\-prefix (e.g."
  175. echo " \\tel are printed on the same line as the previous key if short"
  176. echo " output format (-s option) is used. No spaces are allowed in the"
  177. echo " list."
  178. echo " -l Long output style. Each key is printed on a separate line."
  179. echo " -o,+o,-O Print keys in the order of the selected groups. Otherwise (or"
  180. echo " if the +o or -O option is used) the keys are printed in the"
  181. echo " order they occur in the database."
  182. echo " -p Format output for printing. No newline is inserted between the"
  183. echo " groups. Sets the -o option. This may be changed by specifying +o"
  184. echo " anywhere after the -p option."
  185. echo " -s,+l Short output style."
  186. echo "default options: $DEFAULT_OPTIONS -g ${(j:,:)DEFAULT_QUERY}"
  187. echo "additional -p default options: -o -g ${(j:,:)PRINT_QUERY}"
  188. exit
  189. fi
  190. }
  191. check_group_all ()
  192. {
  193. if [[ ! $[ ${#all} + 1 ] = ${#KEYS} ]] ; then
  194. echo "ERROR: Group 'all' must contain all elements of 'KEYS' except 'nl'."
  195. echo "Please check your configuration at the beginning of this script."
  196. echo
  197. fi
  198. }
  199. function list_valid_keys ()
  200. {
  201. local -i I=2
  202. local -i J
  203. local -i PAD
  204. check_group_all
  205. if [[ ! ${#KEYS} = ${#KEYNAMES} ]] ; then
  206. echo "ERROR: 'KEYS' and 'KEYNAMES' have a different number of entries!"
  207. echo "Please check your configuration at the beginning of this script."
  208. echo "Possibly offending pairs of key/name:"
  209. echo
  210. J=${#KEYS}
  211. (( $J > ${#KEYNAMES} )) && J=${#KEYNAMES}
  212. I=2
  213. repeat $J ; do
  214. if [[ ! ${(L)KEYS[1]} = ${(L)KEYNAMES[1]} ]] ; then
  215. echo "$KEYS[$I] - ${KEYNAMES[$I]%: *}"
  216. fi
  217. I=$I+1
  218. done
  219. exit 3
  220. fi
  221. echo "valid keys:"
  222. echo
  223. PAD=${#KEYNAMES[1]}-1
  224. repeat $[ (${#KEYS}+1)/3 ] ; do
  225. echo " ${(r:5:: :)KEYS[$I]}${(r:$PAD:: :)${(S)KEYNAMES[$I]#:}}\c"
  226. echo " ${(r:5:: :)KEYS[$I+1]}${(r:$PAD:: :)${(S)KEYNAMES[$I+1]#:}}\c"
  227. echo " ${(r:5:: :)KEYS[$I+2]}${(r:$PAD:: :)${(S)KEYNAMES[$I+2]#:}}"
  228. I=$I+3
  229. done
  230. exit $1
  231. }
  232. function list_valid_groups ()
  233. {
  234. check_group_all
  235. echo "valid output groups:"
  236. echo " default $GROUPS[@]"
  237. echo "'default' equals to '$DEFAULT_QUERY'."
  238. exit $1
  239. }
  240. #-------------------------
  241. # break_stanza_lines
  242. #-------------------------
  243. function break_stanza_lines ()
  244. {
  245. [[ -n "$S_BROKEN" ]] && return
  246. S_BROKEN=1
  247. L_DATA=(${(s:|:)STANZA})
  248. L_NUM=$[${#L_DATA}/2]
  249. }
  250. #-------------------------
  251. # printing functions
  252. #-------------------------
  253. function print_line_long ()
  254. {
  255. local S
  256. [[ -n "$L_PANY" ]] && echo || L_PANY=1
  257. S=${KEYS[(i)$L_DATA[$LK]]}
  258. [[ $P_LAST = $S ]] && S=1 || P_LAST=$S
  259. echo "$KEYNAMES[$S]$L_DATA[$LV]\c"
  260. }
  261. function print_line_short ()
  262. {
  263. [[ -n "$L_PANY" ]] && echo "$1\c" || L_PANY=1
  264. echo "$2$L_DATA[$LV]$3\c"
  265. }
  266. function print_stanza ()
  267. {
  268. local -i I
  269. local -i J=1
  270. local -i LK
  271. local -i LV
  272. local -i NKEY
  273. local -i KEY
  274. local -i K_NUM
  275. local K_ARRAY
  276. local S
  277. local L_PRINTED
  278. local P_LAST=""
  279. break_stanza_lines
  280. # print header
  281. [[ $O_FORMAT = l ]] && echo "--> $L_DATA[1]"
  282. # print groups
  283. repeat $G_NUM ; do
  284. LK=2
  285. LV=3
  286. KEY=1
  287. S="\$$G_ARRAY[$J]"
  288. K_ARRAY=( ${(e)S}[@] )
  289. K_NUM=${#K_ARRAY}
  290. repeat $L_NUM ; do
  291. case $L_DATA[$LK] in
  292. com|nl)
  293. if [[ -n "$L_PRINTED" ]] ; then
  294. if [[ $L_PRINTED = com ]] || [[ $L_DATA[$LK] = nl ]] ; then
  295. echo
  296. [[ $O_FORMAT = l ]] && echo "$KEYNAMES[1]\c"
  297. L_PANY=""
  298. print_line_short \\n "$COM_PREFIX" "$COM_SUFFIX"
  299. L_PRINTED=com
  300. else
  301. print_line_short " " "$COM_PREFIX" "$COM_SUFFIX"
  302. L_PRINTED=com
  303. fi
  304. fi;;
  305. **)
  306. NKEY=${${K_ARRAY}[(i)[\,;.:]#$L_DATA[$LK]]}
  307. if (( $NKEY > $K_NUM )) || (( $NKEY < 1 )); then
  308. L_PRINTED=""
  309. KEY=1
  310. else
  311. if [[ $O_FORMAT = l ]] ; then
  312. print_line_long
  313. elif (( $KEY > $NKEY )) ; then
  314. if [[ $O_FORMAT = p ]] ; then
  315. case "${K_ARRAY[$NKEY][1]}" in
  316. ,|\;|.|:)
  317. print_line_short "${K_ARRAY[$NKEY][1]} ";;
  318. **) print_line_short "$G_SEP";;
  319. esac
  320. else
  321. print_line_short "$G_SEP"
  322. fi
  323. else
  324. I=$NKEY
  325. while true ; do
  326. case "${K_ARRAY[$I][1]}" in
  327. \\|,|\;|.|:) ;;
  328. **) if (( $I > $KEY )) && [[ ! $I = $NKEY ]] ; then
  329. print_line_short "$G_SEP"
  330. break
  331. fi;;
  332. esac
  333. I=$I-1
  334. if (( $I <= $KEY )) ; then
  335. case "${K_ARRAY[$NKEY][1]}" in
  336. \\) print_line_short " ";;
  337. ,|\;|.|:)
  338. print_line_short "${K_ARRAY[$NKEY][1]} ";;
  339. **) print_line_short "$G_SEP";;
  340. esac
  341. break
  342. fi
  343. done
  344. fi
  345. KEY=$NKEY
  346. L_PRINTED=1
  347. fi;;
  348. esac
  349. LK=$LK+2
  350. LV=$LV+2
  351. done
  352. J=$J+1
  353. done
  354. }
  355. #-------------------------
  356. # function complex_query
  357. #-------------------------
  358. function complex_query ()
  359. {
  360. ###
  361. [[ -n "${(MS)${(L)STANZA}#${(L)O_QUERY}}" ]]
  362. }
  363. #-------------------------
  364. # parse stanzas
  365. #-------------------------
  366. function parse_stanzas ()
  367. {
  368. local STANZA=""
  369. local S_BROKEN=""
  370. local -i G_NUM
  371. local -i G_ARNUM
  372. local -i G_DFNUM
  373. local S_PANY=""
  374. local G_ARRAY
  375. local -i L_NUM
  376. local L_DATA
  377. local L_PANY=""
  378. local K_MERGED=""
  379. local -i I
  380. local S
  381. local T_ARRAY
  382. local T_NUM
  383. if [[ -n "$O_GSEPARATE" ]] ; then
  384. G_ARRAY=($O_ARRAY)
  385. G_ARNUM=${#G_ARRAY}
  386. else
  387. G_ARRAY=(K_MERGED)
  388. G_ARNUM=1
  389. I=1
  390. repeat ${#O_ARRAY} ; do
  391. S="\$$O_ARRAY[$I]"
  392. K_MERGED=( $K_MERGED[@] ${(e)S}[@] )
  393. I=$I+1
  394. done
  395. fi
  396. G_NUM=$G_ARNUM
  397. # parse input file
  398. read 'STANZA'
  399. while [[ -n "$STANZA" ]] ; do
  400. S_BROKEN=""
  401. if [[ $O_QTYPE = f ]] || complex_query; then
  402. if [[ -z "$S_PANY" ]] ; then
  403. S_PANY=1
  404. else
  405. [[ $O_FORMAT = p ]] && echo || echo "\n"
  406. fi
  407. L_PANY=""
  408. print_stanza
  409. if [[ -z "$L_PANY" ]] ; then
  410. echo "no keys selected, printing whole record"
  411. T_ARRAY=($G_ARRAY)
  412. T_NUM=$G_NUM
  413. G_ARRAY=(all)
  414. G_NUM=1
  415. print_stanza
  416. G_ARRAY=($T_ARRAY)
  417. G_NUM=$T_NUM
  418. fi
  419. fi
  420. read 'STANZA'
  421. done
  422. [[ -n $S_PANY ]] && echo
  423. }
  424. #-------------------------
  425. # function split_stanzas
  426. #-------------------------
  427. function split_stanzas ()
  428. {
  429. sed -n "
  430. bskipline
  431. :seekhead
  432. n
  433. :skipline
  434. /^EOF$/q
  435. /^[^[:space:]].*:$/bhead
  436. bseekhead
  437. :head
  438. h
  439. /$O_FAST/bseektail
  440. bseekhead
  441. :seektail
  442. n
  443. /^[[:space:]]*$/btail
  444. s/^\([^$KEY_SEPARATOR]*\)$/\1|/g
  445. H
  446. bseektail
  447. :tail
  448. x
  449. s/\n[[:space:]]*/$KEY_SEPARATOR/g
  450. s/$KEY_SEPARATOR$KEY_SEPARATOR/$KEY_SEPARATOR $KEY_SEPARATOR/g
  451. p
  452. x
  453. bseekhead
  454. "
  455. }
  456. #-------------------------
  457. # parse options
  458. #-------------------------
  459. local -i I
  460. local S
  461. while getopts ":acC:D:fg:hk:loOps" OPT $DEFAULT_OPTIONS $*; do
  462. case $OPT in
  463. a) O_ARRAY=(all);;
  464. c|+f)
  465. O_QTYPE=c;;
  466. C) COM_PREFIX="$OPTARG";;
  467. D) COM_SUFFIX="$OPTARG";;
  468. f|+c)
  469. O_QTYPE=f;;
  470. g) [[ -z "$OPTARG" ]] && list_valid_groups 0
  471. if [[ $OPTARG = default ]] ; then
  472. O_ARRAY=( $DEFAULT_QUERY[@] )
  473. break
  474. fi
  475. I=${#O_ARRAY}+1
  476. O_ARRAY=( $O_ARRAY[@] ${(s:,:)OPTARG} )
  477. repeat $[ ${#O_ARRAY} - $I + 1 ] ; do
  478. S=${${GROUPS}[(i)${O_ARRAY[$I]}]}
  479. if (( $S < 1 )) || (( $S > ${#GROUPS} )) ; then
  480. [[ $O_ARRAY[$I] = list ]] ||
  481. echo "invalid group $O_ARRAY[$I]" >&2
  482. list_valid_groups 2
  483. fi
  484. I=$I+1
  485. done;;
  486. h) usage help;;
  487. k) [[ -z "$OPTARG" ]] && list_valid_keys 0
  488. I=${#G_CUST}+1
  489. G_CUST=( $G_CUST[@] ${(s:,:)OPTARG} )
  490. repeat $[ ${#G_CUST} - $I + 1 ] ; do
  491. S=${${KEYS}[(i)${G_CUST[$I]#+}]}
  492. if (( $S < 2 )) || (( $S > ${#KEYS} )) ; then
  493. [[ $G_CUST[$I] = list ]] ||
  494. echo "invalid key $G_CUST[$I]" >&2
  495. list_valid_keys 2
  496. fi
  497. I=$I+1
  498. done;;
  499. l|+s)
  500. G_SEP=\\n
  501. O_FORMAT=l;;
  502. o) O_GSEPARATE=1;;
  503. O|+o)
  504. O_GSEPARATE="";;
  505. p) O_FORMAT=p
  506. O_GSEPARATE=1
  507. G_SEP=" "
  508. O_ARRAY=( $PRINT_QUERY[@] );;
  509. s|+l)
  510. G_SEP=\\n
  511. O_FORMAT=s;;
  512. **) echo "illegal option '${OPTARG:-$OPT}'" >&2
  513. usage;;
  514. esac
  515. done
  516. OPTIND=$[ $OPTIND - ${#DEFAULT_OPTIONS} ]
  517. if (( $# > $OPTIND )) ; then
  518. # trailing parameters?
  519. echo "trailing parameters after pattern '$argv[$OPTIND]'" >&2
  520. usage
  521. elif [[ $O_QTYPE = f ]] ; then
  522. # fast search
  523. O_FAST="${(L)${argv[$OPTIND]}}"
  524. else
  525. # complex search
  526. O_QUERY="$argv[$OPTIND]"
  527. fi
  528. # output groups
  529. if [[ ! ${#G_CUST} = 0 ]] ; then
  530. O_ARRAY=(G_CUST)
  531. elif [[ ${#O_ARRAY} = 0 ]] ; then
  532. O_ARRAY=($DEFAULT_QUERY)
  533. fi
  534. #-------------------------
  535. # beginning of data
  536. #-------------------------
  537. # pipe the data group to the parse function (the braces are necessary here)
  538. #{ split_stanzas } <<- "EOF"
  539. { split_stanzas | parse_stanzas } <<- "EOF"
  540. fvwm (fvwm-workers):
  541. nam|fvwm
  542. web|http://fvwm.org
  543. com|fvwm home page
  544. web|ftp://fvwm.org/pub/fvwm/
  545. com|ftp site
  546. web|http://fvwm.org/fvwm-cats/
  547. com|fvwm cats page
  548. ema|fvwm@fvwm.org
  549. ema|fvwm-workers@fvwm.org
  550. ema|fvwm-announce@fvwm.org
  551. suse gmbh (suse, linux):
  552. nam|SuSE GmbH (SuSE Linux)
  553. pho|0911/7406331
  554. fax|0911/7417755
  555. com|Fax
  556. add|Schanzaeckerstr. 10
  557. zip|90443
  558. cit|Nuernberg
  559. acc|115569
  560. web|www.suse.de
  561. universitaet dortmund, unido:
  562. nam|University Dortmund (UniDo)
  563. pho|0231/7551
  564. com|Central
  565. pho|0231/7552256
  566. com|Students office (Emil-Figge Str. 66)
  567. add|Emil-Figge Str.
  568. zip|44221
  569. cit|Dortmund
  570. vogt, dominik (domivogt):
  571. fn|Dominik
  572. sn|Vogt
  573. nn|Avatar
  574. occ|fvwm hacker and zsh fanatic
  575. cmp|fvwm-workers mailing list :-)
  576. cit|Althengstett
  577. ema|dominik.vogt@gmx.de
  578. web|http://fvwm.org
  579. EOF
  580. # The last line before the EOF *must* be empty or the last stanza
  581. # will not be used!!
  582. # DOCUMENTATION
  583. #
  584. #
  585. # Note:
  586. #
  587. # You can find detailed examples at the end of this documentation.
  588. #
  589. # OVERVIEW:
  590. #
  591. # This script implements a database based solely on zsh functionality. The
  592. # only external program used is sed (for performace reasons only). The
  593. # purpose of this script is to provide a small, fast, extendable and portable
  594. # database. It began as a simple phone and address database, but I added new
  595. # types of datasets as I needed them. Today I use it for all the data and
  596. # numbers that were strewn over piles of paper, booklets and files. You can
  597. # run this script on any platform that provides a bug free sed command.
  598. # Should this not work you can still 'vi =tele' this file and look up the
  599. # needed record yourself.
  600. #
  601. # The data is stored in records that are described by stanzas of a certain
  602. # format. A stanza consits of a title and one or more key/value pairs. By
  603. # default a query is limited to the title, but more complex (but slower)
  604. # queries that look at the complete record can be used too.
  605. #
  606. # The keys are abbreviations for the interesting data in the record like 'fn'
  607. # (first name), 'sn' (surname), 'pho' (phone number) and so on. The keys are
  608. # assembled in groups for convenience reasons. The 'add' (address) group
  609. # consists of the keys 'add' (address), 'po' (PO box), 'zip' and 'cit' (city)
  610. # for example. The default query prints the contents of the 'nam' (name),
  611. # 'pho' (phone) and 'add' groups.
  612. #
  613. # In general you have to specify which records and which keys from these
  614. # records you want to see.
  615. #
  616. #
  617. # ADDING RECORDS:
  618. #
  619. # All records are entered in stanzas at the end of this script. The format of
  620. # a record (stanza) is this:
  621. #
  622. # TITLE:
  623. # <tab>KEY|CONTENTS
  624. # <tab>KEY|CONTENTS
  625. # ...
  626. # <empty line>
  627. #
  628. # The TITLE must begin at the start of a line and end with a colon (':').
  629. # The following lines must begin with a tab followed by the KEY, a '|' and
  630. # the data itself. Multiple keys of the same type can be used in one stanza.
  631. # The last line of the stanza *must* be empty to separate if from the
  632. # following stanzas. For example:
  633. #
  634. # vogt, dominik (domivogt):
  635. # fn|Dominik
  636. # sn|Vogt
  637. # nn|Avatar
  638. # cit|Althengstett
  639. #
  640. # vogt, melanie (melle):
  641. # ...
  642. #
  643. # Note: although you can put anything you like in the title, remember that
  644. # most queries look at the titles only. So be sure to put all the information
  645. # you prefer into the title. Personally I put the first name, surname,
  646. # nickname and other keywords like 'doctor' there. Using lower case letters
  647. # only in the title makes querying easier.
  648. #
  649. # Note: Do not use the separator character ('|'). If you need it you can
  650. # configure a different character (see customizing section).
  651. #
  652. # The preconfigured keys are:
  653. #
  654. # tit (title)
  655. # nam (name)
  656. # fn (first name)
  657. # sn (surname)
  658. # nn (nickname)
  659. # occ (occupation)
  660. # cmp (company)
  661. # add (address)
  662. # po (PO box)
  663. # zip (zip)
  664. # cit (city)
  665. # pho (phone)
  666. # fax (fax)
  667. # ema (email)
  668. # web (website)
  669. # hou (hours of business)
  670. # bir (birthday)
  671. # ban (bank)
  672. # bcn (bank code number)
  673. # acc (account)
  674. # cus (customer number)
  675. # mis (miscellaneous)
  676. #
  677. # and two special keys:
  678. #
  679. # nl (newline)
  680. # com (comment)
  681. #
  682. # All comments and newlines are printed whenever the previous line of the
  683. # stanza is printed. E.g.
  684. #
  685. # pho|01234/567890
  686. # com|home
  687. # nl|
  688. # pho|09876/54-3210
  689. # com|office
  690. #
  691. # would be printed as
  692. #
  693. # Phone: 01234/567890 home
  694. #
  695. # Phone: 09876/54-3210 office
  696. #
  697. #
  698. # SYNOPSIS:
  699. #
  700. # tele [ options ] [ search word ]
  701. #
  702. # The search word determines which records in the database are selected
  703. # (and hence printed out). If no search word is gicen, all records are
  704. # selected. When using the fast search option (-f or +c), tele looks for
  705. # matches in the label of each record (the first line). The search word
  706. # is a regular expression as implemented by your version of sed then. With
  707. # a complex search (-c or +f option) the contents of all keys are searched.
  708. # For performance reasons only simple strings are supported (to be honest,
  709. # now that I write this manual I don't understand my script any more. If
  710. # you want to implement regexp complex search you will have to rewrite the
  711. # 'complex_search' function in this script. If you do so, please send me
  712. # your version of the function.) In either case the match is case
  713. # insensitive.
  714. #
  715. # output options:
  716. #
  717. # -a
  718. # Select all keys in the order they appear in KEYS.
  719. #
  720. # -C string
  721. # -D string
  722. # Specify the string printed before (-C) and after (-D) a comment.
  723. #
  724. # -g list|group[,group]...
  725. # Use 'tele -g list' for a list of defined groups (see customizing
  726. # section). If a comma separated list of groups is given, all
  727. # information in the selected records in one of the given groups
  728. # is printed. No spaces must occur between the commas and the groups.
  729. #
  730. # -k list|key[,key]...
  731. #
  732. # Use 'tele -k list' for a list of defined keys (see customizing
  733. # section). If a comma separated list of keys is given, the given
  734. # keys in the selected records are printed. No spaces must occur
  735. # between the commas and the keys.
  736. #
  737. # -l
  738. # Long output style. Each key is printed on a separate line with a
  739. # label.
  740. #
  741. # +l
  742. # Same as -s. Turns off the -l option.
  743. #
  744. # -o
  745. # Print keys in the order of the selected groups.
  746. #
  747. # +o
  748. # Print keys in the order they occur in the database.
  749. #
  750. # -O Same as +o.
  751. #
  752. # -p
  753. # Format output for compact printing. No newline is inserted between the
  754. # groups. Sets the -o option. This may be changed by specifying +o
  755. # anywhere after the -p option.
  756. #
  757. # -s
  758. # Short output style. No labels are printed, information such as names
  759. # and titles are printed on a single line.
  760. #
  761. # +s
  762. # Same as -l. Turns off the +s option.
  763. #
  764. # record selection options:
  765. #
  766. # -c
  767. # Complex search. Search keys as well as record labels.
  768. #
  769. # +c
  770. # Same as -f. Turns off the -c option.
  771. #
  772. # -f
  773. # Fast search. Search only the record labels for matvches.
  774. #
  775. # +f
  776. # Same as -c. Turns off the -f option.
  777. #
  778. # other options:
  779. #
  780. # -h
  781. # Print a help text.
  782. #
  783. # default options:
  784. #
  785. # -s -f -O -g nam,add,pho
  786. #
  787. # default options when using the -p option:
  788. #
  789. # -s -f -o -g psn,pfn,padd,ppho
  790. #
  791. #
  792. # CUSTOMIZING:
  793. #
  794. # Please see the customizing section at the beginning of the script. I hope
  795. # the comments there are detailed enough to allow you to tinker with the
  796. # details of my script.
  797. #
  798. #
  799. # EXAMPLES:
  800. #
  801. # I have prepared a few records to demonstrate the usage of this script.
  802. #
  803. #
  804. # Simple query with default options (short output):
  805. #
  806. # # tele suse
  807. # S.u.S.E. GmbH (SuSE Linux)
  808. # 0911/7406331
  809. # 0911/7417755 Fax
  810. # Schanzaeckerstr. 10
  811. # 90443 Nuernberg
  812. #
  813. #
  814. # Long output format:
  815. #
  816. # # tele -l suse
  817. # --> suse gmbh (suse, linux):
  818. # name: SuSE GmbH (SuSE Linux)
  819. # phone: 0911/7406331
  820. # fax: 0911/7417755 Fax
  821. # address: Schanzaeckerstr. 10
  822. # zip: 90443
  823. # city: Nuernberg
  824. #
  825. #
  826. # Selecting a single key:
  827. #
  828. # # tele -l -k occ domi
  829. # --> vogt, dominik (domivogt):
  830. # occupation: fvwm hacker and zsh fanatic
  831. #
  832. #
  833. # Fast versus complex search:
  834. #
  835. # # tele -lf avatar
  836. # --> fvwm (fvwm-workers):
  837. # name: fvwm
  838. #
  839. # # tele -lc fvwm
  840. # --> fvwm (fvwm-workers):
  841. # name: fvwm
  842. #
  843. # --> vogt, dominik (domivogt):
  844. # first name: Dominik
  845. # surname: Vogt
  846. # nickname: Avatar
  847. # city: Althengstett
  848. #
  849. #
  850. # Viewing the complete record
  851. #
  852. # # tele -a domi
  853. # Dominik Vogt Avatar
  854. # fvwm hacker and zsh fanatic
  855. # fvwm-workers mailing list :-)
  856. # Althengstett
  857. # dominik.vogt@gmx.de
  858. # http://fvwm.org
  859. #
  860. #
  861. # Customized comment delimiters:
  862. #
  863. # # tele -C "<<" -D ">>" -a fvwm
  864. # fvwm
  865. # http://fvwm.org <<fvwm home page>>
  866. # ftp://fvwm.org/pub/fvwm/ <<ftp site>>
  867. # http://fvwm.org/fvwm-cats/ <<fvwm cats page>>
  868. # fvwm@fvwm.org
  869. # fvwm-workers@fvwm.org
  870. # fvwm-announce@fvwm.org
  871. #
  872. #
  873. # Ordering keys in output:
  874. #
  875. # # tele -o -g add,nam suse
  876. # Schanzaeckerstr. 10
  877. # 90443 Nuernberg
  878. # SuSE GmbH (SuSE Linux)
  879. #
  880. # # tele -O -g add,nam suse
  881. # SuSE GmbH (SuSE Linux)
  882. # Schanzaeckerstr. 10
  883. # 90443 Nuernberg
  884. #
  885. #
  886. # BUGS:
  887. #
  888. # Due to a bug in the getopts builtin in zsh 3.0.5 all command line options
  889. # with a leading '+' do not work. Use the corresponding options with
  890. # beginning with '-' instead.
  891. #
  892. # Some implementations of sed don't understand \n to denote a newline in
  893. # search patterns. If you have such a version of sed the script will not
  894. # print the records you want. In this case you have to replace this line of
  895. # the embedded sed script:
  896. #
  897. # s/\n[[:space:]]*/$KEY_SEPARATOR/g
  898. #
  899. # with these two:
  900. #
  901. # s/\
  902. #[[:space:]]*/$KEY_SEPARATOR/g
  903. #
  904. # I.e. insert a \ followed by a line break instead of the \n.