Why is psql inserting a tilde when I press any of the keys in the Home key cluster? - postgresql

I'm using psql 8.2.3 on FreeBSD. Every time I press Insert, Home, Delete, End, Page Up or Page Down, a tilde (~) character is inserted instead of performing the expected function of the key. Why does this happen and how can I fix it?

As mentioned in Endlessdeath's answer, this turned out to be a key mapping problem with the operating system (FreeBSD), not psql. You can make these keys work as expected by creating or adding to a configuration file for inputrc.
You can create a file named .inputrc in your home directory with the following:
set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
Alternatively, you can create a global file for all users. A common practice for this is to create or add to the file at /usr/local/etc/inputrc the same lines as above and then export the variable in /etc/profile:
export INPUTRC=/usr/local/etc/inputrc
Ensure that /etc/profile is sourced by your shell (most do by default) and you're good to go. Note that the file won't be sourced until you log out and in again.
Here are some other resources for this problem:
http://bsdpants.blogspot.com/2007/08/make-home-and-end-keys-work.html
http://www.cyberciti.biz/tips/freebsd-how-to-customized-home-del-insert-keys-for-bash-shell.html
http://www.ibb.net/~anne/keyboard.html

That shouldn't be a psql problem - it's os specific.
A quick search on google could help.

Related

How to skip forward/backward a word at a time when editing postgres command in psql?

In most command line interface "cli" programs the Option-arrow key combinations allows one to move forwards/backwards a word at a time. But in psql both Option-arrow and Control-Arrow actually insert non printable control characters that corrupt the command. In addition in most CLI programs hitting CTL-A goes to the beginning of the command and CTL-E goes to the end of the command. But in psql those combinations do not have any effect.
Navigating a single character at a time is simply too slow: I can not imagine this were an unsolved problem. What is the configuration needed to get one of those key combinations to skip forward/backward by words not characters?
This is an answer containing the response in the comment by by #Marth. The ~/.inputrc does cause the issue.
# want vi to be the default editor for readline
set editing-mode vi
$if mode=vi
# normal mode
set keymap vi-command
set keymap vi-insert
"\C-n": backward-kill-word
"\C-p": history-search-backward
$endif
I have completely removed the ~/.inputrc now.

How to execute a Sublime plugin command from the command line?

I use the plugin SimpleSession with Sublime Text 3 (but any plugin could be considered). If I save a session with multiple windows, this creates a .simplesession file. How can I open that session file just by clicking on the file? The goal is to avoid having to launch ST3 and use the Command Palette to run the "Load Session" command. Currently, clicking on the .simplesession file causes ST3 to open it as a regular file.
Sublime doesn't know that a simplesession file is important in any way, so double clicking on one is going to open it the same as Sublime would open any other file.
Since it's a plugin that created the file, that plugin is the only thing that knows that it's special and what to do with it. So what you really need is the way to tell the plugin to take the action for you.
All actions in Sublime (including things as simple as inserting text) are taken by executing a command. Here that would be a command in the plugin that created the file in question, which would tell it that you want to carry out the action you would normally take manually, such as loading a session.
To do that from within Sublime you'd do something like bind a keyboard key to the appropriate command, add it to a menu, the command palette, etc. If you want to take the action from outside of Sublime, then you need to communicate that command to Sublime in order to get it to execute.
In core Sublime you can do this by executing the subl program that ships with Sublime and tell it a plugin command that you would like to execute.
Although it's possible to do this, the solution provided here has the requirement that Sublime already be running due to technical limitations within Sublime itself, but more on that in a moment.
This answer will give you the information that you need to formulate the command line that you need to execute in order to get the plugin command to run and carry out the action that you desire.
If you want to run this command in response to double clicking a file of a particular type (here a simplesession file), how you do that is specific to the operating system and file browser that you're using, and is best asked as a separate question.
Assuming you instead want a level of integration where you just have a desktop shortcut, start menu entry, etc that does this, this is more straight forward because such a shortcut is really just a visual wrapper that executes a command of your choosing.
Again, how you would do that is different depending on your OS, but the important part is knowing what full command line you need to give to the shortcut to be able to run it, which is what this answer tells you how to construct.
Important Note: The specific package in your question implements a load_session command, which prompts you for the session to load from a list of sessions you've previously created.
This command doesn't take any argument that would tell it what session to load without asking you to pick one first. As a result, what you want isn't technically possible without more work because there's no way to directly tell the load_session command the file that you want to open.
In order to more fully automate things in this particular case, the underlying package needs to be modified. In particular either the load_session command would need an optional argument which, when given, would cause it to load that session without prompting first, or
a new command would need to be created to do the same thing.
If you're not comfortable or knowledgeable enough to make such modifications to the package directly, you need to either find someone that will do that for you or (even better) discuss it with the package author, since that is a feature that others would probably enjoy as well.
The first thing you need to know is, "What command in the plugin is the one that I need to execute to do what I want?". In some cases you may already know exactly what command you need to use because it's documented, or you have already made a custom key binding for it, and so on.
If you don't know the command you need to use, check the documentation on the package (if any) to see if it mentions them. In your particular case, the README on the package page specifically mentions a list of commands, of which load_session seems like the most appropriate fit.
Lacking any documentation, the next easiest thing to do would be to ask Sublime directly. To do this, select View > Show Console from the menu or press the keyboard shortcut associated with it, Ctrl+`. In the console that appears, enter the following command and press enter.
sublime.log_commands(True)
Now whenever you do anything, this console is going to show you exactly what command Sublime is executing, along with any arguments that it may be passing to the command. This remains in effect until you use the same command with False or restart Sublime.
With logging turned on, select the appropriate command from the command palette and see what the Console says.
For example, with this package installed, I get output like the following:
>>> sublime.log_commands(True)
command: show_overlay {"overlay": "command_palette"}
command: load_session
This is showing two commands; first I opened the command palette which uses the show_overlay command, and then I selected the SimpleSession: Load command, which is the load_session command with no arguments.
In order to get Sublime to execute the command from the command line, you use the --command command line argument to subl. So in order to get Sublime to run the load_session command, you can enter the following command in a command prompt/terminal in your OS. This is also the command you would set in your desktop shortcut.
subl --command "load_session"
This presumes that you've set up Sublime so that it's in the path (how you do that is OS specific). If running subl in a terminal gives you an error about a missing command, either add the Sublime install directory to the path or use a fully qualified file name in place of subl (e,g. "C:\Program Files\Sublime Text 3\subl" if you're on Windows); either requires you to know what location Sublime is installed in.
If you want to use a command that takes arguments you need to include the arguments in the command as well, in the same way as they were displayed in the console above.
It's important that the command name and the arguments all be considered one command line argument, which requires you to wrap the whole thing in quote characters, since otherwise the spaces will make it appear as multiple arguments.
If you forget this, Sublime will respond by opening files named after the different parts of the command and arguments that you tried to open under the mistaken belief that you're giving it files to open.
As a concrete example, to get Sublime to open the command palette from outside of Sublime, the command to do this would look like the following if you were on Linux/MacOS:
subl --command 'show_overlay {"overlay": "command_palette"}'
Note again that we are passing exactly what the console showed above, but the whole thing, command and arguments, are wrapped in single quotes so that the terminal knows that the entire value is one argument.
This makes things a little tricky on Windows, which doesn't allow single quotes. On that platform you need to use double quotes instead. This requires you to "quote" the internal double quotes with a leading \ character so that the command processor knows that they're part of the argument and not the double quote that ends the argument.
For the case of opening the command palette on Windows, the command thus looks like this:
subl --command "show_overlay {\"overlay\": \"command_palette\"}"
With this information in hand, you can set up something like a desktop shortcut to run the appropriate command, or potentially set up the file explorer that you're using to execute a command specifically when you double click on a file of your choosing.
Again, how you would do that is specific to the operating system that you're using, and so I'm not really covering that in depth here in this answer. Just keep in mind that regardless of the OS in question, the part that remains the same is that you need to use subl command like the above.
Now, in your particular case, if the package that you're using provided a command that would let it load the session directly without prompting you first, the command that you use would need to also include the name of the session file as one of the command arguments.
However, as I mentioned above, this package doesn't currently allow that at the moment.
Now, here is the GIANT CAVEAT with this whole thing; this only works if Sublime is already running.
The subl command talks to an existing running copy of Sublime and gives it commands to open a file, directory, run a command as we're doing here, and so on. If Sublime isn't already running, then subl will start Sublime first and then communicate these details to it.
Sublime starts and makes it's interface available to you to work right away, and then starts to load packages and plugins in the background. This is to get you in and working on your files without having to wait for all packages to load first.
An issue with this is that as soon as Sublime starts, subl passes off the appropriate commands and then quits, and since packages aren't loaded yet, the command that you want to execute doesn't exist yet (hasn't been loaded), so nothing actually happens.
Unfortunately there's not really a satisfactory way around this particular issue if you want to start Sublime and also execute commands.
A potential workaround would be use something like a script or batch file that would check to see if Sublime is already running, and if not Start it and delay a little bit to allow plugins to finish loading, then use subl to run the command.
However this would require you to basically guess how long it takes Sublime to finish loading, which is less than ideal.

How to view content of emacs autosave file

How do I directly see the content of an emacs autosave file, without implementing a file recovery operation?
That is, suppose I created a file with 'emacs foo', then emacs crashed, so I'm left with no file named 'foo' (since it never was saved) but with a file '#foo#'. When I type 'more #foo#', I get "Missing filename", as though the more command doesn't even see the #foo# part of the command.
I just want to see the text in #foo# so I can copy it out by hand without risking something going wrong in the file recovery process (eg #foo# getting overwritten by a new autosave operation).
(I'm using Terminal on OSX.)
Bash or another shell use '#' as comment character, try :
more "#foo#"

Navigating within directories with name having spaces

I am using Windows 7, EmacsW32 and Emacs23
I am trying to navigate inside a directory whose name has spaces with within Emacs. So, I try to navigate to it in Dired mode by:
C-x d
And then navigate to the directory name with spaces (e.g. My Documents) and the suggestion and auto-complete feature (upon pressing TAB) does not work. How can I navigate to folders and files within such directories without removing spaces?
UPDATE: I tried few other paths with spaces in some directories, and it works. i don't know in which situations it works and fails. It works for Program Files but fails for My Documents.
I am taking a shot in the dark, but unix's case escapes are "\ " and I believe windows does the same.
This may not solve your problem directly.
As you described, I think you may not use ido-mode now. The default tab complete in emacs is weak. Try ido-mode, it is fantastic.
I can't replicate this particular issue, however:
To enter a literal space, type C-qSPC
C-q runs the command quoted-insert which ensures that the next character typed is inserted into the current buffer, which can be useful when the key in question is bound to some function.
The problem is not with folders with spaces in it. The problem is only with My Documents, My Videos and similarly named folders.
When I go in the windows file browser and check the path of the folder My Documents, it appears as C:/..../Documents/...
So, I tried to open Documents instead of My Documents in Emacs and it works. Now I am able to access my files under Documents.

Emacs epa mode: pinentry fails to encrypt and save file

I'm attempting to use epa mode and org mode in emacs as laid out by this article.
I'm attached to the computer using a screen session and ssh. I therefore needed to change /usr/bin/pinentry to point to /usr/bin/pinentry-curses as /usr/bin/pinentry-gtk-2.
I have
pinentry-program /usr/bin/pinentry-curses
as the last line in my .gnupg/gpg.conf. When I attempt to save the file I am presented with this menu:
Select recipients for encryption.
If no one is selected, symmetric encryption will be performed.
- `m' to mark a key on the line
- `u' to unmark a key on the line
[Cancel][OK]
I select 'ok' but only get
Opening output file: Encrypt failed, Exit
I get no prompt for my passphrase and no other output is given. It doesn't promp for a passphrase. It doesn't even list my gpg 'user' as foo#bar.com.
However when that line isn't present in the .gnupg/gpg.conf file I do see my gpg 'user' in the 'Select recipients for encryption' dialog. However, the cpu is pegged with the message stating:
Encrypting /home/user/test.gpg...
(I'm assuming as it is trying to spawn the gtk window and running in circles)
I'm a little confused as to why I needed to link /usr/bin/pinentry to /usr/bin/pinentry-curses and have the line in my gpg.conf file.
Before when /usr/bin/pinentry was linked to /usr/bin/pinentry-gtk-2, if I was on the local machine I'd get the 'Select recipients encryption' prompt with my gpg user listed. I'd get a dialog to input my passphrase and it all worked. I'd get
Encrypting /home/user/test.gpg...
and it would all succeed.
I'm running GNU Emacs 24.2.1 on an Arch system that is up to date as of this morning.
I'm curious what I'm doing wrong.
I've checked out the articles on pinentry and gpg on the arch wiki and they haven't helped to solve the problem.
Thanks in advance.
UPDATE: 26-10-2012 An update this morning to package cryptsetup seems to have influenced behavior. I now get A "Please enter passphrase" prompt when I open a .gpg file but it never seems to get past that. The prompt never goes away after entering my passphrase.
If this prompt comes from pinentry-curses, you might try:
1. enter passphrase (maybe not followed by enter, please try),
2. press tab key, 3. press enter key twice.
The reason for this is that you cannot see the whole form presented by pinentry-curses. Maybe try pinentry-curses outside emacs (and enter command GETPIN) to understand the blind navigation suggested above.
Similar problems exist if you use the Mew mail client (and gpg) inside emacs (in a terminal or tmux).
Anyone knows how to force the pinentry-curses dialog into one line suitable for emacs?
There are two main approaches, but their effectiveness may vary depending on the version of GPG used. This answer is for thecurrent modern branch (i.e. 2.2.x), not whatever was current when the question was asked.
Option 1a. Edit ~/.gnupg/gpg-agent.conf to use ncurses:
pinentry-program /usr/bin/pinentry-curses
Option 1b. Edit ~/.gnupg/gpg-agent.conf to use the Emacs pinentry (if available):
pinentry-program /usr/bin/pinentry-emacs
Option 2. Use the local gpg-agent and GUI over the SSH connection as described here
Option 2 takes a bit more effort to setup, but not too much and the benefits are considerable. Especially if you don't want to leave a secret key on a remote server.