Automatic commit
[selector.git] / smarthist.sh
1 #!/bin/bash
2
3 #
4 #  selector is a simple shell command for selection of strings with a
5 #  dynamic pattern-matching.
6 #
7 #  Copyright (c) 2009 Francois Fleuret
8 #  Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 #
10 #  This file is part of selector.
11 #
12 #  selector is free software: you can redistribute it and/or modify
13 #  it under the terms of the GNU General Public License version 3 as
14 #  published by the Free Software Foundation.
15 #
16 #  selector is distributed in the hope that it will be useful, but
17 #  WITHOUT ANY WARRANTY; without even the implied warranty of
18 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 #  General Public License for more details.
20 #
21 #  You should have received a copy of the GNU General Public License
22 #  along with selector.  If not, see <http://www.gnu.org/licenses/>.
23 #
24
25 # You can add in your ~/.inputrc something like
26 #  Control-h: "smarthist.sh\n"
27 # so that C-h will invoke this script
28
29 EXE=./selector
30
31 # We do not want a security breach
32
33 OUT=`mktemp /tmp/selector.XXXXXX`
34 touch ${OUT}
35 chmod go-rwx ${OUT}
36
37 ${EXE} -o ${OUT} -f ~/.bash_history
38 # ${EXE} -b -o ${OUT} -f ~/.bash_history
39
40 # We set the echo off
41
42 OLD_SETTINGS=`stty -g`
43 stty -echo raw
44
45 # Put the line we got into the tty buffer
46
47 writevt `tty` "`cat ${OUT}`"
48
49 # Set back the echo as it was
50
51 stty ${OLD_SETTINGS}
52
53 # Remove the file containing what we got from the selector
54
55 \rm ${OUT}