24b755d8f20c8dd8b03435d26b387e6540107652
[selector.git] / smarthist.sh
1 #!/bin/bash
2
3 ##################################################################
4 # START_IP_HEADER                                                #
5 #                                                                #
6 # Written by Francois Fleuret                                    #
7 # Contact <francois.fleuret@idiap.ch> for comments & bug reports #
8 #                                                                #
9 # END_IP_HEADER                                                  #
10 ##################################################################
11
12 # You can add in your ~/.inputrc something like
13 #  Control-h: "smarthist.sh\n"
14 # so that C-h will invoke this script
15
16 EXE=./selector
17
18 # We do not want a security breach
19
20 OUT=`mktemp /tmp/selector.XXXXXX`
21 touch ${OUT}
22 chmod go-rwx ${OUT}
23
24 ${EXE} -o ${OUT} -f ~/.bash_history
25
26 # We set the echo off
27
28 OLD_SETTINGS=`stty -g`
29 stty -echo raw
30
31 # Put the line we got into the tty buffer
32
33 writevt `tty` "`cat ${OUT}`"
34
35 # Set back the echo as it was
36
37 stty ${OLD_SETTINGS}
38
39 # Remove the file containing what we got from the selector
40
41 \rm ${OUT}