Bind function keys to useful commands

If you ever find yourself typing the same sequence of psql slash commands over and over again, and wish there was a way of entering them with a single keystroke, and have an unused row of function keys at the top of your keyboard, and are running a UNIX-like system such as Linux, help is at hand:

Use .inputrc to bind function keys to commonly used psql slash commands and input sequences. The below file works on Linux:

elephant:~$ cat .inputrc
$if psql
#F1: show psql slash command help
"\eOP": "\\?\n"

#F2: list databases
"\eOQ": "\\l\n"

#F3: list schemas
"\eOR": "\\dn\n"

#F4: list tables
"\eOS": "\\dt\n"

#F5: list views
"\e[15~": "\\dv\n"

#F6: list indexes
"\e[17~": "\\di\n"

#F7: list aggregates
"\e[18~": "\\da\n"

#F8: list roles
"\e[19~": "\\dg\n"

#F9: list internal variables
"\e[20~": "\\set\n"

#F10: list SQL commands
"\e[21~": "\\h\n"

#F11: toggle pager 
"\e[23~": "\\pset pager\n"

#F12: toggle timing
"\e[24~": "\\timing\n"


On other systems, in bash use the read command to work out which keys generate which escape sequences.; substitute the leading ^[ with \e. E.g. in OS X, F1 produces ^11~, which should be converted to \e[11~ for .inputrc.