Ubuntu – How to bind the capslock key to a fish shell command, and disable its toggle-caps functionality

command linefishkeyboardkeyboard-layoutshortcut-keys

I have recently switched to fish shell, and its autocomplete is really nice.

However, I find myself wanting to use tab to use the complete_autocomplete feature, as opposed to when it's unambiguous. The forward and end keys both do this, but they're out of reach of my fingers in a normal typing position.

I would love to use the Capslock key for this, as I never ever use that key but it's in such a nice position.

I've tried setxkbmap -option caps:none but that seems to disable the capslock key entirely. I suppose I could bind it to the forward or end key but I'm not sure how to do this either.

Also, I can't seem to find a key binding in fish shell for capslock:

cowpig@gerty:~$ bind -K
b2
backspace
btab
dc
down
end
enter
f1
f2
f3
f4
f5
f6
f7
f8
f9
f10
f11
f12
f13
f14
f15
f16
f17
f18
f19
f20
home
ic
left
npage
ppage
right
sdc
send
sf
shome
sic
sleft
snext
sprevious
sr
sright
up

Best Answer

First, check the manual because I think that Ctrl + F will also autocomplete. You can see it typing help in fish.

If you want to go ahead with the mapping, run xev and press capslock to get the keycode. Mine is 66:

enter code hereKeyRelease event, serial 37, synthetic NO, window 0x5200001,
root 0x4b7, subw 0x0, time 6149967, (918,609), root:(984,661),
state 0x10, keycode 66 (keysym 0xff57, End), same_screen YES,
XKeysymToKeycode returns keycode: 37
XLookupString gives 0 bytes: 
XFilterEvent returns: False

Now create a script (i.e. ~/xmodmap.sh) with permission 755 and the following text:

#/bin/bash
xmodmap -e "keycode 66 = End"
xmodmap -e "clear Lock"

Run the script and it will convert the capslock into the End key.

To make this permanent, add this command to the startup applications:

/bin/bash -c "sleep 7 && /home/myusername/xmodmap.sh"

I've tried it with the fish shell and it does auto complete the command.

I use Alt Gr to map some keys to closer positions: Customize keyboard layout including navigation keys