The Friendly Interactive Shell is a fun shell to use. Here are a few cool things I’ve done with it.
‘Keymap’ mods
Fish allows us to use the bind builtin to modify the way it interprets keys. This allows to to easily make ‘keymaps’ for Fish. We can bind commands to keys as well, so we can make it switch back and forth…
eg. ASCII and Greek letters
First we make two functions: one for each set of bindings.
function keymap_ascii --description 'Normal key bindings' set keymap ascii bind --erase --all # Clear earlier bindings, if any bind "" self-insert # This is the default binding, i.e. the one used if no other binding matches bind -k dc delete-char bind -k backspace backward-delete-char bind -k right forward-char bind -k left backward-char bind -k home beginning-of-line bind -k end end-of-line bind -k down down-or-search bind \e\[A down-or-search bind -k up up-or-search bind \e\[B up-or-search bind \n execute # bind \e\n "commandline -i \n" bind \t complete # bind \cy yank bind \cl 'clear; commandline -f repaint' bind \ck 'keymap_greek; infobar' bind \cb 'infobar' end function keymap_greek --description 'Binds Greek keys to normal keys' set keymap greek bind --erase --all # Clear earlier bindings, if any bind "" self-insert # This is the default binding, i.e. the one used if no other binding matches bind -k dc delete-char bind -k backspace backward-delete-char bind -k right forward-char bind -k left backward-char bind -k home beginning-of-line bind -k end end-of-line bind -k down down-or-search bind -k up up-or-search bind \n execute # bind \e\n "commandline -i \n" bind \t complete # bind \cy yank bind \cl 'clear; commandline -f repaint' bind \cb 'infobar' bind a 'commandline -i α' bind b 'commandline -i β' bind c 'commandline -i ς' bind d 'commandline -i δ' bind e 'commandline -i ε' bind f 'commandline -i φ' bind g 'commandline -i γ' bind h 'commandline -i η' bind i 'commandline -i ι' # bind j 'commandline -i ' bind k 'commandline -i κ' bind l 'commandline -i λ' bind m 'commandline -i μ' bind n 'commandline -i ν' bind o 'commandline -i ο' bind p 'commandline -i π' bind q 'commandline -i θ' bind r 'commandline -i ρ' bind s 'commandline -i σ' bind t 'commandline -i τ' bind u 'commandline -i υ' # bind v 'commandline -i ' bind w 'commandline -i ω' bind x 'commandline -i χ' bind y 'commandline -i ψ' bind z 'commandline -i ζ' bind A 'commandline -i Α' bind B 'commandline -i Β' # bind C 'commandline -i ' bind D 'commandline -i Δ' bind E 'commandline -i Ε' bind F 'commandline -i Φ' bind G 'commandline -i Γ' bind H 'commandline -i Η' bind I 'commandline -i Ι' # bind J 'commandline -i ' bind K 'commandline -i Κ' bind L 'commandline -i Λ' bind M 'commandline -i Μ' bind N 'commandline -i Ν' bind O 'commandline -i Ο' bind P 'commandline -i Π' bind Q 'commandline -i Θ' bind R 'commandline -i Ρ' bind S 'commandline -i Σ' # bind T 'commandline -i ' # bind U 'commandline -i ' # bind V 'commandline -i ' # bind W 'commandline -i ' # bind X 'commandline -i ' # bind Y 'commandline -i ' # bind Z 'commandline -i ' bind \ck 'keymap_ascii; infobar' end
Notice that C-k (Control k) is bound to switching the keymap. Don’t worry about infobar for now…
Now, we just need to make it the default binding:
function bfish_default_key_bindings --description 'Default (Emacs-like) key bindings for fish' keymap_ascii end
Really, this isn’t the way to handle it… One should try and do it at another level. I’m toying with the idea of trying to make a kernel module to do this. And simultaneously make cap-locks actually useful. By changing what it does.
Information Bar
We can also create a information bar. We need a function that returns the cursor to where it started once it has made the bar. How? We use tput sc (save cursor) and tput rc (return cursor). Here’s the function, as a straight line, with a colored background…
function info_bar tput sc tput cup 0 0 tput setb 1 tput setaf 7 tput el date echo -n " || " pwd tput rc end
We need this function to run at least when we clear and run a command, so:
function fish_prompt infobar printf (tput setaf 4)(date +%H:%M)(tput setaf 2)(prompt_pwd)(tput setaf 1)"\$ "(tput setaf 0) end function clear /usr/bin/clear echo "" infobar end
Notice that the prompt is just my personal preferred one.