Patch-ID: bash40-021
[bash.git] / examples / functions / fstty
bloba770d8417e59f54f29f70df8709b82a2f4021bbe
2 # A function that works as a front end for both stty and the `bind'
3 # builtin, so the tty driver and readline see the same changes
7 # Convert between the stty ^H control character form and the readline \C-H
8 # form
10 cvt()
12         echo "$@" | cat -v | sed 's/\^/\\C-/'
16 # stty front-end.  Parses the argument list and creates two command strings,
17 # one for stty, another for bind.
19 fstty()
21         local   cmd="" bargs=""
22         local   e
24         while [ $# -gt 0 ]
25         do
26                 case "$1" in
27                 -a)     cmd="$cmd everything"
28                         ;;
29                 erase)  shift;
30                         e=$(cvt "$1")
31                         cmd="$cmd erase $1"
32                         bargs="$bargs '\"$e\": backward-delete-char'"
33                         ;;
34                 kill)   shift
35                         e=$(cvt "$1")
36                         cmd="$cmd kill $1"
37                         bargs="$bargs '\"$e\": unix-line-discard'"
38                         ;;
39                 werase) shift;
40                         e=$(cvt "$1")
41                         cmd="$cmd erase $1"
42                         bargs="$bargs '\"$e\": backward-kill-word'"
43                         ;;
44                 lnext)  shift;
45                         e=$(cvt "$1")
46                         cmd="$cmd erase $1"
47                         bargs="$bargs '\"$e\": quoted-insert'"
48                         ;;
49                 *)      cmd="$cmd $1"
50                         ;;
51                 esac
52                 shift
53         done
55         command stty $cmd
56         if [ -n "$bargs" ]; then
57                 builtin bind $bargs
58         fi