How to add keyboard shortcut for custom nemo action? - cinnamon

I have an custom nemo action as explained here:
https://wiki.archlinux.org/index.php/Nemo#Nemo_Actions
How can I add an shortcut for this action?
(If it can be done adding a line in ~/.gnome2/accels/nemo, then I have the additional problem that on my system this file is auto generated on every reboot, so editing something here will not help. I have Cinnamon 3.2.7 and nemo 3.2.2.)
Any suggestions? Thanks in advance! :)

Nemo Action
First, you should place the myaction.nemo_action under ~/.local/share/nemo/actions/.
Then, to make a keystroke put an underscore _ in front of the letter you want. For example in the Hello _Shortcut the s is the key. So you press the right-click and then s.
Bellow is an example of my action to open files and directories with Atom:
# Custom action for Nemo File Manager for Cinnamon.
# Adds right-click open file/files or directory with Atom.
# Place it under: ~/.local/share/nemo/actions/atom.nemo_action
# For more info: https://github.com/linuxmint/nemo/blob/master/files/usr/share/nemo/actions/sample.nemo_action
[Nemo Action]
Active=true
Name=Open in _Atom
Comment=Open %F in Atom
Exec=atom %F
Icon-Name=atom
Selection=any
Extensions=any;
Dependencies=atom;
Quote=double
Global Shortcut
If you want a global shortcut, you should use the Cinnamon Keyboard setting under the System settings, go to the second tab and add your custom shortcut.
Or, if you prefer more control over CLI you can use the dconf. For example, the bellow configuration will add the shortcut Shift><Alt>a
/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/name
'Open Atom'
/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/command
'atom'
/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/binding
['<Shift><Alt>a']
/org/cinnamon/desktop/keybindings/custom-list
['custom0']

Am trying to respond to Duncan Marshall but the post ended up in the mainthread. Yes, it's possible. Your file ~/.gnome2/accels/nemo can contain a line such as the following, which would execute a scrip file named edit.sh when F4 is pressed. The scripfile must be located in this special path (~/.local/share/nemo/scripts) and it must be enabled via a checkbox in User Interface>Edit>Preferences>Plugins>Scripts. Also i was unable to specify a script path such as ~/... instead of /home/username... When the syntax in the accels/nemo file is incorrect, nemo will prepend the incorrect line with ; and it will also delete the keycode at the end of the line and it also likes to resort lines in the accels file. I will also dismiss a line when the keycode was already used in another line. So it couldn't be more tricky to get this right.
(gtk_accel_path "<Actions>/ScriptsGroup/script_file:\\s\\s\\shome\\sUSERNAME\\s.local\\sshare\\snemo\\sscripts\\sedit.sh" "F4")
the script file might look like this
#!/bin/bash
export FILETOEDIT="$1"
FILEOWNER=$(stat -c %U "$1")
if [ "$FILEOWNER" = "$USER" ]; then
subl "$1"
else
sudo xed -w "$FILETOEDIT"
fi

Related

Add trailing slash in tcsh completion of directory symbolic links

Assume I have a folder ~/Documents
Now when I type /Doc and press tab key, my tcsh would complete the line to /Documents
What I would like to achieve, is to get /Documents/
I found most of the discussions on the Internet is about bash. But here I'm using tcsh. I know this is doable as my previous setup works like this in tcsh.
This is how tcsh should behave by default; but it's controlled with the addsuffix setting; from tcsh(1):
addsuffix (+)
If set, filename completion adds `/' to the end of directories
and a space to the end of normal files when they are matched
exactly. Set by default.

How to open a file and select/highlight several lines on Sublime from the command line?

I know subl myfile.txt:5 would open “myfile.txt” on line 5. I however want to be able to, from the command line, open a file with say lines 5,9,15 highlighted or selected. I know adding –command should enable me to do that, but how? What would the command be?
There's no built-in command that I know of that can do this, but one can easily create one.
(Technically, it could be done using the bookmarks functionality from the Default package, and the built-in "Expand Selection to Line" functionality. However, experience shows that it would be better and more reliable to write a command in ST specifically for this purpose.)
In ST:
from the Tools menu -> Developer -> New Plugin...
select all and replace with the following
import sublime
import sublime_plugin
class SelectSpecificLinesCommand(sublime_plugin.TextCommand):
def run(self, edit, lines):
self.view.sel().clear()
for line in lines:
position = self.view.text_point(int(line) - 1, 0) # internally, line numbers start from 0
self.view.sel().add(self.view.line(position))
save it, in the folder ST recommends (Packages/User/) as something like select_lines.py (file extension is important).
subl myfile.txt
subl --command "select_specific_lines { \"lines\": [5, 9, 15] }" (this style of escaping the quotes for JSON strings works from the Windows Command Prompt and Linux's Bash)
Why did I specify the command on a separate line / call to subl? Because of these 2 caveats:
ST must already be running, otherwise commands specified on the command line may not get executed, because the plugins haven't loaded yet.
the command could get executed before the file is loaded.
Arguably, point 2 could still happen with multiple invocations of subl, but hopefully it is less likely. There is an open issue on the ST bug tracker for better command line command handling: https://github.com/SublimeTextIssues/Core/issues/1457.

vi command line editing key bindings - previous command

I use the vi editor on the command line, and I really like it.
I use
set -o vi
to set the bindings.
The only thing is that I have to use the up and down arrows to cycle through the
previous executed commands.
In the emacs key bindings it was Ctrl+p to get to the previous command. It is the one emacs binding I miss.
I have been looking for something like it vi - but can't find it. My search gets diverted to the text editing vi binding for previous command which is held in " : " or hitting Ctrl+F to get a command window. I am using vi on the command line instead of emacs. There has to be something.
Is there something comparable in the vi command line ?
Using the Up / Down arrow keys is driving me nuts.
Actually I found the answer on this on this site:
Working Productively in Bash's Vi Command Line Editing Mode (with Cheat Sheet)
Make sure set -o vi is set to 'on'. Hit Ctrl+[ or escape to get to command mode. Then tap k go up the history and j to go down. It is so intuitive that I imagine most vi power-users discover it without trying, without help.
Thanks.

How to get the target of a shortcut?

How can I resolve a shortcut to its ultimate target on Windows programmatically?
I specify "ultimate" above to include the general case
shortcut → shortcut_1 →… → shortcut_n → target, in which there may be one or more "intervening" shortcut(s) in reference chain between shortcut and target.Also, I specify "programmatically" to rule out solutions that require interactive use of some feature of the MATLAB GUI.
(On Unix systems, one way to resolve shortcuts is to use something like system(['readlink ' shortcut]), or even better, if available, system(['readlink -f ' shortcut]). But I have not been able to find anything like this on Windows.)
If you open the shortcut file and read the first line you should see it.
>>fID=fopen(shortcutpath);
>>C=fgetl(fID);
C =
*some weird string* *filepath* *some other weird string*
Then with regexp you can find it easily.
Assuming your goal is just to open the shortcut to its destination, it seems to be as easy as on unix. Simply use this code to open a shortcut named sc in your current directory:
!sc.lnk % Equivalent to system('sc.lnk')
If the file is not in your current directory you need to add the path of course. If the shortcut refers to a shortcut it automatically ends up on the final result.
You could do it using COM.
Example:
server = actxserver('WScript.Shell');
path = server.CreateShortcut('D:\temp.lnk').TargetPath;
server.delete;
As Windows doesn't allow a shortcut to a shortcut, you get the "ultimate" target. :)

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

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.